From dee57aa592a96d388651ed32e7aab455f89be500 Mon Sep 17 00:00:00 2001 From: Jamie Pickett Date: Thu, 19 Jan 2023 14:59:23 -0500 Subject: [PATCH] added baseaggr of 10 to some tests --- test/constructor-testing.js | 236 ++++++++++++++++++++++++++++++++---- test/weth-usdc-testing.js | 6 +- 2 files changed, 218 insertions(+), 24 deletions(-) diff --git a/test/constructor-testing.js b/test/constructor-testing.js index 36e14f3..d32327c 100644 --- a/test/constructor-testing.js +++ b/test/constructor-testing.js @@ -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"); - }) -}) \ No newline at end of file + 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"); + }); +}); diff --git a/test/weth-usdc-testing.js b/test/weth-usdc-testing.js index 4655513..cbac376 100644 --- a/test/weth-usdc-testing.js +++ b/test/weth-usdc-testing.js @@ -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 @@ -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); @@ -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);