Skip to content

Commit

Permalink
Adjust safe signerlaunchpad to packed userop
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Mar 5, 2024
1 parent 9c8fe00 commit 9e034b1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
4 changes: 3 additions & 1 deletion modules/passkey/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
build:
context: .
dockerfile: docker/bundler/Dockerfile
args:
TAG: 26e4f4c433916a6a2ea8ecc91ba8a56cd904f27f
restart: always
command: ['--auto', '--network=http://geth:8545']
ports:
Expand All @@ -28,7 +30,7 @@ services:
context: .
dockerfile: docker/bundler/Dockerfile
args:
TAG: main
TAG: 26e4f4c433916a6a2ea8ecc91ba8a56cd904f27f
restart: always
command: ['--auto', '--network=http://geth:8545']
ports:
Expand Down
4 changes: 3 additions & 1 deletion modules/passkey/docker/bundler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM docker.io/library/node:18

ARG TAG=v0.6.1
# v0.7.0
ARG TAG=26e4f4c
RUN git clone https://github.com/eth-infinitism/bundler /src/bundler
WORKDIR /src/bundler
RUN git checkout ${TAG}
RUN git submodule init && git submodule update

RUN yarn && yarn preprocess
ENTRYPOINT ["yarn", "bundler"]
Expand Down
2 changes: 1 addition & 1 deletion modules/passkey/src/deploy/4337.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const deploy: DeployFunction = async ({ deployments, getNamedAccounts, network }
contract: EntryPoint,
args: [],
log: true,
deterministicDeployment: true,
deterministicDeployment: '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3',
})
} else if (!ENTRY_POINT) {
throw new Error('TESTS_4337_MODULE_DEPLOYMENT_ENTRY_POINT_ADDRESS must be set')
Expand Down
22 changes: 14 additions & 8 deletions modules/passkey/test/4337-e2e/WebAuthnSigner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai'
import { deployments, ethers, network } from 'hardhat'
import { packGasParameters, unpackUserOperation } from '@safe-global/safe-erc4337/src/utils/userOp'
import { bundlerRpc, prepareAccounts, waitForUserOp } from '../utils/e2e'
import { chainId } from '../utils/encoding'
import {
Expand All @@ -9,6 +10,7 @@ import {
extractPublicKey,
extractSignature,
} from '../utils/webauthn'
import { PackedUserOperationStruct } from '../../typechain-types/@account-abstraction/contracts/interfaces/IAccount'

describe('E2E - WebAuthn Signers', () => {
before(function () {
Expand Down Expand Up @@ -135,7 +137,7 @@ describe('E2E - WebAuthn Signers', () => {
const safeSalt = Date.now()
const safe = await proxyFactory.createProxyWithNonce.staticCall(signerLaunchpad.target, launchpadInitializer, safeSalt)

const userOp = {
const packedUserOp: PackedUserOperationStruct = {
sender: safe,
nonce: ethers.toBeHex(await entryPoint.getNonce(safe, 0)),
initCode: ethers.solidityPacked(
Expand All @@ -156,16 +158,19 @@ describe('E2E - WebAuthn Signers', () => {
safeInit.fallbackHandler,
module.interface.encodeFunctionData('executeUserOp', [user.address, ethers.parseEther('0.5'), '0x', 0]),
]),
callGasLimit: ethers.toBeHex(2000000),
verificationGasLimit: ethers.toBeHex(500000),
...packGasParameters({
verificationGasLimit: 500000,
callGasLimit: 2000000,
maxFeePerGas: 10000000000,
maxPriorityFeePerGas: 10000000000,
}),
preVerificationGas: ethers.toBeHex(60000),
maxFeePerGas: ethers.toBeHex(10000000000),
maxPriorityFeePerGas: ethers.toBeHex(10000000000),
paymasterAndData: '0x',
signature: '0x',
}

const safeInitOp = {
userOpHash: await entryPoint.getUserOpHash({ ...userOp, signature: '0x' }),
userOpHash: await entryPoint.getUserOpHash({ ...packedUserOp, signature: '0x' }),
validAfter: 0,
validUntil: 0,
entryPoint: entryPoint.target,
Expand Down Expand Up @@ -211,9 +216,10 @@ describe('E2E - WebAuthn Signers', () => {
expect(await ethers.provider.getBalance(safe)).to.equal(ethers.parseEther('1'))
expect(await ethers.provider.getCode(safe)).to.equal('0x')
expect(await ethers.provider.getCode(signerAddress)).to.equal('0x')


Check failure on line 219 in modules/passkey/test/4337-e2e/WebAuthnSigner.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
const userOp = await unpackUserOperation({ ...packedUserOp, signature })
await bundler.sendUserOperation({ ...userOp, signature }, await entryPoint.getAddress())

console.log("sent user op")

Check failure on line 222 in modules/passkey/test/4337-e2e/WebAuthnSigner.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"sent·user·op"` with `'sent·user·op'`
await waitForUserOp(userOp)
expect(await ethers.provider.getBalance(safe)).to.be.lessThanOrEqual(ethers.parseEther('0.5'))
expect(await ethers.provider.getCode(safe)).to.not.equal('0x')
Expand Down
4 changes: 2 additions & 2 deletions modules/passkey/test/utils/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deployments, ethers } from 'hardhat'
import { MultiProvider4337 } from '@safe-global/safe-erc4337/dist/src/utils/safe'
import { UserOperation } from '@safe-global/safe-erc4337/dist/src/utils/userOp'
import { AddressLike, BigNumberish, BytesLike, HDNodeWallet } from 'ethers'
import { PackedUserOperationStruct } from '../../typechain-types/@account-abstraction/contracts/interfaces/IAccount'

export const BUNDLER_URL = process.env.TEST_BUNLDER_URL || 'http://localhost:3000/rpc'
export const BUNDLER_MNEMONIC = process.env.TEST_BUNDLER_MNEMONIC || 'test test test test test test test test test test test junk'
Expand All @@ -27,7 +27,7 @@ export function bundlerRpc(url = BUNDLER_URL) {
return new MultiProvider4337(url, ethers.provider)
}

export async function waitForUserOp({ sender, nonce }: Pick<UserOperation, 'sender' | 'nonce'>, timeout = 10_000) {
export async function waitForUserOp({ sender, nonce }: Pick<PackedUserOperationStruct, 'sender' | 'nonce'>, timeout = 10_000) {
const { address: entryPointAddress } = await deployments.get('EntryPoint')
const entryPoint = await ethers.getContractAt('INonceManager', entryPointAddress)
const start = performance.now()
Expand Down

0 comments on commit 9e034b1

Please sign in to comment.