Skip to content

Commit

Permalink
Split PoolModuleFundAdmin.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Apr 16, 2024
1 parent 3e2c718 commit 3285945
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 795 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from 'node:assert';
import { ethers } from 'ethers';
import { bootstrapWithMockMarketAndPool } from '../../bootstrap';

describe('PoolModule Admin createPool()', function () {
const { signers, systems, restore } = bootstrapWithMockMarketAndPool();

let owner: ethers.Signer, user1: ethers.Signer;

const secondPoolId = 3384692;

before('identify signers', async () => {
[owner, user1] = signers();
});

before(restore);

it('fails when pool already exists', async () => {});

before('give user1 permission to create pool', async () => {
await systems()
.Core.connect(owner)
.addToFeatureFlagAllowlist(
ethers.utils.formatBytes32String('createPool'),
await user1.getAddress()
);
});

before('create a pool', async () => {
await (
await systems()
.Core.connect(user1)
.createPool(secondPoolId, await user1.getAddress())
).wait();
});

it('pool is created', async () => {
assert.equal(await systems().Core.getPoolOwner(secondPoolId), await user1.getAddress());
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import assert from 'node:assert';
import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber';
import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert';
import { ethers } from 'ethers';
import { bn, bootstrapWithMockMarketAndPool } from '../../bootstrap';

describe('PoolModule Admin set pool collateral issuance ratio', function () {
const { signers, systems, collateralAddress, restore } = bootstrapWithMockMarketAndPool();

let owner: ethers.Signer, user1: ethers.Signer, user2: ethers.Signer;

const thirdPoolId = 3384633;

before('identify signers', async () => {
[owner, user1, user2] = signers();
});

before(restore);

before('give user1 permission to create pool', async () => {
await systems()
.Core.connect(owner)
.addToFeatureFlagAllowlist(
ethers.utils.formatBytes32String('createPool'),
await user1.getAddress()
);
});

before('create a pool', async () => {
await (
await systems()
.Core.connect(user1)
.createPool(thirdPoolId, await user1.getAddress())
).wait();
});

it('only works for owner', async () => {
await assertRevert(
systems()
.Core.connect(user2)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
collateralLimitD18: bn(10),
issuanceRatioD18: bn(2),
}),
`Unauthorized("${await user2.getAddress()}")`,
systems().Core
);
});

it('min collateral ratio is set to zero for the pool by default', async () => {
assert.equal(
await systems().Core.getPoolCollateralIssuanceRatio(thirdPoolId, collateralAddress()),
0
);
});

it('set the pool collateal issuance ratio to 200%', async () => {
await systems()
.Core.connect(user1)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
collateralLimitD18: bn(10),
issuanceRatioD18: bn(2),
});

assertBn.equal(
await systems().Core.getPoolCollateralIssuanceRatio(thirdPoolId, collateralAddress()),
bn(2)
);
});

it('can get pool collateral configuration', async () => {
await systems()
.Core.connect(user1)
.setPoolCollateralConfiguration(thirdPoolId, collateralAddress(), {
collateralLimitD18: bn(123),
issuanceRatioD18: bn(345),
});

const { collateralLimitD18, issuanceRatioD18 } =
await systems().Core.getPoolCollateralConfiguration(thirdPoolId, collateralAddress());
assert.deepEqual(
{ collateralLimitD18, issuanceRatioD18 },
{ collateralLimitD18: bn(123), issuanceRatioD18: bn(345) }
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assertBn from '@synthetixio/core-utils/utils/assertions/assert-bignumber';
import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert';
import { ethers } from 'ethers';
import { bootstrapWithMockMarketAndPool } from '../../bootstrap';

describe('PoolModule Admin setMinLiquidityRatio(uint256)', function () {
const { signers, systems, restore } = bootstrapWithMockMarketAndPool();

let owner: ethers.Signer, user1: ethers.Signer;

before('identify signers', async () => {
[owner, user1] = signers();
});

before(restore);

it('only works for owner', async () => {
await assertRevert(
systems().Core.connect(user1)['setMinLiquidityRatio(uint256)'](ethers.utils.parseEther('2')),
`Unauthorized("${await user1.getAddress()}")`,
systems().Core
);
});

it('is set when invoked successfully', async () => {
const value = ethers.utils.parseEther('2');
await systems().Core.connect(owner)['setMinLiquidityRatio(uint256)'](value);
assertBn.equal(await systems().Core['getMinLiquidityRatio()'](), value);
});
});
Loading

0 comments on commit 3285945

Please sign in to comment.