From 3229b23ee02b3c6262654d3fdf79531678b8945c Mon Sep 17 00:00:00 2001 From: Joe Pegler Date: Tue, 27 Aug 2024 22:44:53 +0100 Subject: [PATCH] chore: fix tests --- src/account/utils/Helpers.ts | 16 +--------------- tests/instances/account.test.ts | 10 +--------- tests/instances/bundler.test.ts | 18 ++++++++++++++++-- tests/test.utils.ts | 2 +- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/account/utils/Helpers.ts b/src/account/utils/Helpers.ts index 4d154c22..5955f233 100644 --- a/src/account/utils/Helpers.ts +++ b/src/account/utils/Helpers.ts @@ -13,18 +13,4 @@ export const isDebugging = (): boolean => { } catch (e) { return false } -} - -export const pollFunction = async ( - fn: () => Promise, - interval: number, - timeout: number -): Promise => { - const start = Date.now() - let result = await fn() - while (!result && Date.now() - start < timeout) { - await new Promise((resolve) => setTimeout(resolve, interval)) - result = await fn() - } - return result -} +} \ No newline at end of file diff --git a/tests/instances/account.test.ts b/tests/instances/account.test.ts index cb42e133..5d4946c3 100644 --- a/tests/instances/account.test.ts +++ b/tests/instances/account.test.ts @@ -13,13 +13,7 @@ import { type Transaction, createSmartAccountClient } from "../../src/account" -import { - getTestAccount, - killNetwork, - toTestClient, - topUp, - writeToFile -} from "../test.utils" +import { getTestAccount, killNetwork, toTestClient, topUp } from "../test.utils" import type { MasterClient, NetworkConfig } from "../test.utils" import { type TestFileNetworkType, toNetwork } from "../testSetup" @@ -77,8 +71,6 @@ describe("account", () => { testClient.getBytecode({ address: contracts.k1ValidatorFactory.address }), testClient.getBytecode({ address: contracts.k1Validator.address }) ]) - const [k1ValidatorFactory, k1Validator] = byteCodes - writeToFile("byteCodes.json", { k1ValidatorFactory, k1Validator }) expect(byteCodes.every(Boolean)).toBe(true) }) diff --git a/tests/instances/bundler.test.ts b/tests/instances/bundler.test.ts index 55c18fe9..2f091410 100644 --- a/tests/instances/bundler.test.ts +++ b/tests/instances/bundler.test.ts @@ -7,6 +7,7 @@ import { createWalletClient } from "viem" import { afterAll, beforeAll, describe, expect, test } from "vitest" +import contracts from "../../src/__contracts" import { type NexusSmartAccount, type Transaction, @@ -24,11 +25,14 @@ describe("bundler", () => { // Nexus Config let chain: Chain let bundlerUrl: string + let factoryAddress: Hex + let k1ValidatorAddress: Hex let walletClient: WalletClient // Test utils let testClient: MasterClient let account: Account + let recipientAccount: Account let smartAccount: NexusSmartAccount let smartAccountAddress: Hex @@ -39,6 +43,7 @@ describe("bundler", () => { bundlerUrl = network.bundlerUrl account = getTestAccount(0) + recipientAccount = getTestAccount(3) walletClient = createWalletClient({ account, @@ -55,11 +60,20 @@ describe("bundler", () => { }) smartAccountAddress = await smartAccount.getAddress() + // await fundAndDeploy(testClient, smartAccount) }) afterAll(async () => { await killNetwork([network.rpcPort, network.bundlerPort]) }) + test("byteCodes", async () => { + const byteCodes = await Promise.all([ + testClient.getBytecode({ address: contracts.k1ValidatorFactory.address }), + testClient.getBytecode({ address: contracts.k1Validator.address }) + ]) + expect(byteCodes.every(Boolean)).toBe(true) + }) + test("topUp", async () => { const total = await testClient.getBalance({ address: testClient.account.address @@ -81,7 +95,7 @@ describe("bundler", () => { ]) }) - test("should send eth", async () => { + test("send eth", async () => { const tx: Transaction = { to: account.address, value: 1n @@ -89,7 +103,7 @@ describe("bundler", () => { const { wait } = await smartAccount.sendTransaction(tx) - const { success } = await wait() + const { success, receipt } = await wait() expect(success).toBe(true) }) diff --git a/tests/test.utils.ts b/tests/test.utils.ts index 4a53e579..1d4bc7da 100644 --- a/tests/test.utils.ts +++ b/tests/test.utils.ts @@ -378,4 +378,4 @@ const deployContracts = async (rpcPort: number): Promise => { } export const sleep = (ms: number) => - new Promise((resolve) => setTimeout(resolve, ms)) \ No newline at end of file + new Promise((resolve) => setTimeout(resolve, ms))