From b2f01d205380200aa63a56a7470f1ab27fa167d0 Mon Sep 17 00:00:00 2001 From: Nicolas Brugneaux Date: Wed, 2 Oct 2024 11:22:15 +0200 Subject: [PATCH] test: fixing async tests --- src/tests/e2e.test.ts | 28 +++++++++++++++++++++++----- src/tests/utils.test.ts | 36 ++++++++++++++---------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/tests/e2e.test.ts b/src/tests/e2e.test.ts index 2c8d1b43..7d7835f3 100644 --- a/src/tests/e2e.test.ts +++ b/src/tests/e2e.test.ts @@ -1,22 +1,26 @@ -import { beforeAll, expect, test } from "bun:test"; +import { + afterEach, + beforeAll, + beforeEach, + describe, + expect, + test, +} from "bun:test"; import { CeloContract, CeloTransactionTypesPlugin } from ".."; import Web3, { Address } from "web3"; import { stableTokenEurABI } from "@celo/abis"; -import { CeloChains } from "../utils"; +import { CeloChains, isWhitelisted } from "../utils"; let stable: CeloContract; let stableAddress: Address; const web3 = new Web3(CeloChains.alfajores.rpcUrl); -console.log(process.env.TEST_ACCOUNT_1!.slice(5)); -console.log(process.env.TEST_ACCOUNT_2!.slice(5)); const account = web3.eth.accounts.privateKeyToAccount( process.env.TEST_ACCOUNT_1 as string ); const account2 = web3.eth.accounts.privateKeyToAccount( process.env.TEST_ACCOUNT_2 as string ); - web3.eth.accounts.wallet?.add(account); beforeAll(async () => { @@ -97,3 +101,17 @@ test( }, { timeout: 10_000 } ); + +describe("dango", () => { + const _web3 = new Web3(CeloChains.dango.rpcUrl); + _web3.registerPlugin(new CeloTransactionTypesPlugin()); + + test("isWhitelisted", () => { + expect(_web3.celo.isValidFeeCurrency("0x123")).resolves.toBe(false); + expect( + _web3.celo.isValidFeeCurrency( + "0x4822e58de6f5e485eF90df51C41CE01721331dC0" + ) + ).resolves.toBe(true); + }); +}); diff --git a/src/tests/utils.test.ts b/src/tests/utils.test.ts index 7f4679ce..b40a4804 100644 --- a/src/tests/utils.test.ts +++ b/src/tests/utils.test.ts @@ -30,22 +30,22 @@ testWithAnvilL1("l1", (web3) => { web3.registerPlugin(plugin); describe("getContractAddressFromRegistry()", () => { - test("returns a contract address", async () => { + test("returns a contract address", () => { expect( - await getContractAddressFromRegistry(plugin, "FeeCurrencyWhitelist") - ).toMatch(/^0x[0-9a-f]{40}$/i); + getContractAddressFromRegistry(plugin, "FeeCurrencyWhitelist") + ).resolves.toMatch(/^0x[0-9a-f]{40}$/i); }); }); - describe("isCel2()", async () => { - expect(await isCel2(plugin)).toBe(false); + describe("isCel2()", () => { + expect(isCel2(plugin)).resolves.toBe(false); }); - test("isWhitelisted()", async () => { - expect(await isWhitelisted(plugin, "0x123")).toBe(false); + test("isWhitelisted()", () => { + expect(isWhitelisted(plugin, "0x123")).resolves.toBe(false); expect( - await isWhitelisted(plugin, "0xc47bde654fEDA0d1dF4880f8BF00a5c650738586") - ).toBe(true); + isWhitelisted(plugin, "0xc47bde654fEDA0d1dF4880f8BF00a5c650738586") + ).resolves.toBe(true); }); }); @@ -54,10 +54,10 @@ testWithAnvilL2("l2", (web3) => { web3.registerPlugin(plugin); describe("getContractAddressFromRegistry()", () => { - test("returns a contract address", async () => { + test("returns a contract address", () => { expect( - await getContractAddressFromRegistry(plugin, "FeeCurrencyDirectory") - ).toMatch(/^0x[0-9a-f]{40}$/i); + getContractAddressFromRegistry(plugin, "FeeCurrencyDirectory") + ).resolves.toMatch(/^0x[0-9a-f]{40}$/i); }); test("returns a non zero contract address", async () => { const address = await getContractAddressFromRegistry( @@ -74,15 +74,7 @@ testWithAnvilL2("l2", (web3) => { }); }); - describe("isCel2()", async () => { - expect(await isCel2(plugin)).toBe(true); - }); - - test("isWhitelisted", async () => { - web3.setProvider(CeloChains.dango.rpcUrl); - expect(await isWhitelisted(plugin, "0x123")).toBe(false); - expect( - await isWhitelisted(plugin, "0x4822e58de6f5e485eF90df51C41CE01721331dC0") - ).toBe(true); + describe("isCel2()", () => { + expect(isCel2(plugin)).resolves.toBe(true); }); });