-
Notifications
You must be signed in to change notification settings - Fork 680
Expand file tree
/
Copy pathToken.test.ts
More file actions
108 lines (88 loc) · 2.5 KB
/
Copy pathToken.test.ts
File metadata and controls
108 lines (88 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { describe, expect, it } from "vitest";
import { TEST_CLIENT } from "~test/test-clients.js";
import { tokens } from "./Token.js";
describe.runIf(process.env.TW_SECRET_KEY)("tokens", () => {
it("should fetch tokens", async () => {
// Setup
const client = TEST_CLIENT;
// Test
const result = await tokens({ client });
// Verify
expect(result).toBeInstanceOf(Array);
// Basic structure validation
if (result.length > 0) {
const token = result[0];
expect(token).toBeDefined();
expect(token).toHaveProperty("chainId");
expect(token).toHaveProperty("address");
expect(token).toHaveProperty("decimals");
expect(token).toHaveProperty("symbol");
expect(token).toHaveProperty("name");
expect(token).toHaveProperty("prices");
if (token) {
expect(typeof token.chainId).toBe("number");
expect(typeof token.address).toBe("string");
expect(typeof token.decimals).toBe("number");
expect(typeof token.symbol).toBe("string");
expect(typeof token.name).toBe("string");
}
}
});
it("should exclude prices if includePrices is false", async () => {
// Setup
const client = TEST_CLIENT;
// Test
const result = await tokens({
client,
includePrices: false,
});
// Verify
expect(result).toBeInstanceOf(Array);
// All tokens should not have prices
for (const token of result) {
expect(token.prices).toBeUndefined();
}
});
it("should filter tokens by chainId", async () => {
// Setup
const client = TEST_CLIENT;
// Test
const result = await tokens({
chainId: 1,
client,
});
// Verify
expect(result).toBeInstanceOf(Array);
// All tokens should have chainId 1
for (const token of result) {
expect(token.chainId).toBe(1);
}
});
it("should respect limit parameter", async () => {
// Setup
const client = TEST_CLIENT;
// Test
const result = await tokens({
client,
limit: 5,
});
// Verify
expect(result).toBeInstanceOf(Array);
expect(result.length).toBeLessThanOrEqual(5);
});
it("should filter tokens by symbol", async () => {
// Setup
const client = TEST_CLIENT;
// Test
const result = await tokens({
client,
symbol: "ETH",
});
// Verify
expect(result).toBeInstanceOf(Array);
// All tokens should have symbol "ETH"
for (const token of result) {
expect(token.symbol).toContain("ETH");
}
});
});