-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
191 additions
and
59 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/relay-kit/src/packs/safe-4337/SafeOperationBase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { EthSafeSignature } from '@safe-global/protocol-kit' | ||
import SafeOperationV07 from './SafeOperationV07' | ||
import * as fixtures from './testing-utils/fixtures' | ||
|
||
describe('SafeOperationBase', () => { | ||
it('should add and retrieve signatures', () => { | ||
const safeOperation = new SafeOperationV07(fixtures.USER_OPERATION_V07, { | ||
chainId: BigInt(fixtures.CHAIN_ID), | ||
moduleAddress: fixtures.MODULE_ADDRESS, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
safeOperation.addSignature(new EthSafeSignature('0xSigner', '0xSignature')) | ||
|
||
expect(safeOperation.signatures.size).toBe(1) | ||
expect(safeOperation.getSignature('0xSigner')).toMatchObject({ | ||
signer: '0xSigner', | ||
data: '0xSignature', | ||
isContractSignature: false | ||
}) | ||
}) | ||
|
||
it('should encode the signatures', () => { | ||
const safeOperation = new SafeOperationV07(fixtures.USER_OPERATION_V07, { | ||
chainId: BigInt(fixtures.CHAIN_ID), | ||
moduleAddress: fixtures.MODULE_ADDRESS, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
safeOperation.addSignature(new EthSafeSignature('0xSigner1', '0xSignature1')) | ||
safeOperation.addSignature(new EthSafeSignature('0xSigner2', '0xSignature2')) | ||
|
||
expect(safeOperation.encodedSignatures()).toBe('0xSignature1Signature2') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/relay-kit/src/packs/safe-4337/SafeOperationV07.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Hex, concat, encodePacked } from 'viem' | ||
import { EthSafeSignature } from '@safe-global/protocol-kit' | ||
import SafeOperationV07 from './SafeOperationV07' | ||
import * as fixtures from './testing-utils/fixtures' | ||
|
||
describe('SafeOperationV07', () => { | ||
it('should create a SafeOperation from an UserOperation', () => { | ||
const safeOperation = new SafeOperationV07(fixtures.USER_OPERATION_V07, { | ||
chainId: BigInt(fixtures.CHAIN_ID), | ||
moduleAddress: fixtures.MODULE_ADDRESS, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
expect(safeOperation.getSafeOperation()).toMatchObject({ | ||
safe: fixtures.USER_OPERATION_V07.sender, | ||
nonce: fixtures.USER_OPERATION_V07.nonce, | ||
initCode: concat([ | ||
safeOperation.userOperation.factory as Hex, | ||
(safeOperation.userOperation.factoryData as Hex) || ('0x' as Hex) | ||
]), | ||
callData: fixtures.USER_OPERATION_V07.callData, | ||
callGasLimit: fixtures.USER_OPERATION_V07.callGasLimit, | ||
verificationGasLimit: fixtures.USER_OPERATION_V07.verificationGasLimit, | ||
preVerificationGas: fixtures.USER_OPERATION_V07.preVerificationGas, | ||
maxFeePerGas: fixtures.USER_OPERATION_V07.maxFeePerGas, | ||
maxPriorityFeePerGas: fixtures.USER_OPERATION_V07.maxPriorityFeePerGas, | ||
paymasterAndData: '0x', | ||
validAfter: 0, | ||
validUntil: 0, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
expect(safeOperation.signatures.size).toBe(0) | ||
}) | ||
|
||
it('should add estimations', () => { | ||
const safeOperation = new SafeOperationV07(fixtures.USER_OPERATION_V07, { | ||
chainId: BigInt(fixtures.CHAIN_ID), | ||
moduleAddress: fixtures.MODULE_ADDRESS, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
safeOperation.addEstimations({ | ||
callGasLimit: BigInt(fixtures.GAS_ESTIMATION.callGasLimit), | ||
verificationGasLimit: BigInt(fixtures.GAS_ESTIMATION.verificationGasLimit), | ||
preVerificationGas: BigInt(fixtures.GAS_ESTIMATION.preVerificationGas) | ||
}) | ||
|
||
expect(safeOperation.getSafeOperation()).toMatchObject({ | ||
safe: fixtures.USER_OPERATION_V07.sender, | ||
nonce: fixtures.USER_OPERATION_V07.nonce, | ||
initCode: concat([ | ||
safeOperation.userOperation.factory as Hex, | ||
(safeOperation.userOperation.factoryData as Hex) || ('0x' as Hex) | ||
]), | ||
callData: fixtures.USER_OPERATION_V07.callData, | ||
callGasLimit: BigInt(fixtures.GAS_ESTIMATION.callGasLimit), | ||
verificationGasLimit: BigInt(fixtures.GAS_ESTIMATION.verificationGasLimit), | ||
preVerificationGas: BigInt(fixtures.GAS_ESTIMATION.preVerificationGas), | ||
maxFeePerGas: fixtures.USER_OPERATION_V07.maxFeePerGas, | ||
maxPriorityFeePerGas: fixtures.USER_OPERATION_V07.maxPriorityFeePerGas, | ||
paymasterAndData: '0x', | ||
validAfter: 0, | ||
validUntil: 0, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
}) | ||
|
||
it('should retrieve the UserOperation', () => { | ||
const safeOperation = new SafeOperationV07(fixtures.USER_OPERATION_V07, { | ||
chainId: BigInt(fixtures.CHAIN_ID), | ||
moduleAddress: fixtures.MODULE_ADDRESS, | ||
entryPoint: fixtures.ENTRYPOINTS[1] | ||
}) | ||
|
||
safeOperation.addSignature( | ||
new EthSafeSignature( | ||
'0xSigner', | ||
'0x000000000000000000000000a397ca32ee7fb5282256ee3465da0843485930b803d747516aac76e152f834051ac18fd2b3c0565590f9d65085538993c85c9bb189c940d15c15402c7c2885821b' | ||
) | ||
) | ||
|
||
expect(safeOperation.getUserOperation()).toMatchObject({ | ||
sender: safeOperation.userOperation.sender, | ||
nonce: fixtures.USER_OPERATION_V07.nonce, | ||
factory: fixtures.USER_OPERATION_V07.factory, | ||
factoryData: fixtures.USER_OPERATION_V07.factoryData, | ||
callData: safeOperation.userOperation.callData, | ||
callGasLimit: safeOperation.userOperation.callGasLimit, | ||
verificationGasLimit: safeOperation.userOperation.verificationGasLimit, | ||
preVerificationGas: safeOperation.userOperation.preVerificationGas, | ||
maxFeePerGas: safeOperation.userOperation.maxFeePerGas, | ||
maxPriorityFeePerGas: safeOperation.userOperation.maxPriorityFeePerGas, | ||
paymaster: safeOperation.userOperation.paymaster, | ||
paymasterData: safeOperation.userOperation.paymasterData, | ||
signature: encodePacked( | ||
['uint48', 'uint48', 'bytes'], | ||
[ | ||
safeOperation.options.validAfter || 0, | ||
safeOperation.options.validUntil || 0, | ||
safeOperation.encodedSignatures() as Hex | ||
] | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters