|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { getChainConfig, getChainConfigs } from "../utils"; |
| 3 | +import { createPublicClient, http } from "viem"; |
| 4 | +import abi from "../abi/erc20"; |
| 5 | + |
| 6 | +describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))("$name", ({ tokens, ...chain }) => { |
| 7 | + const publicClient = createPublicClient({ chain, transport: http() }); |
| 8 | + |
| 9 | + it("Should configure native token", () => { |
| 10 | + expect(tokens.some((t) => t.type === "native")).not.toBeFalsy(); |
| 11 | + }); |
| 12 | + |
| 13 | + describe.each(tokens.filter((t) => !!t.cross.length))("$symbol", (token) => { |
| 14 | + it.each(token.cross)( |
| 15 | + `The target chain should not be configured as the source chain: '${chain.network}' => $target.network`, |
| 16 | + (cross) => { |
| 17 | + expect(cross.target.network).not.toBe(chain.network); |
| 18 | + }, |
| 19 | + ); |
| 20 | + |
| 21 | + it.each(token.cross)("The target chain should already be configured: $target.network", (cross) => { |
| 22 | + expect(getChainConfig(cross.target.network)).toBeDefined(); |
| 23 | + }); |
| 24 | + |
| 25 | + it.each(token.cross)("The target token should already be configured: $target.symbol", (cross) => { |
| 26 | + expect(getChainConfig(cross.target.network)?.tokens.find((t) => t.symbol === cross.target.symbol)).toBeDefined(); |
| 27 | + }); |
| 28 | + |
| 29 | + it.skipIf(chain.network === "taiko")(`Should configure the correct decimals: '${token.decimals}'`, async () => { |
| 30 | + if (token.type === "native") { |
| 31 | + expect(token.decimals).toEqual(18); |
| 32 | + } else { |
| 33 | + const decimals = await publicClient.readContract({ address: token.address, abi, functionName: "decimals" }); |
| 34 | + expect(token.decimals).toEqual(decimals); |
| 35 | + } |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
0 commit comments