Skip to content

Commit b62d973

Browse files
committed
wip
1 parent 3cff504 commit b62d973

File tree

1 file changed

+131
-100
lines changed

1 file changed

+131
-100
lines changed

protocol/synthetix/test/integration/modules/core/PoolModuleFundAdmin.setPoolConfiguration.test.ts

Lines changed: 131 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import assert from 'node:assert';
22
import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber';
33
import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert';
4-
import { snapshotCheckpoint } from '@synthetixio/core-utils/utils/mocha/snapshot';
54
import { ethers } from 'ethers';
65
import hre from 'hardhat';
76
import { bootstrapWithMockMarketAndPool } from '../../bootstrap';
@@ -27,13 +26,27 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
2726
const One = ethers.utils.parseEther('1');
2827
const Hundred = ethers.utils.parseEther('100');
2928

30-
before('identify signers', async () => {
29+
const marketId2 = 2;
30+
31+
before(async () => {
3132
[owner, user1, user2] = signers();
32-
});
3333

34-
const marketId2 = 2;
34+
// give user1 permission to create pool
35+
await systems()
36+
.Core.connect(owner)
37+
.addToFeatureFlagAllowlist(
38+
ethers.utils.formatBytes32String('createPool'),
39+
await user1.getAddress()
40+
);
3541

36-
before('set dummy markets', async () => {
42+
// create a pool
43+
await (
44+
await systems()
45+
.Core.connect(user1)
46+
.createPool(secondPoolId, await user1.getAddress())
47+
).wait();
48+
49+
// set dummy markets
3750
const factory = await hre.ethers.getContractFactory('MockMarket');
3851
const MockMarket2 = await factory.connect(owner).deploy();
3952
const MockMarket3 = await factory.connect(owner).deploy();
@@ -43,8 +56,6 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
4356
await (await systems().Core.connect(owner).registerMarket(MockMarket3.address)).wait();
4457
});
4558

46-
const restore = snapshotCheckpoint(provider);
47-
4859
it('reverts when pool does not exist', async () => {
4960
await assertRevert(
5061
systems()
@@ -115,7 +126,13 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
115126
});
116127

117128
describe('repeat pool sets position', async () => {
118-
before(restore);
129+
let snapshotId: number;
130+
before(async () => {
131+
snapshotId = await provider().send('evm_snapshot', []);
132+
});
133+
after(async () => {
134+
await provider().send('evm_revert', [snapshotId]);
135+
});
119136

120137
before('set pool position', async () => {
121138
await systems()
@@ -133,11 +150,14 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
133150
});
134151

135152
describe('if one of the markets has a min delegation time', () => {
136-
const restore = snapshotCheckpoint(provider);
137-
153+
let snapshotId: number;
138154
before('set market min delegation time to something high', async () => {
155+
snapshotId = await provider().send('evm_snapshot', []);
139156
await MockMarket().setMinDelegationTime(86400);
140157
});
158+
after(async () => {
159+
await provider().send('evm_revert', [snapshotId]);
160+
});
141161

142162
it('fails when min delegation timeout not elapsed', async () => {
143163
await assertRevert(
@@ -152,23 +172,17 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
152172
);
153173
});
154174

155-
describe('after time passes', () => {
156-
before('fast forward', async () => {
157-
// for some reason `fastForward` doesn't seem to work with anvil
158-
await fastForwardTo((await getTime(provider())) + 86400, provider());
159-
});
175+
it('works after time passes', async () => {
176+
// for some reason `fastForward` doesn't seem to work with anvil
177+
await fastForwardTo((await getTime(provider())) + 86400, provider());
160178

161-
it('works', async () => {
162-
await systems()
163-
.Core.connect(owner)
164-
.setPoolConfiguration(poolId, [
165-
{ marketId: marketId(), weightD18: 1, maxDebtShareValueD18: One },
166-
{ marketId: marketId2, weightD18: 3, maxDebtShareValueD18: One },
167-
]);
168-
});
179+
await systems()
180+
.Core.connect(owner)
181+
.setPoolConfiguration(poolId, [
182+
{ marketId: marketId(), weightD18: 1, maxDebtShareValueD18: One },
183+
{ marketId: marketId2, weightD18: 3, maxDebtShareValueD18: One },
184+
]);
169185
});
170-
171-
after(restore);
172186
});
173187

174188
describe('pool changes staking position to add another market', async () => {
@@ -266,100 +280,100 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
266280
await MockMarket().setLocked(ethers.utils.parseEther('0'));
267281
});
268282

269-
describe('exit first market', () => {
270-
const restore = snapshotCheckpoint(provider);
283+
it('exit first market', async () => {
284+
const snapshotId = await provider().send('evm_snapshot', []);
271285

272-
before('set pool position', async () => {
273-
await systems()
274-
.Core.connect(owner)
275-
.setPoolConfiguration(poolId, [
276-
{ marketId: marketId2, weightD18: 3, maxDebtShareValueD18: One },
277-
]);
278-
});
286+
// set pool position
287+
await systems()
288+
.Core.connect(owner)
289+
.setPoolConfiguration(poolId, [
290+
{ marketId: marketId2, weightD18: 3, maxDebtShareValueD18: One },
291+
]);
279292

280-
it('returns pool position correctly', async () => {
281-
const distributions = await systems().Core.getPoolConfiguration(poolId);
293+
// returns pool position correctly
294+
const distributions = await systems().Core.getPoolConfiguration(poolId);
282295

283-
assertBn.equal(distributions[0].marketId, marketId2);
284-
assertBn.equal(distributions[0].weightD18, 3);
285-
assertBn.equal(distributions[0].maxDebtShareValueD18, One);
286-
});
296+
assertBn.equal(distributions[0].marketId, marketId2);
297+
assertBn.equal(distributions[0].weightD18, 3);
298+
assertBn.equal(distributions[0].maxDebtShareValueD18, One);
287299

288-
it('markets have same available liquidity', async () => {
289-
// marketId() gets to keep its available liquidity because when
290-
// the market exited when it did it "committed"
291-
assertBn.equal(
292-
await systems().Core.connect(owner).getWithdrawableMarketUsd(marketId()),
293-
debtAmount
294-
);
300+
// markets have same available liquidity
301+
// marketId() gets to keep its available liquidity because when
302+
// the market exited when it did it "committed"
303+
assertBn.equal(
304+
await systems().Core.connect(owner).getWithdrawableMarketUsd(marketId()),
305+
debtAmount
306+
);
295307

296-
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId()), 0);
297-
});
308+
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId()), 0);
298309

299-
after(restore);
310+
await provider().send('evm_revert', [snapshotId]);
300311
});
301312

302-
describe('exit second market', () => {
303-
const restore = snapshotCheckpoint(provider);
304-
305-
before('set pool position', async () => {
306-
await systems()
307-
.Core.connect(owner)
308-
.setPoolConfiguration(poolId, [
309-
{ marketId: marketId(), weightD18: 2, maxDebtShareValueD18: One.mul(2) },
310-
]);
311-
});
313+
it('exit second market', async () => {
314+
const snapshotId = await provider().send('evm_snapshot', []);
315+
// set pool position
316+
await systems()
317+
.Core.connect(owner)
318+
.setPoolConfiguration(poolId, [
319+
{ marketId: marketId(), weightD18: 2, maxDebtShareValueD18: One.mul(2) },
320+
]);
312321

313-
it('returns pool position correctly', async () => {
314-
const distributions = await systems().Core.getPoolConfiguration(poolId);
322+
// returns pool position correctly
323+
const distributions = await systems().Core.getPoolConfiguration(poolId);
315324

316-
assertBn.equal(distributions[0].marketId, marketId());
317-
assertBn.equal(distributions[0].weightD18, 2);
318-
assertBn.equal(distributions[0].maxDebtShareValueD18, One.mul(2));
319-
});
325+
assertBn.equal(distributions[0].marketId, marketId());
326+
assertBn.equal(distributions[0].weightD18, 2);
327+
assertBn.equal(distributions[0].maxDebtShareValueD18, One.mul(2));
320328

321-
it('available liquidity taken away from second market', async () => {
322-
// marketId2 never reported an increased balance so its liquidity is 0 as ever
323-
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId2), 0);
324-
});
329+
// available liquidity taken away from second market
330+
// marketId2 never reported an increased balance so its liquidity is 0 as ever
331+
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId2), 0);
325332

326-
after(restore);
333+
await provider().send('evm_revert', [snapshotId]);
327334
});
328335

329-
describe('exit both market', () => {
330-
before('set pool position', async () => {
331-
await systems().Core.connect(owner).setPoolConfiguration(poolId, []);
332-
});
336+
it('exit both market', async () => {
337+
const snapshotId = await provider().send('evm_snapshot', []);
333338

334-
it('returns pool position correctly', async () => {
335-
assert.deepEqual(await systems().Core.getPoolConfiguration(poolId), []);
336-
});
339+
// set pool position
340+
await systems().Core.connect(owner).setPoolConfiguration(poolId, []);
337341

338-
it('debt is still assigned', async () => {
339-
assertBn.equal(
340-
await systems().Core.callStatic.getVaultDebt(poolId, collateralAddress()),
341-
debtAmount
342-
);
343-
});
342+
// returns pool position correctly
343+
assert.deepEqual(await systems().Core.getPoolConfiguration(poolId), []);
344344

345-
it('markets have same available liquidity', async () => {
346-
// marketId() gets to keep its available liquidity because when
347-
// the market exited when it did it "committed"
348-
assertBn.equal(
349-
await systems().Core.connect(owner).getWithdrawableMarketUsd(marketId()),
350-
debtAmount
351-
);
345+
// debt is still assigned
346+
assertBn.equal(
347+
await systems().Core.callStatic.getVaultDebt(poolId, collateralAddress()),
348+
debtAmount
349+
);
352350

353-
// marketId2 never reported an increased balance so its liquidity is 0 as ever
354-
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId2), 0);
355-
});
351+
// markets have same available liquidity
352+
353+
// marketId() gets to keep its available liquidity because when
354+
// the market exited when it did it "committed"
355+
assertBn.equal(
356+
await systems().Core.connect(owner).getWithdrawableMarketUsd(marketId()),
357+
debtAmount
358+
);
359+
360+
// marketId2 never reported an increased balance so its liquidity is 0 as ever
361+
assertBn.equal(await systems().Core.connect(owner).getMarketCollateral(marketId2), 0);
362+
363+
await provider().send('evm_revert', [snapshotId]);
356364
});
357365
});
358366
});
359367
});
360368

361369
describe('sets max debt below current debt share', async () => {
362-
before(restore);
370+
let snapshotId: number;
371+
before(async () => {
372+
snapshotId = await provider().send('evm_snapshot', []);
373+
});
374+
after(async () => {
375+
await provider().send('evm_revert', [snapshotId]);
376+
});
363377

364378
before('raise maxLiquidityRatio', async () => {
365379
const value = ethers.utils.parseEther('0.2');
@@ -492,10 +506,15 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
492506
);
493507
});
494508

495-
const restore = snapshotCheckpoint(provider);
496-
497509
describe('and then the market reports balance above limit again', () => {
498-
before(restore);
510+
let snapshotId: number;
511+
before(async () => {
512+
snapshotId = await provider().send('evm_snapshot', []);
513+
});
514+
after(async () => {
515+
await provider().send('evm_revert', [snapshotId]);
516+
});
517+
499518
// testing the "soft" limit
500519
before('set market', async () => {
501520
await MockMarket().connect(user1).setReportedDebt(Hundred.add(One));
@@ -534,7 +553,13 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
534553
});
535554

536555
describe('and then the market reports balance above both pools limits', () => {
537-
before(restore);
556+
let snapshotId: number;
557+
before(async () => {
558+
snapshotId = await provider().send('evm_snapshot', []);
559+
});
560+
after(async () => {
561+
await provider().send('evm_revert', [snapshotId]);
562+
});
538563
// testing the "soft" limit
539564
before('set market', async () => {
540565
await MockMarket().connect(user1).setReportedDebt(Hundred.mul(1234));
@@ -575,7 +600,13 @@ describe('PoolModule Admin setPoolConfiguration()', function () {
575600
});
576601

577602
describe('when limit is higher than minLiquidityRatio', async () => {
578-
before(restore);
603+
let snapshotId: number;
604+
before(async () => {
605+
snapshotId = await provider().send('evm_snapshot', []);
606+
});
607+
after(async () => {
608+
await provider().send('evm_revert', [snapshotId]);
609+
});
579610

580611
before('set minLiquidityRatio', async () => {
581612
const value = ethers.utils.parseEther('2');

0 commit comments

Comments
 (0)