From 35044941b034b18e4ef8e6a1347410fe01ef9220 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 25 Sep 2020 11:20:12 +0200 Subject: [PATCH] Fix test related to the LTV change --- .../flash-liquidation-with-collateral.spec.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/flash-liquidation-with-collateral.spec.ts b/test/flash-liquidation-with-collateral.spec.ts index 3b20f79c..15dac674 100644 --- a/test/flash-liquidation-with-collateral.spec.ts +++ b/test/flash-liquidation-with-collateral.spec.ts @@ -833,12 +833,13 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn await oracle.setAssetPrice(dai.address, daiPrice); }); - it('User 5 deposits WETH and DAI, then borrows USDC at Variable, then disables WETH as collateral', async () => { + it('User 4 deposits WETH, LEND and DAI, then borrows USDC at Variable, then disables WETH as collateral', async () => { const {pool, weth, dai, usdc, users} = testEnv; const user = users[4]; const amountWETHToDeposit = parseEther('10'); - const amountDAIToDeposit = parseEther('60'); - const amountToBorrow = parseUnits('65', 6); + const amountDAIToDeposit = parseEther('100'); + + const amountToBorrow = parseUnits('75', 6); await weth.connect(user.signer).mint(amountWETHToDeposit); await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); @@ -851,8 +852,8 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn await pool.connect(user.signer).borrow(usdc.address, amountToBorrow, 2, 0, user.address); }); - it('Liquidator tries to liquidates User 5 USDC loan by swapping his WETH collateral, should revert due WETH collateral disabled', async () => { - const {pool, weth, usdc, users, mockSwapAdapter, oracle} = testEnv; + it('Liquidator tries to liquidate User 5 USDC loan by swapping his WETH collateral, should revert due WETH collateral disabled', async () => { + const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle} = testEnv; const user = users[4]; const liquidator = users[5]; @@ -874,6 +875,14 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn expect(wethUserDataBefore.usageAsCollateralEnabled).to.be.false; + //drop the price to set the HF below 1 + const daiPrice = await oracle.getAssetPrice(dai.address); + + await oracle.setAssetPrice( + dai.address, + new BigNumber(daiPrice.toString()).multipliedBy(0.9).toFixed(0) + ); + // Liquidator should NOT be able to liquidate himself with WETH, even if is disabled await mockSwapAdapter.setAmountToReturn(amountToRepay); await expect( @@ -888,6 +897,7 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn '0x' ) ).to.be.revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED); + const repayWithCollateralTimestamp = await timeLatest(); const {userData: wethUserDataAfter} = await getContractsData(