Skip to content

Commit

Permalink
Merge pull request #221 from pimlicolabs/fix/compression
Browse files Browse the repository at this point in the history
Fix/compression
  • Loading branch information
mouseless0x authored May 24, 2024
2 parents 24c3528 + 6fc952b commit 78d12ab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
9 changes: 5 additions & 4 deletions src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class RpcHandler implements IRpcEndpoint {
// Since we don't want our estimations to depend upon baseFee, we set
// maxFeePerGas to maxPriorityFeePerGas
userOperation.maxPriorityFeePerGas = userOperation.maxFeePerGas


// Check if the nonce is valid
// If the nonce is less than the current nonce, the user operation has already been executed
Expand All @@ -381,7 +381,8 @@ export class RpcHandler implements IRpcEndpoint {
"UserOperation reverted during simulation with reason: AA25 invalid account nonce",
ValidationErrors.InvalidFields
)
} else if (userOperationNonceValue > currentNonceValue) {
}
if (userOperationNonceValue > currentNonceValue) {
// Nonce queues are supported only for v7 user operations
if (isVersion06(userOperation)) {
throw new RpcError(
Expand Down Expand Up @@ -1008,7 +1009,7 @@ export class RpcHandler implements IRpcEndpoint {
userOperationNonceValue === currentNonceValue + BigInt(queuedUserOperations.length)
) {
if (this.dangerousSkipUserOperationValidation) {
const success = this.mempool.add(userOperation, entryPoint)
const success = this.mempool.add(op, entryPoint)
if (!success) {
throw new RpcError(
"UserOperation reverted during simulation with reason: AA25 invalid account nonce",
Expand Down Expand Up @@ -1057,7 +1058,7 @@ export class RpcHandler implements IRpcEndpoint {
}
}

this.nonceQueuer.add(userOperation, entryPoint)
this.nonceQueuer.add(op, entryPoint)
return "queued"
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
image: ghcr.io/foundry-rs/foundry:nightly-503792a1dbadd901a4c02f6fcd1de1caff1573ff
ports: [ "8545:8545" ]
entrypoint: [ "anvil", "--host", "0.0.0.0", "--silent" ]
platform: linux/amd64/v8

deploy-contracts:
build:
Expand Down
71 changes: 52 additions & 19 deletions test/e2e/tests/pimlico_sendCompressedUserOperation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, beforeAll, expect, beforeEach } from "vitest"
import { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types"
import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types"
import {
beforeEachCleanUp,
getPimlicoBundlerClient,
Expand All @@ -11,14 +11,16 @@ import { ENTRYPOINT_ADDRESS_V06 } from "permissionless/utils"
import {
createPublicClient,
createTestClient,
getAddress,
getContract,
http,
parseEther,
parseGwei
parseGwei,
zeroAddress
} from "viem"
import { ANVIL_RPC } from "../src/constants"
import { foundry } from "viem/chains"
import { PimlicoBundlerClient } from "permissionless/clients/pimlico"
import type { PimlicoBundlerClient } from "permissionless/clients/pimlico"

const publicClient = createPublicClient({
transport: http(ANVIL_RPC),
Expand Down Expand Up @@ -71,7 +73,7 @@ const SIMPLE_INFLATOR_CONTRACT = getContract({
describe("V0.6 pimlico_sendCompressedUserOperation", () => {
let pimlicoBundlerClient: PimlicoBundlerClient<ENTRYPOINT_ADDRESS_V06_TYPE>

beforeAll(async () => {
beforeAll(() => {
pimlicoBundlerClient = getPimlicoBundlerClient(ENTRYPOINT_ADDRESS_V06)
})

Expand Down Expand Up @@ -109,7 +111,17 @@ describe("V0.6 pimlico_sendCompressedUserOperation", () => {

await new Promise((resolve) => setTimeout(resolve, 1500))

await pimlicoBundlerClient.waitForUserOperationReceipt({ hash })
const receipt = await pimlicoBundlerClient.waitForUserOperationReceipt({
hash
})

const txReceipt = await publicClient.getTransaction({
hash: receipt.receipt.transactionHash
})

expect(getAddress(txReceipt.to || zeroAddress)).toEqual(
"0x09aeBCF1DF7d4D0FBf26073e79A6B250f458fFB8"
)

expect(
await publicClient.getBalance({ address: to })
Expand Down Expand Up @@ -174,6 +186,14 @@ describe("V0.6 pimlico_sendCompressedUserOperation", () => {
expect(
await publicClient.getBalance({ address: to })
).toBeGreaterThanOrEqual(value)

const txReceipt = await publicClient.getTransaction({
// @ts-ignore: null check done above but ts doesnt recognize it
hash: opReceipt.receipt.transactionHash
})
expect(getAddress(txReceipt.to || zeroAddress)).toEqual(
"0x09aeBCF1DF7d4D0FBf26073e79A6B250f458fFB8"
)
})

test("Send multiple compressedOps", async () => {
Expand Down Expand Up @@ -246,20 +266,33 @@ describe("V0.6 pimlico_sendCompressedUserOperation", () => {

await sendBundleNow()

expect(
(
await pimlicoBundlerClient.waitForUserOperationReceipt({
hash: firstHash
})
).success
).toEqual(true)
expect(
(
await pimlicoBundlerClient.waitForUserOperationReceipt({
hash: secondHash
})
).success
).toEqual(true)
const firstReceipt =
await pimlicoBundlerClient.waitForUserOperationReceipt({
hash: firstHash
})

const secondReceipt =
await pimlicoBundlerClient.waitForUserOperationReceipt({
hash: secondHash
})

expect(firstReceipt.success).toEqual(true)
expect(secondReceipt.success).toEqual(true)

const firstTx = await publicClient.getTransaction({
hash: firstReceipt.receipt.transactionHash
})
const secondTx = await publicClient.getTransaction({
hash: firstReceipt.receipt.transactionHash
})

expect(getAddress(firstTx.to || zeroAddress)).toEqual(
"0x09aeBCF1DF7d4D0FBf26073e79A6B250f458fFB8"
)

expect(getAddress(secondTx.to || zeroAddress)).toEqual(
"0x09aeBCF1DF7d4D0FBf26073e79A6B250f458fFB8"
)

expect(
await publicClient.getBalance({ address: to })
Expand Down

0 comments on commit 78d12ab

Please sign in to comment.