From 1adc8672b582d3c31f66ba3a5725de511043f8ce Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:06:39 +0100 Subject: [PATCH] fix getUserOperationReceipt endpoint --- .../tests/eth_getUserOperationReceipt.test.ts | 97 +++++++++++++++---- 1 file changed, 76 insertions(+), 21 deletions(-) diff --git a/test/e2e/tests/eth_getUserOperationReceipt.test.ts b/test/e2e/tests/eth_getUserOperationReceipt.test.ts index 50ee716e..01723981 100644 --- a/test/e2e/tests/eth_getUserOperationReceipt.test.ts +++ b/test/e2e/tests/eth_getUserOperationReceipt.test.ts @@ -1,8 +1,17 @@ -import { parseGwei, type Address, type Hex } from "viem" +import { + parseGwei, + type Address, + type Hex, + getContract, + parseEther, + concat +} from "viem" import { type EntryPointVersion, entryPoint06Address, - entryPoint07Address + entryPoint07Address, + UserOperation, + getUserOperationHash } from "viem/account-abstraction" import { beforeAll, beforeEach, describe, expect, test } from "vitest" import { @@ -12,6 +21,8 @@ import { } from "../src/revertingContract" import { deployPaymaster } from "../src/testPaymaster" import { beforeEachCleanUp, getSmartAccountClient } from "../src/utils" +import { deepHexlify } from "permissionless" +import { foundry } from "viem/chains" describe.each([ { @@ -37,28 +48,77 @@ describe.each([ await beforeEachCleanUp() }) + // uses pimlico_sendUserOperationNow to force send a reverting op (because it skips validation) test("Returns revert bytes when UserOperation reverts", async () => { const smartAccountClient = await getSmartAccountClient({ entryPointVersion }) - const hash = await smartAccountClient.sendUserOperation({ - calls: [ - { - to: revertingContract, - data: getRevertCall("foobar"), - value: 0n - } - ], - callGasLimit: 500_000n, - verificationGasLimit: 500_000n, - preVerificationGas: 500_000n + const { factory, factoryData } = + await smartAccountClient.account.getFactoryArgs() + + let op: UserOperation + if (entryPointVersion === "0.6") { + op = { + callData: await smartAccountClient.account.encodeCalls([ + { + to: revertingContract, + data: getRevertCall("foobar"), + value: 0n + } + ]), + initCode: concat([factory as Hex, factoryData as Hex]), + paymasterAndData: paymaster, + callGasLimit: 500_000n, + verificationGasLimit: 500_000n, + preVerificationGas: 500_000n, + sender: smartAccountClient.account.address, + nonce: 0n, + maxFeePerGas: parseGwei("10"), + maxPriorityFeePerGas: parseGwei("10") + } as UserOperation + } else { + op = { + sender: smartAccountClient.account.address, + nonce: 0n, + factory, + factoryData, + callData: await smartAccountClient.account.encodeCalls([ + { + to: revertingContract, + data: getRevertCall("foobar"), + value: 0n + } + ]), + callGasLimit: 500_000n, + verificationGasLimit: 500_000n, + preVerificationGas: 500_000n, + maxFeePerGas: parseGwei("10"), + maxPriorityFeePerGas: parseGwei("10"), + paymaster, + paymasterVerificationGasLimit: 100_000n, + paymasterPostOpGasLimit: 50_000n + } as UserOperation + } + + op.signature = + await smartAccountClient.account.signUserOperation(op) + + await smartAccountClient.request({ + // @ts-ignore + method: "pimlico_sendUserOperationNow", + params: [deepHexlify(op), entryPoint] }) await new Promise((resolve) => setTimeout(resolve, 1500)) const receipt = await smartAccountClient.getUserOperationReceipt({ - hash + hash: getUserOperationHash({ + userOperation: op, + chainId: foundry.id, + entryPointAddress: entryPoint, + entryPointVersion + }) }) expect(receipt).not.toBeNull() @@ -74,18 +134,13 @@ describe.each([ let hash: Hex if (entryPointVersion === "0.6") { hash = await smartAccountClient.sendUserOperation({ - callData: await smartAccountClient.account.encodeCalls([ + calls: [ { to: "0x23B608675a2B2fB1890d3ABBd85c5775c51691d5", data: "0x", value: 0n } - ]), - callGasLimit: 500_000n, - verificationGasLimit: 500_000n, - preVerificationGas: 500_000n, - maxFeePerGas: parseGwei("10"), - maxPriorityFeePerGas: parseGwei("10"), + ], paymasterAndData: paymaster }) } else {