Skip to content

Commit

Permalink
[#754] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jul 11, 2024
1 parent 42b216e commit 0306c39
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
36 changes: 19 additions & 17 deletions modules/4337/test/erc4337/ERC4337ModuleNew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,29 +234,31 @@ describe('Safe4337Module - Newly deployed safe', () => {
)

const opData = calculateSafeOperationData(await validator.getAddress(), safeOp, await chainId())
const signature = buildSignatureBytes([
const parentSafeSignature = await user1.signTypedData(
{
signer: parentSafe.address,
data: await user1.signTypedData(
{
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
),
dynamic: true,
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
)

// The 2nd word of static part of signature containing invalid value pointing to dynamic part
const signature = ethers.concat([
ethers.zeroPadValue(parentSafe.address, 32), // address of the signer
ethers.toBeHex(0, 32), // offset of the start of the signature
'0x00', // contract signature type
ethers.toBeHex(ethers.dataLength(parentSafeSignature), 32), // length of the dynamic signature
parentSafeSignature,
])

const userOp = buildPackedUserOperationFromSafeUserOperation({
safeOp,
// Replace the 2nd word of static part of signature containing the pointer to dynamic part with invalid pointer value
signature: signature.slice(0, 67) + '00'.padStart(64, '0') + signature.slice(131),
signature,
})

await expect(entryPoint.handleOps([userOp], await relayer.getAddress()))
Expand Down
39 changes: 22 additions & 17 deletions modules/4337/test/erc4337/ReferenceEntryPoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,28 +327,33 @@ describe('Safe4337Module - Reference EntryPoint', () => {
)

const opData = calculateSafeOperationData(await validator.getAddress(), safeOp, await chainId())
const signature = buildSignatureBytes([

const parentSafeSignature = await user.signTypedData(
{
signer: parentSafe.address,
data: await user.signTypedData(
{
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
),
dynamic: true,
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
)

// The 2nd word of static part of signature containing invalid value pointing to dynamic part
const signature = ethers.concat([
ethers.zeroPadValue(parentSafe.address, 32), // address of the signer
ethers.toBeHex(0, 32), // offset of the start of the signature
'0x00', // contract signature type
ethers.toUtf8Bytes('padding'), // extra illegal padding between signatures
ethers.toBeHex(ethers.dataLength(parentSafeSignature), 32), // length of the dynamic signature
parentSafeSignature,
])

const userOp = buildPackedUserOperationFromSafeUserOperation({
safeOp,
// Replace the 2nd word of static part of signature containing the pointer to dynamic part with invalid pointer value
signature: signature.slice(0, 67) + '00'.padStart(64, '0') + signature.slice(131),
signature,
})

await expect(entryPoint.handleOps([userOp], await relayer.getAddress()))
Expand Down

0 comments on commit 0306c39

Please sign in to comment.