diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts index 8d0ef94d4..4806e6853 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts @@ -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', () => { @@ -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), @@ -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]) + }) })