forked from compound-finance/comet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset-info-test.ts
94 lines (84 loc) · 2.87 KB
/
asset-info-test.ts
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
import { expect, exp, makeProtocol, ONE } from './helpers';
describe('asset info', function () {
it('initializes protocol', async () => {
const { comet, tokens } = await makeProtocol({
assets: {
USDC: {},
ASSET1: {},
ASSET2: {},
ASSET3: {},
},
reward: 'ASSET1',
});
const cometNumAssets = await comet.numAssets();
const cometMaxAssets = await comet.maxAssets();
expect(cometMaxAssets).to.be.equal(15);
expect(cometNumAssets).to.be.equal(3);
const assetInfo00 = await comet.getAssetInfo(0);
expect(assetInfo00.asset).to.be.equal(tokens['ASSET1'].address);
expect(assetInfo00.borrowCollateralFactor).to.equal(ONE - exp(1, 14));
expect(assetInfo00.liquidateCollateralFactor).to.equal(ONE);
const assetInfo01 = await comet.getAssetInfo(1);
expect(assetInfo01.asset).to.be.equal(tokens['ASSET2'].address);
expect(assetInfo01.borrowCollateralFactor).to.equal(ONE - exp(1, 14));
expect(assetInfo01.liquidateCollateralFactor).to.equal(ONE);
const assetInfo02 = await comet.getAssetInfo(2);
expect(assetInfo02.asset).to.be.equal(tokens['ASSET3'].address);
expect(assetInfo02.borrowCollateralFactor).to.equal(ONE - exp(1, 14));
expect(assetInfo02.liquidateCollateralFactor).to.equal(ONE);
});
it('reverts if too many assets are passed', async () => {
await expect(
makeProtocol({
assets: {
USDC: {},
ASSET1: {},
ASSET2: {},
ASSET3: {},
ASSET4: {},
ASSET5: {},
ASSET6: {},
ASSET7: {},
ASSET8: {},
ASSET9: {},
ASSET10: {},
ASSET11: {},
ASSET12: {},
ASSET13: {},
ASSET14: {},
ASSET15: {},
ASSET16: {},
},
reward: 'ASSET1',
})
).to.be.revertedWith("custom error 'TooManyAssets()'");
});
it('reverts if index is greater than numAssets', async () => {
const { comet } = await makeProtocol();
await expect(comet.getAssetInfo(3)).to.be.revertedWith("custom error 'BadAsset()'");
});
it('reverts if collateral factors are out of range', async () => {
await expect(makeProtocol({
assets: {
USDC: {},
ASSET1: {borrowCF: exp(0.9, 18), liquidateCF: exp(0.9, 18)},
ASSET2: {},
},
})).to.be.revertedWith("custom error 'BorrowCFTooLarge()'");
// check descaled factors
await expect(makeProtocol({
assets: {
USDC: {},
ASSET1: {borrowCF: exp(0.9, 18), liquidateCF: exp(0.9, 18) + 1n},
ASSET2: {},
},
})).to.be.revertedWith("custom error 'BorrowCFTooLarge()'");
await expect(makeProtocol({
assets: {
USDC: {},
ASSET1: {borrowCF: exp(0.99, 18), liquidateCF: exp(1.1, 18)},
ASSET2: {},
},
})).to.be.revertedWith("custom error 'LiquidateCFTooLarge()'");
});
});