forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
105 lines (93 loc) · 3.21 KB
/
test.js
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
const baseFields = {
pool: 'string',
chain: 'string',
project: 'string',
symbol: 'string',
};
const adapter = global.adapter;
const apy = global.apy;
const uniquePoolIdentifiersDB = global.uniquePoolIdentifiersDB;
const protocols = global.protocolsSlug;
describe(`Running ${process.env.npm_config_adapter} Test`, () => {
describe('Check for allowed field names', () => {
const optionalFields = [
'apy',
'apyBase',
'apyReward',
'underlyingTokens',
'rewardTokens',
];
const fields = [...Object.keys(baseFields), ...optionalFields, 'tvlUsd'];
apy.forEach((pool) => {
test(`Expects pool id ${
pool.pool
} to contain only allowed keys: ${fields} and has: ${Object.keys(
pool
)}`, () => {
expect(Object.keys(pool).every((f) => fields.includes(f))).toBe(true);
});
});
});
test('Check for unique pool ids', () => {
const poolIds = apy.map((pool) => pool.pool);
const uniquePoolIds = [...new Set(poolIds)];
expect(poolIds).toEqual(uniquePoolIds);
});
describe('Check apy data types', () => {
const apyFields = ['apy', 'apyBase', 'apyReward'];
apy.forEach((pool) => {
test(`Expects pool with id ${pool.pool} to have at least one number apy field`, () => {
expect(apyFields.map((field) => typeof pool[field])).toContain(
'number'
);
});
});
});
describe('Check tvl data type', () => {
apy.forEach((pool) => {
test(`tvlUsd field of pool with id ${pool.pool} should be number `, () => {
expect(typeof pool.tvlUsd).toBe('number');
});
});
});
describe('Check tokens data types', () => {
const tokenFields = ['rewardTokens', 'underlyingTokens'];
apy.forEach((pool) => {
tokenFields.forEach((field) => {
if (pool[field]) {
test(`${field} field of pool with id ${pool.pool} should be an Array of strings`, () => {
expect(Array.isArray(pool[field])).toBe(true);
const isStringArray =
pool[field].map((v) => typeof v).filter((v) => v === 'string')
.length === pool[field].length;
expect(isStringArray).toBe(true);
});
}
});
});
});
describe('Check other fields data types', () => {
apy.forEach((pool) => {
test(`Expect other fields of pool with id ${pool.pool} to match thier data types`, () => {
Object.entries(baseFields).map(([field, type]) => {
expect(typeof pool[field]).toBe(type);
});
});
});
});
describe('Check if pool id already used by other project', () => {
const uniqueIds = new Set(apy.map(({ pool }) => pool));
const duplicatedPoolIds = new Set(
[...uniqueIds].filter((p) => uniquePoolIdentifiersDB.has(p))
);
test('Expect duplicate ids array to be empty', () => {
expect(duplicatedPoolIds.size).toBe(0);
});
});
test('Check project field is constant in all pools and if folder name and project field in pool objects matches the information in /protocols slug', () => {
expect(new Set(apy.map((p) => p.project)).size).toBe(1);
expect(
protocolsSlug.includes(apy[0].project) && apy[0].project === adapter
).toBe(true);
});
});