Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit 50196a1

Browse files
add tests for risk manager with undefined uniswap factory
1 parent b36aaa2 commit 50196a1

File tree

5 files changed

+239
-2
lines changed

5 files changed

+239
-2
lines changed

test/activateMarket.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ et.testSet({
1010

1111

1212
.test({
13-
desc: "re-activate",
13+
desc: "re-activate after uniswap activation",
1414
actions: ctx => [
1515
{ from: ctx.wallet, send: 'markets.activateMarket', args: [ctx.contracts.tokens.UTST.address], },
1616

@@ -32,6 +32,31 @@ et.testSet({
3232
})
3333

3434

35+
.test({
36+
desc: "re-activate after chainlink activation",
37+
actions: ctx => [
38+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
39+
args: [ctx.contracts.tokens.UTST2.address, NON_ZERO_ADDRESS],
40+
},
41+
42+
{ call: 'markets.underlyingToEToken', args: [ctx.contracts.tokens.UTST2.address], onResult: r => {
43+
ctx.stash.eTokenAddr = r;
44+
}},
45+
46+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
47+
args: [ctx.contracts.tokens.UTST2.address, NON_ZERO_ADDRESS],
48+
expectError: 'e/market/underlying-already-activated'
49+
},
50+
51+
{ from: ctx.wallet, send: 'markets.activateMarket', args: [ctx.contracts.tokens.UTST2.address], },
52+
53+
{ call: 'markets.underlyingToEToken', args: [ctx.contracts.tokens.UTST2.address], onResult: r => {
54+
et.expect(ctx.stash.eTokenAddr).to.equal(r);
55+
}},
56+
],
57+
})
58+
59+
3560
.test({
3661
desc: "invalid contracts",
3762
actions: ctx => [

test/activateMarketNoUniswap.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const et = require('./lib/eTestLib');
2+
3+
const PRICINGTYPE__CHAINLINK = 4
4+
const NON_ZERO_ADDRESS = '0x0000000000000000000000000000000000000001'
5+
6+
et.testSet({
7+
desc: "activating markets without uniswap",
8+
fixture: 'testing-no-uniswap'
9+
})
10+
11+
12+
.test({
13+
desc: "re-activate",
14+
actions: ctx => [
15+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
16+
args: [ctx.contracts.tokens.WETH.address, NON_ZERO_ADDRESS],
17+
},
18+
19+
{ call: 'markets.underlyingToEToken', args: [ctx.contracts.tokens.WETH.address], onResult: r => {
20+
ctx.stash.eTokenAddr = r;
21+
}},
22+
23+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
24+
args: [ctx.contracts.tokens.WETH.address, NON_ZERO_ADDRESS],
25+
expectError: 'e/market/underlying-already-activated'
26+
},
27+
28+
{ from: ctx.wallet, send: 'markets.activateMarket', args: [ctx.contracts.tokens.WETH.address], },
29+
30+
{ call: 'markets.underlyingToEToken', args: [ctx.contracts.tokens.WETH.address], onResult: r => {
31+
et.expect(ctx.stash.eTokenAddr).to.equal(r);
32+
}},
33+
],
34+
})
35+
36+
37+
.test({
38+
desc: "invalid contracts",
39+
actions: ctx => [
40+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
41+
args: [ctx.contracts.euler.address, NON_ZERO_ADDRESS],
42+
expectError: 'e/markets/invalid-token',
43+
},
44+
45+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
46+
args: [ctx.contracts.tokens.WETH.address, NON_ZERO_ADDRESS],
47+
},
48+
{ action: 'cb', cb: async () => {
49+
const eWETH = await ctx.contracts.markets.underlyingToEToken(ctx.contracts.tokens.WETH.address);
50+
const dWETH = await ctx.contracts.markets.underlyingToDToken(ctx.contracts.tokens.WETH.address);
51+
52+
let msg;
53+
await ctx.contracts.markets.activateMarketWithChainlinkPriceFeed(eWETH, NON_ZERO_ADDRESS)
54+
.catch(e => {
55+
msg = e.message;
56+
});
57+
et.expect(msg).to.contains('e/markets/invalid-token');
58+
59+
msg = ""
60+
await ctx.contracts.markets.activateMarketWithChainlinkPriceFeed(dWETH, NON_ZERO_ADDRESS)
61+
.catch(e => {
62+
msg = e.message;
63+
});
64+
et.expect(msg).to.contains('e/markets/invalid-token');
65+
} },
66+
],
67+
})
68+
69+
70+
.test({
71+
desc: "no uniswap factory",
72+
actions: ctx => [
73+
// error for permissionless activation
74+
{ send: 'markets.activateMarket', args: [ctx.contracts.tokens.TST.address], expectError: 'e/markets/pricing-type-invalid', },
75+
76+
// succeeds for permissioned activation with Chainlink
77+
{ from: ctx.wallet, send: 'markets.activateMarketWithChainlinkPriceFeed',
78+
args: [ctx.contracts.tokens.TST.address, NON_ZERO_ADDRESS],
79+
},
80+
81+
{ call: 'markets.getPricingConfig', args: [ctx.contracts.tokens.TST.address], onResult: r => {
82+
et.expect(r.pricingType).to.equal(PRICINGTYPE__CHAINLINK);
83+
et.expect(r.pricingParameters).to.equal(0);
84+
}, },
85+
86+
{ call: 'markets.getChainlinkPriceFeedConfig', args: [ctx.contracts.tokens.TST.address], onResult: r => {
87+
et.expect(r).to.equal(NON_ZERO_ADDRESS);
88+
}, },
89+
],
90+
})
91+
92+
.run();

test/lib/eTestLib.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ async function deployContracts(provider, wallets, tokenSetupName) {
762762

763763
if (ctx.tokenSetup.riskManagerSettings) {
764764
riskManagerSettings = ctx.tokenSetup.riskManagerSettings;
765+
} else if (ctx.tokenSetup.dontUseUniswap) {
766+
riskManagerSettings = {
767+
referenceAsset: ctx.contracts.tokens['WETH'].address,
768+
uniswapFactory: ethers.constants.AddressZero,
769+
uniswapPoolInitCodeHash: ctx.uniswapV3PoolByteCodeHash,
770+
}
765771
} else {
766772
riskManagerSettings = {
767773
referenceAsset: ctx.contracts.tokens['WETH'].address,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
module.exports = {
2+
dontUseUniswap: true,
3+
testing: {
4+
tokens: [
5+
{
6+
name: "Wrapped ETH",
7+
symbol: "WETH",
8+
decimals: 18,
9+
},
10+
{
11+
name: "Test Token",
12+
symbol: "TST",
13+
decimals: 18,
14+
},
15+
{
16+
name: "Test Token 2",
17+
symbol: "TST2",
18+
decimals: 18,
19+
},
20+
{
21+
name: "Test Token 3",
22+
symbol: "TST3",
23+
decimals: 18,
24+
},
25+
{
26+
name: "Test Token 4",
27+
symbol: "TST4",
28+
decimals: 18,
29+
},
30+
{
31+
name: "Test Token 5",
32+
symbol: "TST5",
33+
decimals: 18,
34+
},
35+
{
36+
name: "Test Token 6",
37+
symbol: "TST6",
38+
decimals: 18,
39+
},
40+
{
41+
name: "Test Token 7",
42+
symbol: "TST7",
43+
decimals: 18,
44+
},
45+
{
46+
name: "Test Token 8",
47+
symbol: "TST8",
48+
decimals: 18,
49+
},
50+
{
51+
name: "Test Token 9",
52+
symbol: "TST9",
53+
decimals: 6,
54+
},
55+
{
56+
name: "Test Token 10",
57+
symbol: "TST10",
58+
decimals: 0,
59+
},
60+
{
61+
name: "Unactivated Test Token",
62+
symbol: "UTST",
63+
decimals: 18,
64+
},
65+
{
66+
name: "Test Token 11",
67+
symbol: "TST11",
68+
decimals: 18,
69+
},
70+
{
71+
name: "Test Token 12",
72+
symbol: "TST12",
73+
decimals: 8,
74+
},
75+
{
76+
name: "Test Token 13",
77+
symbol: "TST13",
78+
decimals: 18,
79+
},
80+
{
81+
name: "Test Token 14",
82+
symbol: "TST14",
83+
decimals: 18,
84+
},
85+
{
86+
name: "Euler Token",
87+
symbol: "EUL",
88+
decimals: 18,
89+
},
90+
],
91+
92+
uniswapPools: [
93+
["TST", "WETH"],
94+
["TST2", "WETH"],
95+
["TST3", "WETH"],
96+
["TST6", "WETH"],
97+
["TST9", "WETH"],
98+
["TST10", "WETH"],
99+
["TST11", "WETH"],
100+
["TST12", "WETH"],
101+
["TST13", "WETH"],
102+
["TST14", "WETH"],
103+
["UTST", "WETH"],
104+
],
105+
106+
activated: [
107+
],
108+
},
109+
};

test/lib/token-setups/testing.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ module.exports = {
6868
decimals: 0,
6969
},
7070
{
71-
name: "Unactivated Test Token",
71+
name: "Unactivated Test Token 1",
7272
symbol: "UTST",
7373
decimals: 18,
7474
},
75+
{
76+
name: "Unactivated Test Token 2",
77+
symbol: "UTST2",
78+
decimals: 18,
79+
},
7580
{
7681
name: "Test Token 11",
7782
symbol: "TST11",

0 commit comments

Comments
 (0)