Skip to content

Commit

Permalink
🚧 hh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina authored and cruzdanilo committed Dec 19, 2023
1 parent 8f48956 commit 65ab5b1
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 78 deletions.
1 change: 1 addition & 0 deletions test/hardhat/13_floating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe("Smart Pool", function () {
await wbtc.connect(bob).approve(marketWBTC.address, parseUnits("1", 8));
await marketWBTC.connect(bob).approve(john.address, parseUnits("1", 8));
await marketWBTC.connect(bob).deposit(parseUnits("1", 8), bob.address);
await ethers.provider.send("evm_increaseTime", [3_600]);
});
it("THEN bob's eWBTC balance is 1", async () => {
expect(await marketWBTC.balanceOf(bob.address)).to.equal(parseUnits("1", 8));
Expand Down
2 changes: 2 additions & 0 deletions test/hardhat/18_eth_market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ describe("ETHMarket - receive bare ETH instead of WETH", function () {
await weth.deposit({ value: parseUnits("60") });
await marketWETH.deposit(parseUnits("60"), alice.address);
await auditor.enterMarket(marketWETH.address);
await provider.send("evm_increaseTime", [3_600]);
});
describe("WHEN borrowing with ETH (native)", () => {
let tx: ContractTransaction;
Expand Down Expand Up @@ -631,6 +632,7 @@ describe("ETHMarket - receive bare ETH instead of WETH", function () {
await marketWETH.deposit(parseUnits("60"), alice.address);
await auditor.enterMarket(marketWETH.address);
tx = routerETH.borrowAtMaturity(futurePools(1)[0], parseUnits("5"), parseUnits("5"));
await provider.send("evm_increaseTime", [3_600]);
});
it("THEN the tx should revert with Disagreement", async () => {
await expect(tx).to.be.revertedWithCustomError(marketWETH, "Disagreement");
Expand Down
44 changes: 41 additions & 3 deletions test/hardhat/2_market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ describe("Market", function () {
penaltyRate = await marketDAI.penaltyRate();

await deploy("InterestRateModel", {
args: [AddressZero, 0, 0, parseUnits("6"), parseUnits("0.7")],
args: [
AddressZero,
0,
0,
parseUnits("6"),
parseUnits("0.7"),
parseUnits("2.5"),
parseUnits("1"),
parseUnits("10"),
parseUnits("0.2"),
parseUnits("0"),
parseUnits("0.5"),
],
from: owner.address,
});
irm = await getContract<InterestRateModel>("InterestRateModel", maria);
Expand All @@ -61,6 +73,7 @@ describe("Market", function () {
await weth.deposit({ value: parseUnits("10") });
await weth.approve(marketWETH.address, parseUnits("10"));
}
await provider.send("evm_increaseTime", [3_600]);
});

describe("small positions", () => {
Expand All @@ -69,6 +82,7 @@ describe("Market", function () {
await marketDAI.deposit(3, maria.address);
// add liquidity to the maturity
await marketDAI.depositAtMaturity(futurePools(1)[0], 3, 0, maria.address);
await provider.send("evm_increaseTime", [3_600]);
});
it("THEN the Market registers a supply of 3 wei DAI for the account (exposed via accountSnapshot)", async () => {
expect(await marketDAI.maxWithdraw(maria.address)).to.equal(3);
Expand Down Expand Up @@ -416,7 +430,19 @@ describe("Market", function () {
describe("GIVEN an interest rate of 2%", () => {
beforeEach(async () => {
const { address } = await deploy("InterestRateModel", {
args: [AddressZero, 0, parseUnits("0.02"), parseUnits("6"), parseUnits("0.7")],
args: [
AddressZero,
0,
parseUnits("0.02"),
parseUnits("6"),
parseUnits("0.7"),
parseUnits("2.5"),
parseUnits("1"),
parseUnits("10"),
parseUnits("0.2"),
parseUnits("0"),
parseUnits("0.5"),
],
from: owner.address,
});
await timelockExecute(owner, marketDAI, "setInterestRateModel", [address]);
Expand Down Expand Up @@ -453,7 +479,19 @@ describe("Market", function () {
await auditor.enterMarket(marketWETH.address);

const { address } = await deploy("InterestRateModel", {
args: [AddressZero, 0, 0, parseUnits("1.1"), parseUnits("0.7")],
args: [
AddressZero,
0,
0,
parseUnits("1.1"),
parseUnits("0.7"),
parseUnits("2.5"),
parseUnits("1"),
parseUnits("10"),
parseUnits("0.2"),
parseUnits("0"),
parseUnits("0.5"),
],
from: owner.address,
});
await timelockExecute(owner, marketDAI, "setInterestRateModel", [address]);
Expand Down
29 changes: 27 additions & 2 deletions test/hardhat/4_liquidity_computation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ describe("Liquidity computations", function () {
}

const { address: irm } = await deploy("InterestRateModel", {
args: [AddressZero, 0, 0, parseUnits("6"), parseUnits("0.7")],
args: [
AddressZero,
0,
0,
parseUnits("6"),
parseUnits("0.7"),
parseUnits("2.5"),
parseUnits("1"),
parseUnits("10"),
parseUnits("0.2"),
parseUnits("0"),
parseUnits("0.5"),
],
from: bob.address,
});
await timelockExecute(multisig, marketDAI, "setInterestRateModel", [irm]);
Expand All @@ -83,6 +95,7 @@ describe("Liquidity computations", function () {
describe("GIVEN laura deposits 1k dai to a smart pool", () => {
beforeEach(async () => {
await marketDAI.deposit(parseUnits("1000"), laura.address);
await provider.send("evm_increaseTime", [3_600]);
});

it("THEN lauras liquidity is adjustFactor*collateral - 0.8*1000 == 800, AND she has no shortfall", async () => {
Expand All @@ -100,7 +113,19 @@ describe("Liquidity computations", function () {
describe("AND GIVEN a 1% borrow interest rate", () => {
beforeEach(async () => {
const { address: irm } = await deploy("InterestRateModel", {
args: [AddressZero, 0, parseUnits("0.01"), parseUnits("6"), parseUnits("0.7")],
args: [
AddressZero,
0,
parseUnits("0.01"),
parseUnits("6"),
parseUnits("0.7"),
parseUnits("2.5"),
parseUnits("1"),
parseUnits("10"),
parseUnits("0.2"),
parseUnits("0"),
parseUnits("0.5"),
],
from: bob.address,
});
await timelockExecute(multisig, marketDAI, "setInterestRateModel", [irm]);
Expand Down
8 changes: 8 additions & 0 deletions test/hardhat/5_liquidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import futurePools from "./utils/futurePools";
const {
constants: { MaxUint256 },
utils: { parseUnits },
provider,
} = ethers;
const nextPoolID = futurePools(3)[2].toNumber();

Expand Down Expand Up @@ -65,6 +66,7 @@ describe("Liquidations", function () {
await exactlyEnv.depositMP("DAI", nextPoolID, "65000");
await dai.connect(bob).approve(marketDAI.address, parseUnits("200000"));
await dai.connect(john).approve(marketDAI.address, parseUnits("10000"));
await provider.send("evm_increaseTime", [3_600]);
});

describe("AND GIVEN Alice takes the biggest loan she can (31920 DAI), 31920/0.8=39900", () => {
Expand Down Expand Up @@ -316,18 +318,21 @@ describe("Liquidations", function () {

await exactlyEnv.depositSP("WETH", "10");
await exactlyEnv.enterMarket("WETH");
await provider.send("evm_increaseTime", [3_600]);
});
describe("AND GIVEN alice deposits 10k DAI to the smart pool AND borrows USD8k worth of WETH (80% collateralization rate)", () => {
beforeEach(async () => {
exactlyEnv.switchWallet(alice);
await exactlyEnv.depositSP("DAI", "10000");
await exactlyEnv.enterMarket("DAI");
await provider.send("evm_increaseTime", [3_600]);

await exactlyEnv.borrowMP("WETH", futurePools(1)[0].toNumber(), "0.93");
await exactlyEnv.borrowMP("WETH", futurePools(2)[1].toNumber(), "0.93");
});
describe("WHEN WETH price doubles AND john borrows 10k DAI from a maturity pool (all liquidity in smart pool)", () => {
beforeEach(async () => {
await provider.send("evm_increaseTime", [3_600 * 2]);
await exactlyEnv.setPrice(marketETH.address, parseUnits("8000", 8));
exactlyEnv.switchWallet(john);
await exactlyEnv.borrowMP("DAI", futurePools(1)[0].toNumber(), "10000");
Expand All @@ -345,6 +350,7 @@ describe("Liquidations", function () {
await dai.mint(john.address, parseUnits("10000"));
await exactlyEnv.depositSP("DAI", "10000");
await eth.connect(john).approve(marketETH.address, parseUnits("1"));
await provider.send("evm_increaseTime", [3_600]);
});
it("WHEN both of alice's positions are liquidated THEN it doesn't revert", async () => {
await expect(marketETH.connect(john).liquidate(alice.address, parseUnits("1"), marketDAI.address)).to.not.be
Expand Down Expand Up @@ -376,6 +382,7 @@ describe("Liquidations", function () {

await exactlyEnv.borrowMP("DAI", futurePools(1)[0].toNumber(), "1000");
await exactlyEnv.borrowMP("DAI", futurePools(2)[1].toNumber(), "6000");
await provider.send("evm_increaseTime", [3_600]);
});
describe("WHEN 20 days goes by without payment, WETH price halves AND alice's first borrow is liquidated with a higher amount as repayment", () => {
let johnETHBalanceBefore: BigNumber;
Expand Down Expand Up @@ -410,6 +417,7 @@ describe("Liquidations", function () {
await dai.connect(john).approve(marketDAI.address, MaxUint256);
await dai.mint(john.address, parseUnits("100000"));
await marketDAI.connect(john).deposit(parseUnits("100000"), john.address);
await provider.send("evm_increaseTime", [3_600]);

// distribute earnings to accumulator
await exactlyEnv.setBorrowRate("1");
Expand Down
Loading

0 comments on commit 65ab5b1

Please sign in to comment.