From 6dcde5613f9248a82392f02787c61310de44e1b4 Mon Sep 17 00:00:00 2001 From: GabiDev Date: Wed, 20 Mar 2024 14:16:42 +0200 Subject: [PATCH] feat: added tests for bundler + refactor --- src/accounts/actions/sendTransaction.ts | 2 +- src/accounts/actions/sendTransactions.ts | 2 +- src/bundler/actions/getUserOperationStatus.ts | 2 +- ...eipt.ts => waitForUserOperationReceipt.ts} | 0 src/client/decorators/bundler.ts | 2 +- tests/ep6/bundler.test.ts | 52 ++++++++++++++++--- 6 files changed, 49 insertions(+), 11 deletions(-) rename src/bundler/actions/{waitForUserOperationRceipt.ts => waitForUserOperationReceipt.ts} (100%) diff --git a/src/accounts/actions/sendTransaction.ts b/src/accounts/actions/sendTransaction.ts index 84c59a963..0b3086e3e 100644 --- a/src/accounts/actions/sendTransaction.ts +++ b/src/accounts/actions/sendTransaction.ts @@ -7,7 +7,7 @@ import { toHex } from "viem" import type { Prettify } from "viem/chains" -import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationRceipt" +import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationReceipt" import type { UserOpReceipt } from "../../bundler/utils/types" import { getAction, parseAccount } from "../utils/helpers" import type { Middleware, SmartAccount } from "../utils/types" diff --git a/src/accounts/actions/sendTransactions.ts b/src/accounts/actions/sendTransactions.ts index 430ed2d0b..367353c62 100644 --- a/src/accounts/actions/sendTransactions.ts +++ b/src/accounts/actions/sendTransactions.ts @@ -9,7 +9,7 @@ import { toHex } from "viem" import type { Prettify } from "viem/chains" -import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationRceipt" +import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationReceipt" import { getAction, parseAccount } from "../utils/helpers" import type { GetAccountParameter, diff --git a/src/bundler/actions/getUserOperationStatus.ts b/src/bundler/actions/getUserOperationStatus.ts index 446e43492..a83de7274 100644 --- a/src/bundler/actions/getUserOperationStatus.ts +++ b/src/bundler/actions/getUserOperationStatus.ts @@ -21,6 +21,6 @@ export const getUserOpStatus = async < userOperationReceipt: response.userOperationReceipt } as UserOpStatus } catch (err) { - throw new Error("Error estimating gas fee values.") + throw new Error(`Error getting user op status. ${err}`) } } diff --git a/src/bundler/actions/waitForUserOperationRceipt.ts b/src/bundler/actions/waitForUserOperationReceipt.ts similarity index 100% rename from src/bundler/actions/waitForUserOperationRceipt.ts rename to src/bundler/actions/waitForUserOperationReceipt.ts diff --git a/src/client/decorators/bundler.ts b/src/client/decorators/bundler.ts index 67bce8f18..f23b79332 100644 --- a/src/client/decorators/bundler.ts +++ b/src/client/decorators/bundler.ts @@ -18,7 +18,7 @@ import { type SendUserOperationParameters, sendUserOperation } from "../../bundler/actions/sendUserOperation" -import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationRceipt" +import { waitForUserOperationReceipt } from "../../bundler/actions/waitForUserOperationReceipt" import type { BundlerClient } from "../../bundler/createBundlerClient" import type { EstimateUserOperationGasParameters, diff --git a/tests/ep6/bundler.test.ts b/tests/ep6/bundler.test.ts index 0005d709d..a1dd5fe41 100644 --- a/tests/ep6/bundler.test.ts +++ b/tests/ep6/bundler.test.ts @@ -1,12 +1,31 @@ -import { http } from "viem" +import { http, createPublicClient, createWalletClient, zeroAddress } from "viem" import { describe, expect, it } from "vitest" import { privateKeyToAccount } from "viem/accounts" +import { + getUserOperationHash, + walletClientToSmartAccountSigner +} from "../../src/accounts/utils/helpers.js" import { createBundlerClient } from "../../src/bundler/createBundlerClient.js" +import { + createSmartAccountClient, + signerToSmartAccount +} from "../../src/index.js" import { getChainConfig } from "../utils.js" describe("Bundler tests", () => { - const { bundlerUrl, chainId, chain } = getChainConfig() + const { bundlerUrl, chain } = getChainConfig() + const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`) + const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" + const walletClient = createWalletClient({ + account, + chain, + transport: http() + }) + const publicClient = createPublicClient({ + chain, + transport: http() + }) it("Should have the properties of a viem client", async () => { const bundlerClient = createBundlerClient({ @@ -14,7 +33,7 @@ describe("Bundler tests", () => { transport: http(bundlerUrl) }) expect(bundlerClient.uid).toBeDefined() - expect(bundlerClient?.chain?.id).toBe(chainId) + expect(bundlerClient?.chain?.id).toBe(chain.id) expect(bundlerClient.pollingInterval).toBeDefined() }) @@ -23,15 +42,34 @@ describe("Bundler tests", () => { chain, transport: http(bundlerUrl) }) - expect(await bundlerClient.chainId()).toBe(chainId) + expect(await bundlerClient.chainId()).toBe(chain.id) }) - it("Should get user operation status", async () => { + it("Should get user op status", async () => { const bundlerClient = createBundlerClient({ chain, transport: http(bundlerUrl) }) - expect(await bundlerClient.chainId()).toBe(chainId) - }) + const userOpHash = + "0xebea403d4701fe950c4fe4aeb117e457a930b843238430b9cc8c3cf502bb2cb0" + + const status = await bundlerClient.getUserOpStatus(userOpHash) + console.log("User Operation Status: ", status) + }, 35000) + + it("Should get user op receipt", async () => { + const bundlerClient = createBundlerClient({ + chain, + transport: http(bundlerUrl) + }) + + const userOpHash = + "0xebea403d4701fe950c4fe4aeb117e457a930b843238430b9cc8c3cf502bb2cb0" + + const receipt = await bundlerClient.getUserOperationReceipt({ + hash: userOpHash + }) + console.log("User Operation Receipt: ", receipt) + }, 35000) })