Skip to content

Commit

Permalink
Add entrypoint assertion test
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardotc committed May 27, 2024
1 parent 38cc616 commit 73921b3
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ describe('Safe4337Pack', () => {
'Incompatibility detected: The EIP-4337 fallbackhandler is not attached to the Safe Account. Attach this fallbackhandler (address: 0xa581c4A4DB7175302464fF3C06380BC3270b4037) to ensure compatibility.'
)
})

it('should throw an error if the injected Entrypoint does not match the correct module version', async () => {
await expect(
createSafe4337Pack({
safeModulesVersion: '0.3.0',
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[1] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.3.0 of safe modules')

await expect(
createSafe4337Pack({
safeModulesVersion: '0.2.0',
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[0] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.2.0 of safe modules')

await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[1] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.2.0 of safe modules')
})
})

describe('When using existing Safe Accounts with version 1.4.1 or greater', () => {
Expand Down Expand Up @@ -496,32 +521,7 @@ describe('Safe4337Pack', () => {
})
})

it('should throw an error if the injected Entrypoint does not match the correct module version', async () => {
await expect(
createSafe4337Pack({
safeModulesVersion: '0.3.0',
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[1] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.3.0 of safe modules')

await expect(
createSafe4337Pack({
safeModulesVersion: '0.2.0',
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[0] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.2.0 of safe modules')

await expect(
createSafe4337Pack({
options: { safeAddress: fixtures.SAFE_ADDRESS_v1_4_1 },
customContracts: { entryPointAddress: fixtures.ENTRYPOINTS[1] }
})
).rejects.toThrow('The used entrypoint is not compatbile with version 0.2.0 of safe modules')
})

it('should all to sign a SafeOperation', async () => {
it('should allow to sign a SafeOperation', async () => {
const transferUSDC = {
to: fixtures.PAYMASTER_TOKEN_ADDRESS,
data: generateTransferCallData(fixtures.SAFE_ADDRESS_v1_4_1, 100_000n),
Expand Down Expand Up @@ -663,4 +663,26 @@ describe('Safe4337Pack', () => {

expect(supportedEntryPoints).toContain('0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789')
})

it('should pick an entrypoint that matches the modules version', async () => {
const transferUSDC = {
to: fixtures.PAYMASTER_TOKEN_ADDRESS,
data: generateTransferCallData(fixtures.SAFE_ADDRESS_v1_4_1, 100_000n),
value: '0',
operation: 0
}

const safe4337Pack = await createSafe4337Pack({
safeModulesVersion: '0.3.0',
options: {
safeAddress: fixtures.SAFE_ADDRESS_v1_4_1
}
})

const safeOperation = await safe4337Pack.createTransaction({
transactions: [transferUSDC]
})

expect(safeOperation.data.entryPoint).toBe(fixtures.ENTRYPOINTS[1])
})
})

0 comments on commit 73921b3

Please sign in to comment.