Skip to content

Commit

Permalink
[#754] Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jul 11, 2024
1 parent 025234f commit 1091977
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions modules/4337/test/erc4337/ReferenceEntryPoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,67 @@ describe('Safe4337Module - Reference EntryPoint', () => {
.withArgs(0, 'AA24 signature error')
})

it('should revert when expected offset and given dynamic pointer in signatures are not equal - Smart contract signature (NOTE: would require a staked paymaster for ERC-4337)', async () => {
const { user, relayer, safe: parentSafe, validator, entryPoint, safeGlobalConfig } = await setupTests()

await parentSafe.deploy(user)
const daughterSafe = Safe4337.withSigner(parentSafe.address, safeGlobalConfig)

const accountBalance = ethers.parseEther('1.0')
await user.sendTransaction({ to: daughterSafe.address, value: accountBalance })
expect(await ethers.provider.getBalance(daughterSafe.address)).to.be.eq(accountBalance)

const transfer = ethers.parseEther('0.1')
const safeOp = buildSafeUserOpTransaction(
daughterSafe.address,
user.address,
transfer,
'0x',
'0x0',
await entryPoint.getAddress(),
false,
false,
{
initCode: daughterSafe.getInitCode(),
},
)

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

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, 66) +
((signature.length - 2) / 2).toString(16).padStart(64, '0') +
'00' +
signature.slice(132) +
signature.slice(132),
})

await expect(entryPoint.handleOps([userOp], await relayer.getAddress()))
.to.be.revertedWithCustomError(entryPoint, 'FailedOp')
.withArgs(0, 'AA24 signature error')
})

function isEventLog(log: Log): log is EventLog {
return typeof (log as Partial<EventLog>).eventName === 'string'
}
Expand Down

0 comments on commit 1091977

Please sign in to comment.