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 4, 2024
1 parent 17e6d46 commit 9e22daf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 144 deletions.
11 changes: 0 additions & 11 deletions modules/4337/contracts/test/TestSafe4337Module.sol

This file was deleted.

12 changes: 3 additions & 9 deletions modules/4337/test/erc4337/ERC4337ModuleNew.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ describe('Safe4337Module - Newly deployed safe', () => {
expect(await ethers.provider.getBalance(safe.address)).to.be.eq(ethers.parseEther('0'))
})

it('should revert when signature length is manipulated', async () => {
const { user1, safe, validator, entryPoint, entryPointSimulations } = await setupTests()
const entryPointAddress = await entryPoint.getAddress()
it('should revert when signature length contains additional bytes', async () => {
const { user1, safe, validator, entryPoint } = await setupTests()

await entryPoint.depositTo(await safe.address, { value: ethers.parseEther('1.0') })

Expand All @@ -139,12 +138,7 @@ describe('Safe4337Module - Newly deployed safe', () => {
initCode: safe.getInitCode(),
},
)
const gasEstimation = await estimateUserOperationGas(ethers.provider, entryPointSimulations, safeOp, entryPointAddress)
safeOp.callGasLimit = gasEstimation.callGasLimit
safeOp.preVerificationGas = gasEstimation.preVerificationGas
safeOp.verificationGasLimit = gasEstimation.verificationGasLimit
safeOp.maxFeePerGas = gasEstimation.maxFeePerGas
safeOp.maxPriorityFeePerGas = gasEstimation.maxPriorityFeePerGas

// Add additional byte to the signature to make signature length invalid
const signature = buildSignatureBytes([await signSafeOp(user1, await validator.getAddress(), safeOp, await chainId())]).concat('00')
const userOp = buildPackedUserOperationFromSafeUserOperation({
Expand Down
34 changes: 34 additions & 0 deletions modules/4337/test/erc4337/Safe4337Module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,40 @@ describe('Safe4337Module', () => {

expect(await safeFromEntryPoint.validateUserOp.staticCall(userOp, ethers.ZeroHash, 0)).to.eq(packedValidationData)
})

it('should indicate failed validation data when signature length contains additional bytes', async () => {
const { user, safeModule, validator, entryPoint } = await setupTests()

const validAfter = BigInt(ethers.hexlify(ethers.randomBytes(3)))
const validUntil = validAfter + BigInt(ethers.hexlify(ethers.randomBytes(3)))

const safeOp = buildSafeUserOpTransaction(
await safeModule.getAddress(),
user.address,
0,
'0x',
'0',
await entryPoint.getAddress(),
false,
false,
{
validAfter,
validUntil,
},
)

const safeOpHash = calculateSafeOperationHash(await validator.getAddress(), safeOp, await chainId())
const signature = buildSignatureBytes([await signHash(user, safeOpHash)]).concat('00')
const userOp = buildPackedUserOperationFromSafeUserOperation({
safeOp,
signature,
})
const packedValidationData = packValidationData(1, validUntil, validAfter)
const entryPointImpersonator = await ethers.getSigner(await entryPoint.getAddress())
const safeFromEntryPoint = safeModule.connect(entryPointImpersonator)

expect(await safeFromEntryPoint.validateUserOp.staticCall(userOp, ethers.ZeroHash, 0)).to.eq(packedValidationData)
})
})

describe('execUserOp', () => {
Expand Down
124 changes: 0 additions & 124 deletions modules/4337/test/erc4337/TestSafe4337Module.spec.ts

This file was deleted.

0 comments on commit 9e22daf

Please sign in to comment.