Skip to content

Commit

Permalink
fix getUserOperationReceipt endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless-eth committed Oct 13, 2024
1 parent 4dd4e69 commit 1adc867
Showing 1 changed file with 76 additions and 21 deletions.
97 changes: 76 additions & 21 deletions test/e2e/tests/eth_getUserOperationReceipt.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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([
{
Expand All @@ -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<typeof entryPointVersion>
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<typeof entryPointVersion>
} 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<typeof entryPointVersion>
}

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()
Expand All @@ -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 {
Expand Down

0 comments on commit 1adc867

Please sign in to comment.