Skip to content

Commit

Permalink
Test cases (#723)
Browse files Browse the repository at this point in the history
* Remove js and ts from taillwind content

* Setup vitest

* Add test cases
  • Loading branch information
JayJay1024 authored May 20, 2024
1 parent 7ab7e9f commit 800126d
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 4 deletions.
454 changes: 453 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:mainnet": "tsc && vite build --mode mainnet",
"build:testnet": "tsc && vite build --mode testnet",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "echo test",
"test": "vitest --run --silent",
"preview": "vite preview",
"format": "prettier 'src/**/*.{js,jsx,ts,tsx,json}' --write",
"prepare": "husky"
Expand Down Expand Up @@ -68,6 +68,7 @@
"prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "^3.4.3",
"typescript": "^5.2.2",
"vite": "^5.2.0"
"vite": "^5.2.0",
"vitest": "^1.6.0"
}
}
11 changes: 11 additions & 0 deletions src/__tests__/native-token.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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();
});
},
);
19 changes: 19 additions & 0 deletions src/__tests__/target-chain.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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);
});
}
});
},
);
21 changes: 21 additions & 0 deletions src/__tests__/target-token.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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);
});
}
});
},
);
20 changes: 20 additions & 0 deletions src/__tests__/token-decimals.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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);
}
});
},
);
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
content: ["./index.html", "./src/**/*.{jsx,tsx}"],
theme: {
extend: {
backgroundImage: {
Expand Down
2 changes: 2 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

Expand Down

0 comments on commit 800126d

Please sign in to comment.