Skip to content

Commit

Permalink
feat: added tests for bundler + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
GabiDev45 committed Mar 20, 2024
1 parent 658b871 commit 6dcde56
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/accounts/actions/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/actions/sendTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/actions/getUserOperationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
2 changes: 1 addition & 1 deletion src/client/decorators/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 45 additions & 7 deletions tests/ep6/bundler.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
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({
chain,
transport: http(bundlerUrl)
})
expect(bundlerClient.uid).toBeDefined()
expect(bundlerClient?.chain?.id).toBe(chainId)
expect(bundlerClient?.chain?.id).toBe(chain.id)
expect(bundlerClient.pollingInterval).toBeDefined()
})

Expand All @@ -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)
})

0 comments on commit 6dcde56

Please sign in to comment.