diff --git a/src/__tests__/chain-config.spec.ts b/src/__tests__/chain-config.spec.ts new file mode 100644 index 00000000..e7820c0c --- /dev/null +++ b/src/__tests__/chain-config.spec.ts @@ -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); + } + }); + }); +}); diff --git a/src/__tests__/native-token.spec.ts b/src/__tests__/native-token.spec.ts deleted file mode 100644 index 6cd144aa..00000000 --- a/src/__tests__/native-token.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { getChainConfigs } from "../utils"; - -describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))( - `Should configure native token`, - ({ name, tokens }) => { - it(name, () => { - expect(tokens.some((t) => t.type === "native")).not.toBeFalsy(); - }); - }, -); diff --git a/src/__tests__/target-chain.spec.ts b/src/__tests__/target-chain.spec.ts deleted file mode 100644 index 1fb0698c..00000000 --- a/src/__tests__/target-chain.spec.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { getChainConfigs } from "../utils"; - -describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))( - `Test cross's target network: $network`, - ({ network, tokens }) => { - describe.each(tokens)(`$symbol`, (token) => { - if (token.cross.length) { - it.each(token.cross)(`$target.network`, (cross) => { - expect(cross.target.network).not.toBe(network); - }); - } else { - it("Cross is empty", () => { - expect(token.cross.length).toEqual(0); - }); - } - }); - }, -); diff --git a/src/__tests__/target-token.spec.ts b/src/__tests__/target-token.spec.ts deleted file mode 100644 index 0c9fe30f..00000000 --- a/src/__tests__/target-token.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { getChainConfig, getChainConfigs } from "../utils"; - -describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))( - `Should configure target token`, - ({ network, tokens }) => { - describe.each(tokens)(`Cross $symbol from ${network}`, (token) => { - if (token.cross.length) { - it.each(token.cross)(`to $target.network $target.symbol`, (cross) => { - expect( - getChainConfig(cross.target.network)?.tokens.find((t) => t.symbol === cross.target.symbol), - ).not.toBeUndefined(); - }); - } else { - it("Cross is empty", () => { - expect(token.cross.length).toEqual(0); - }); - } - }); - }, -); diff --git a/src/__tests__/token-decimals.spec.ts b/src/__tests__/token-decimals.spec.ts deleted file mode 100644 index bfa2e884..00000000 --- a/src/__tests__/token-decimals.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { getChainConfigs } from "../utils"; -import { createPublicClient, http } from "viem"; -import abi from "../abi/erc20"; - -describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length && c.network !== "taiko"))( - `Test token's decimals: $name`, - ({ tokens, ...chain }) => { - const publicClient = createPublicClient({ chain, transport: http() }); - - it.each(tokens)(`$symbol`, async (token) => { - 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); - } - }); - }, -);