Skip to content

Commit

Permalink
Merge pull request #55 from mysofinance/add-extra-tests-small-aggr
Browse files Browse the repository at this point in the history
added baseaggr of 10 to some tests
  • Loading branch information
jpick713 authored Jan 19, 2023
2 parents a396dd6 + dee57aa commit 57d26a1
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 24 deletions.
236 changes: 215 additions & 21 deletions test/constructor-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,237 @@ const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Constructor Testing", function () {

const MONE = ethers.BigNumber.from("1000000000000000000"); //10**18
const ONE_USDC = ethers.BigNumber.from("1000000");
const ONE_ETH = MONE;
const _loanCcyToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const _loanCcyToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const _collCcyToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const _loanTenor = 86400;
const _maxLoanPerColl = ONE_USDC.mul(1000);
const _r1 = MONE.mul(2).div(10)
const _r2 = MONE.mul(2).div(100)
const _r1 = MONE.mul(2).div(10);
const _r2 = MONE.mul(2).div(100);
const _liquidityBnd1 = ONE_USDC.mul(100000);
const _liquidityBnd2 = ONE_USDC.mul(1000000);
const _minLoan = ONE_USDC.mul(100);

it("Should revert with invalid deployment parameters in constructor", async function () {
[deployer, lp1, lp2, lp3, lp4, lp5, borrower, ...addrs] = await ethers.getSigners();
[deployer, lp1, lp2, lp3, lp4, lp5, borrower, ...addrs] =
await ethers.getSigners();

// deploy pool
ConstructorTest = await ethers.getContractFactory("ConstructorTest");
ConstructorTest = await ConstructorTest.connect(deployer);
constructorTest = await ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0);
constructorTest = await ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
);
await constructorTest.deployed();

// test constructor reverts
await expect(ConstructorTest.deploy(ZERO_ADDRESS, _collCcyToken, 800, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidZeroAddress");
await expect(ConstructorTest.deploy(_loanCcyToken, ZERO_ADDRESS, 800, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidZeroAddress");
await expect(ConstructorTest.deploy(_loanCcyToken, _loanCcyToken, 800, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "IdenticalLoanAndCollCcy");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, 800, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidLoanTenor");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, 0, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidMaxLoanPerColl");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, 0, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 50, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidBaseAggrSize");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 101, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidBaseAggrSize");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, ONE_ETH)).to.be.revertedWithCustomError(constructorTest, "InvalidFee");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r2, _r1, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, 0, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd2, _liquidityBnd1, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidLiquidityBnds");
await expect(ConstructorTest.deploy(_loanCcyToken, _collCcyToken, _loanTenor, _maxLoanPerColl, _r1, _r2, 0, _liquidityBnd1, _minLoan, 100, 0)).to.be.revertedWithCustomError(constructorTest, "InvalidLiquidityBnds");
})
})
await expect(
ConstructorTest.deploy(
ZERO_ADDRESS,
_collCcyToken,
800,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidZeroAddress");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
ZERO_ADDRESS,
800,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidZeroAddress");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_loanCcyToken,
800,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "IdenticalLoanAndCollCcy");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
800,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidLoanTenor");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
0,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidMaxLoanPerColl");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
0,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
5,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidBaseAggrSize");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
101,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidBaseAggrSize");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
ONE_ETH
)
).to.be.revertedWithCustomError(constructorTest, "InvalidFee");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r2,
_r1,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
0,
_liquidityBnd1,
_liquidityBnd2,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidRateParams");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
_liquidityBnd2,
_liquidityBnd1,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidLiquidityBnds");
await expect(
ConstructorTest.deploy(
_loanCcyToken,
_collCcyToken,
_loanTenor,
_maxLoanPerColl,
_r1,
_r2,
0,
_liquidityBnd1,
_minLoan,
100,
0
)
).to.be.revertedWithCustomError(constructorTest, "InvalidLiquidityBnds");
});
});
6 changes: 3 additions & 3 deletions test/weth-usdc-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("WETH-USDC Pool Testing", function () {
// deploy pool
PoolWethUsdc = await ethers.getContractFactory("PoolWethUsdc");
PoolWethUsdc = await PoolWethUsdc.connect(deployer);
poolWethUsdc = await PoolWethUsdc.deploy(_loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 100, 0);
poolWethUsdc = await PoolWethUsdc.deploy(_loanTenor, _maxLoanPerColl, _r1, _r2, _liquidityBnd1, _liquidityBnd2, _minLoan, 10, 0);
await poolWethUsdc.deployed();

// approve DAI and WETH balances
Expand Down Expand Up @@ -279,7 +279,7 @@ describe("WETH-USDC Pool Testing", function () {
// lp2 claims via aggregate
benchmarkDiff = postClaimBal.sub(preClaimBal)
preClaimBal = await USDC.balanceOf(lp2.address);
await poolWethUsdc.connect(lp2).claimFromAggregated(lp2.address, [0, 100], false, timestamp+9999999);
await poolWethUsdc.connect(lp2).claimFromAggregated(lp2.address, [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], false, timestamp+9999999);
postClaimBal = await USDC.balanceOf(lp2.address);
diff = postClaimBal.sub(preClaimBal)
await expect(benchmarkDiff).to.be.equal(diff);
Expand Down Expand Up @@ -441,7 +441,7 @@ describe("WETH-USDC Pool Testing", function () {
timestamp = timestamp + 60*60*24*365;

// lp1 claims and reinvest
await poolWethUsdc.connect(lp1).claimFromAggregated(lp1.address, [0, 1000, 2000], true, timestamp + 60*60*24*365 + 1);
await poolWethUsdc.connect(lp1).claimFromAggregated(lp1.address, [0, 1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000], true, timestamp + 60*60*24*365 + 1);
// await poolWethUsdc.connect(lp2).claimFromAggregated([0, 99,199, 299, 399, 499, 599, 699, 799, 899, 999], false, timestamp+9999999);
// lp2 and lp3 claim without reinvest
await poolWethUsdc.connect(lp2).claimFromAggregated(lp2.address, [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000], false, timestamp+9999999);
Expand Down

0 comments on commit 57d26a1

Please sign in to comment.