Skip to content

Commit ef6e82b

Browse files
committed
Add test cases
1 parent 9689974 commit ef6e82b

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/__tests__/native-token.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getChainConfigs } from "../utils";
3+
4+
describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))(
5+
`Should configure native token`,
6+
({ name, tokens }) => {
7+
it(name, () => {
8+
expect(tokens.some((t) => t.type === "native")).not.toBeFalsy();
9+
});
10+
},
11+
);

src/__tests__/target-chain.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getChainConfigs } from "../utils";
3+
4+
describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))(
5+
`Test cross's target network: $network`,
6+
({ network, tokens }) => {
7+
describe.each(tokens)(`$symbol`, (token) => {
8+
if (token.cross.length) {
9+
it.each(token.cross)(`$target.network`, (cross) => {
10+
expect(cross.target.network).not.toBe(network);
11+
});
12+
} else {
13+
it("Cross is empty", () => {
14+
expect(token.cross.length).toEqual(0);
15+
});
16+
}
17+
});
18+
},
19+
);

src/__tests__/target-token.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getChainConfig, getChainConfigs } from "../utils";
3+
4+
describe.each(getChainConfigs(true).filter((c) => !!c.tokens.length))(
5+
`Should configure target token`,
6+
({ network, tokens }) => {
7+
describe.each(tokens)(`Cross $symbol from ${network}`, (token) => {
8+
if (token.cross.length) {
9+
it.each(token.cross)(`to $target.network $target.symbol`, (cross) => {
10+
expect(
11+
getChainConfig(cross.target.network)?.tokens.find((t) => t.symbol === cross.target.symbol),
12+
).not.toBeUndefined();
13+
});
14+
} else {
15+
it("Cross is empty", () => {
16+
expect(token.cross.length).toEqual(0);
17+
});
18+
}
19+
});
20+
},
21+
);

src/__tests__/token-decimals.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it } from "vitest";
2+
import { 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 && c.network !== "taiko"))(
7+
`Test token's decimals: $name`,
8+
({ tokens, ...chain }) => {
9+
const publicClient = createPublicClient({ chain, transport: http() });
10+
11+
it.each(tokens)(`$symbol`, async (token) => {
12+
if (token.type === "native") {
13+
expect(token.decimals).toEqual(18);
14+
} else {
15+
const decimals = await publicClient.readContract({ address: token.address, abi, functionName: "decimals" });
16+
expect(token.decimals).toEqual(decimals);
17+
}
18+
});
19+
},
20+
);

0 commit comments

Comments
 (0)