Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed May 29, 2024
1 parent bbaa540 commit a686d67
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 71 deletions.
38 changes: 38 additions & 0 deletions src/__tests__/chain-config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { getChainConfig, getChainConfigs } from "../utils";
import { createPublicClient, http } from "viem";
import abi from "../abi/erc20";

describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))("$name", ({ tokens, ...chain }) => {
const publicClient = createPublicClient({ chain, transport: http() });

it("Should configure native token", () => {
expect(tokens.some((t) => t.type === "native")).not.toBeFalsy();
});

describe.each(tokens.filter((t) => !!t.cross.length))("$symbol", (token) => {
it.each(token.cross)(
`The target chain should not be configured as the source chain: '${chain.network}' => $target.network`,
(cross) => {
expect(cross.target.network).not.toBe(chain.network);
},
);

it.each(token.cross)("The target chain should already be configured: $target.network", (cross) => {
expect(getChainConfig(cross.target.network)).toBeDefined();
});

it.each(token.cross)("The target token should already be configured: $target.symbol", (cross) => {
expect(getChainConfig(cross.target.network)?.tokens.find((t) => t.symbol === cross.target.symbol)).toBeDefined();
});

it.skipIf(chain.network === "taiko")(`Should configure the correct decimals: '${token.decimals}'`, async () => {
if (token.type === "native") {
expect(token.decimals).toEqual(18);
} else {
const decimals = await publicClient.readContract({ address: token.address, abi, functionName: "decimals" });
expect(token.decimals).toEqual(decimals);
}
});
});
});
11 changes: 0 additions & 11 deletions src/__tests__/native-token.spec.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/__tests__/target-chain.spec.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/__tests__/target-token.spec.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/__tests__/token-decimals.spec.ts

This file was deleted.

0 comments on commit a686d67

Please sign in to comment.