Skip to content

Commit

Permalink
test: fixing async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Oct 2, 2024
1 parent c13041e commit b2f01d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
28 changes: 23 additions & 5 deletions src/tests/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof stableTokenEurABI>;
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 () => {
Expand Down Expand Up @@ -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);
});
});
36 changes: 14 additions & 22 deletions src/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

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

0 comments on commit b2f01d2

Please sign in to comment.