mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Moved all pausable tests into their own Pausable test suite
This commit is contained in:
parent
b8a7237458
commit
202ddbdec4
|
@ -18,6 +18,7 @@
|
|||
"test-transfers": "buidler test test/__setup.spec.ts test/atoken-transfer.spec.ts",
|
||||
"test-flash": "buidler test test/__setup.spec.ts test/flashloan.spec.ts",
|
||||
"test-liquidate": "buidler test test/__setup.spec.ts test/liquidation-atoken.spec.ts",
|
||||
"test-pausable": "buidler test test/__setup.spec.ts test/pausable-functions.spec.ts",
|
||||
"dev:coverage": "buidler coverage --network coverage",
|
||||
"dev:deployment": "buidler dev-deployment",
|
||||
"dev:deployExample": "buidler deploy-Example",
|
||||
|
|
|
@ -80,104 +80,4 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
|
|||
TRANSFER_NOT_ALLOWED
|
||||
).to.be.revertedWith(TRANSFER_NOT_ALLOWED);
|
||||
});
|
||||
|
||||
it('User 0 deposits 1000 DAI. Configurator pauses pool. Transfers to user 1 reverts. Configurator unpauses the network and next transfer succees', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
|
||||
|
||||
const user0Balance = await aDai.balanceOf(users[0].address);
|
||||
const user1Balance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// User 0 tries the transfer to User 1
|
||||
await expect(
|
||||
aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit)
|
||||
).to.revertedWith(TRANSFER_NOT_ALLOWED);
|
||||
|
||||
const pausedFromBalance = await aDai.balanceOf(users[0].address);
|
||||
const pausedToBalance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(pausedFromBalance).to.be.equal(
|
||||
user0Balance.toString(),
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
expect(pausedToBalance.toString()).to.be.equal(
|
||||
user1Balance.toString(),
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
|
||||
// User 0 succeeds transfer to User 1
|
||||
await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit);
|
||||
|
||||
const fromBalance = await aDai.balanceOf(users[0].address);
|
||||
const toBalance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(fromBalance.toString()).to.be.equal(
|
||||
user0Balance.sub(amountDAItoDeposit),
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
expect(toBalance.toString()).to.be.equal(
|
||||
user1Balance.add(amountDAItoDeposit),
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
});
|
||||
|
||||
it('User 0 deposits 1000 DAI but reverts due pool is paused', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
await expect(
|
||||
pool.connect(users[0].signer).deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
|
||||
).to.revertedWith(IS_PAUSED);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 0 burns 1000 aDAI but reverts due pool is paused', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// user tries to burn
|
||||
await expect(
|
||||
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit)
|
||||
).to.revertedWith(IS_PAUSED);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -913,57 +913,4 @@ makeSuite('LendingPool. repayWithCollateral() with liquidator', (testEnv: TestEn
|
|||
|
||||
expect(wethUserDataAfter.usageAsCollateralEnabled).to.be.false;
|
||||
});
|
||||
|
||||
it('Liquidator tries to repay 7 user a bigger amount that what can be swapped of a particular collateral, but reverts due pool is paused', async () => {
|
||||
const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle, configurator} = testEnv;
|
||||
const user = users[6];
|
||||
const liquidator = users[5];
|
||||
|
||||
const amountToDepositWeth = parseEther('0.1');
|
||||
const amountToDepositDAI = parseEther('500');
|
||||
const amountToBorrowVariable = parseUnits('80', '6');
|
||||
|
||||
await weth.connect(user.signer).mint(amountToDepositWeth);
|
||||
await dai.connect(user.signer).mint(amountToDepositDAI);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await dai.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
await pool.connect(user.signer).deposit(weth.address, amountToDepositWeth, user.address, '0');
|
||||
await pool.connect(user.signer).deposit(dai.address, amountToDepositDAI, user.address, '0');
|
||||
|
||||
await pool.connect(user.signer).borrow(usdc.address, amountToBorrowVariable, 2, 0);
|
||||
|
||||
const amountToRepay = amountToBorrowVariable;
|
||||
|
||||
// Set HF below 1
|
||||
const daiPrice = await oracle.getAssetPrice(dai.address);
|
||||
await oracle.setAssetPrice(
|
||||
dai.address,
|
||||
new BigNumber(daiPrice.toString()).multipliedBy(0.1).toFixed(0)
|
||||
);
|
||||
const userGlobalDataPrior = await pool.getUserAccountData(user.address);
|
||||
expect(userGlobalDataPrior.healthFactor.toString()).to.be.bignumber.lt(oneEther, INVALID_HF);
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
|
||||
// Pause the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(
|
||||
pool
|
||||
.connect(liquidator.signer)
|
||||
.repayWithCollateral(
|
||||
weth.address,
|
||||
usdc.address,
|
||||
user.address,
|
||||
amountToRepay,
|
||||
mockSwapAdapter.address,
|
||||
'0x'
|
||||
)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -356,26 +356,4 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
|||
|
||||
expect(callerDebt.toString()).to.be.equal('800720000000000000', 'Invalid user debt');
|
||||
});
|
||||
|
||||
it('Caller tries to take a WETH flash loan but pool is paused', async () => {
|
||||
const {dai, pool, weth, users, configurator} = testEnv;
|
||||
|
||||
const caller = users[3];
|
||||
|
||||
const flashAmount = ethers.utils.parseEther('0.8');
|
||||
|
||||
await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
await expect(
|
||||
pool
|
||||
.connect(caller.signer)
|
||||
.flashLoan(_mockFlashLoanReceiver.address, weth.address, flashAmount, 1, '0x10', '0')
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -354,84 +354,4 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
|||
'Invalid collateral available liquidity'
|
||||
);
|
||||
});
|
||||
|
||||
it('User 4 borrows - drops HF, liquidates the borrower but reverts due paused pool', async () => {
|
||||
const {users, pool, usdc, oracle, weth, configurator} = testEnv;
|
||||
const depositor = users[3];
|
||||
const borrower = users[4];
|
||||
|
||||
//mints USDC to depositor
|
||||
await usdc
|
||||
.connect(depositor.signer)
|
||||
.mint(await convertToCurrencyDecimals(usdc.address, '1000'));
|
||||
|
||||
//approve protocol to access depositor wallet
|
||||
await usdc.connect(depositor.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
//user 3 deposits 1000 USDC
|
||||
const amountUSDCtoDeposit = await convertToCurrencyDecimals(usdc.address, '1000');
|
||||
|
||||
await pool
|
||||
.connect(depositor.signer)
|
||||
.deposit(usdc.address, amountUSDCtoDeposit, depositor.address, '0');
|
||||
|
||||
//user 4 deposits 1 ETH
|
||||
const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1');
|
||||
|
||||
//mints WETH to borrower
|
||||
await weth.connect(borrower.signer).mint(amountETHtoDeposit);
|
||||
|
||||
//approve protocol to access borrower wallet
|
||||
await weth.connect(borrower.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
await pool
|
||||
.connect(borrower.signer)
|
||||
.deposit(weth.address, amountETHtoDeposit, borrower.address, '0');
|
||||
|
||||
//user 4 borrows
|
||||
const userGlobalData = await pool.getUserAccountData(borrower.address);
|
||||
|
||||
const usdcPrice = await oracle.getAssetPrice(usdc.address);
|
||||
|
||||
const amountUSDCToBorrow = await convertToCurrencyDecimals(
|
||||
usdc.address,
|
||||
new BigNumber(userGlobalData.availableBorrowsETH.toString())
|
||||
.div(usdcPrice.toString())
|
||||
.multipliedBy(0.9502)
|
||||
.toFixed(0)
|
||||
);
|
||||
|
||||
await pool
|
||||
.connect(borrower.signer)
|
||||
.borrow(usdc.address, amountUSDCToBorrow, RateMode.Stable, '0');
|
||||
|
||||
//drops HF below 1
|
||||
|
||||
await oracle.setAssetPrice(
|
||||
usdc.address,
|
||||
new BigNumber(usdcPrice.toString()).multipliedBy(1.2).toFixed(0)
|
||||
);
|
||||
|
||||
//mints dai to the liquidator
|
||||
|
||||
await usdc.mint(await convertToCurrencyDecimals(usdc.address, '1000'));
|
||||
|
||||
//approve protocol to access depositor wallet
|
||||
await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address);
|
||||
|
||||
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString())
|
||||
.multipliedBy(0.5)
|
||||
.toFixed(0);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
expect(
|
||||
pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
||||
|
|
356
test/pausable-functions.spec.ts
Normal file
356
test/pausable-functions.spec.ts
Normal file
|
@ -0,0 +1,356 @@
|
|||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||
import {ProtocolErrors, RateMode} from '../helpers/types';
|
||||
import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants';
|
||||
import {convertToCurrencyDecimals, getMockFlashLoanReceiver} from '../helpers/contracts-helpers';
|
||||
import {parseEther, parseUnits} from 'ethers/lib/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
|
||||
|
||||
const {expect} = require('chai');
|
||||
|
||||
makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
||||
|
||||
const {
|
||||
IS_PAUSED,
|
||||
TRANSFER_NOT_ALLOWED,
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
||||
INVALID_HF,
|
||||
} = ProtocolErrors;
|
||||
|
||||
before(async () => {
|
||||
_mockFlashLoanReceiver = await getMockFlashLoanReceiver();
|
||||
});
|
||||
|
||||
it('User 0 deposits 1000 DAI. Configurator pauses pool. Transfers to user 1 reverts. Configurator unpauses the network and next transfer succees', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
|
||||
|
||||
const user0Balance = await aDai.balanceOf(users[0].address);
|
||||
const user1Balance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// User 0 tries the transfer to User 1
|
||||
await expect(
|
||||
aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit)
|
||||
).to.revertedWith(TRANSFER_NOT_ALLOWED);
|
||||
|
||||
const pausedFromBalance = await aDai.balanceOf(users[0].address);
|
||||
const pausedToBalance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(pausedFromBalance).to.be.equal(
|
||||
user0Balance.toString(),
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
expect(pausedToBalance.toString()).to.be.equal(
|
||||
user1Balance.toString(),
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
|
||||
// User 0 succeeds transfer to User 1
|
||||
await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit);
|
||||
|
||||
const fromBalance = await aDai.balanceOf(users[0].address);
|
||||
const toBalance = await aDai.balanceOf(users[1].address);
|
||||
|
||||
expect(fromBalance.toString()).to.be.equal(
|
||||
user0Balance.sub(amountDAItoDeposit),
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
expect(toBalance.toString()).to.be.equal(
|
||||
user1Balance.add(amountDAItoDeposit),
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER
|
||||
);
|
||||
});
|
||||
|
||||
it('User 0 deposits 1000 DAI but reverts due pool is paused', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
await expect(
|
||||
pool.connect(users[0].signer).deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
|
||||
).to.revertedWith(IS_PAUSED);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 0 burns 1000 aDAI but reverts due pool is paused', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
||||
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
|
||||
|
||||
// user 0 deposits 1000 DAI
|
||||
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool
|
||||
.connect(users[0].signer)
|
||||
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
|
||||
|
||||
// Configurator pauses the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// user tries to burn
|
||||
await expect(
|
||||
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit)
|
||||
).to.revertedWith(IS_PAUSED);
|
||||
|
||||
// Configurator unpauses the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('Repay with collateral', async () => {
|
||||
const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle, configurator} = testEnv;
|
||||
const user = users[6];
|
||||
const liquidator = users[5];
|
||||
|
||||
// Pause the pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(
|
||||
pool
|
||||
.connect(liquidator.signer)
|
||||
.repayWithCollateral(
|
||||
weth.address,
|
||||
usdc.address,
|
||||
user.address,
|
||||
'1',
|
||||
mockSwapAdapter.address,
|
||||
'0x'
|
||||
)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('Flash loan', async () => {
|
||||
const {dai, pool, weth, users, configurator} = testEnv;
|
||||
|
||||
const caller = users[3];
|
||||
|
||||
const flashAmount = parseEther('0.8');
|
||||
|
||||
await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
await expect(
|
||||
pool
|
||||
.connect(caller.signer)
|
||||
.flashLoan(_mockFlashLoanReceiver.address, weth.address, flashAmount, 1, '0x10', '0')
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('Liquidation call', async () => {
|
||||
const {users, pool, usdc, oracle, weth, configurator} = testEnv;
|
||||
const depositor = users[3];
|
||||
const borrower = users[4];
|
||||
|
||||
//mints USDC to depositor
|
||||
await usdc
|
||||
.connect(depositor.signer)
|
||||
.mint(await convertToCurrencyDecimals(usdc.address, '1000'));
|
||||
|
||||
//approve protocol to access depositor wallet
|
||||
await usdc.connect(depositor.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
//user 3 deposits 1000 USDC
|
||||
const amountUSDCtoDeposit = await convertToCurrencyDecimals(usdc.address, '1000');
|
||||
|
||||
await pool
|
||||
.connect(depositor.signer)
|
||||
.deposit(usdc.address, amountUSDCtoDeposit, depositor.address, '0');
|
||||
|
||||
//user 4 deposits 1 ETH
|
||||
const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1');
|
||||
|
||||
//mints WETH to borrower
|
||||
await weth.connect(borrower.signer).mint(amountETHtoDeposit);
|
||||
|
||||
//approve protocol to access borrower wallet
|
||||
await weth.connect(borrower.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
await pool
|
||||
.connect(borrower.signer)
|
||||
.deposit(weth.address, amountETHtoDeposit, borrower.address, '0');
|
||||
|
||||
//user 4 borrows
|
||||
const userGlobalData = await pool.getUserAccountData(borrower.address);
|
||||
|
||||
const usdcPrice = await oracle.getAssetPrice(usdc.address);
|
||||
|
||||
const amountUSDCToBorrow = await convertToCurrencyDecimals(
|
||||
usdc.address,
|
||||
new BigNumber(userGlobalData.availableBorrowsETH.toString())
|
||||
.div(usdcPrice.toString())
|
||||
.multipliedBy(0.9502)
|
||||
.toFixed(0)
|
||||
);
|
||||
|
||||
await pool
|
||||
.connect(borrower.signer)
|
||||
.borrow(usdc.address, amountUSDCToBorrow, RateMode.Stable, '0');
|
||||
|
||||
// Drops HF below 1
|
||||
await oracle.setAssetPrice(
|
||||
usdc.address,
|
||||
new BigNumber(usdcPrice.toString()).multipliedBy(1.2).toFixed(0)
|
||||
);
|
||||
|
||||
//mints dai to the liquidator
|
||||
await usdc.mint(await convertToCurrencyDecimals(usdc.address, '1000'));
|
||||
await usdc.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
|
||||
const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address);
|
||||
|
||||
const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString())
|
||||
.multipliedBy(0.5)
|
||||
.toFixed(0);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Do liquidation
|
||||
expect(
|
||||
pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 6 deposits WETH and DAI, then borrows USDC at Variable', async () => {
|
||||
const {pool, weth, dai, usdc, users, configurator, mockSwapAdapter} = testEnv;
|
||||
const user = users[5];
|
||||
const amountWETHToDeposit = parseEther('10');
|
||||
const amountDAIToDeposit = parseEther('120');
|
||||
const amountToBorrow = parseUnits('65', 6);
|
||||
|
||||
await weth.connect(user.signer).mint(amountWETHToDeposit);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(weth.address, amountWETHToDeposit, user.address, '0');
|
||||
|
||||
await dai.connect(user.signer).mint(amountDAIToDeposit);
|
||||
await dai.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(dai.address, amountDAIToDeposit, user.address, '0');
|
||||
|
||||
await pool.connect(user.signer).borrow(usdc.address, amountToBorrow, 2, 0);
|
||||
|
||||
const amountToRepay = parseUnits('65', 6);
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Try to repay
|
||||
await expect(
|
||||
pool
|
||||
.connect(user.signer)
|
||||
.repayWithCollateral(
|
||||
weth.address,
|
||||
usdc.address,
|
||||
user.address,
|
||||
amountToRepay,
|
||||
mockSwapAdapter.address,
|
||||
'0x'
|
||||
)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 2 deposits WETH and DAI, then borrows USDC at Variable, then tries to swap to stable but pool is paused', async () => {
|
||||
const {pool, weth, dai, usdc, users, configurator, mockSwapAdapter} = testEnv;
|
||||
const user = users[1];
|
||||
const amountWETHToDeposit = parseEther('10');
|
||||
const amountDAIToDeposit = parseEther('120');
|
||||
const amountToBorrow = parseUnits('65', 6);
|
||||
|
||||
await weth.connect(user.signer).mint(amountWETHToDeposit);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(weth.address, amountWETHToDeposit, user.address, '0');
|
||||
|
||||
await dai.connect(user.signer).mint(amountDAIToDeposit);
|
||||
await dai.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(dai.address, amountDAIToDeposit, user.address, '0');
|
||||
|
||||
await pool.connect(user.signer).borrow(usdc.address, amountToBorrow, 2, 0);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Try to repay
|
||||
await expect(
|
||||
pool.connect(user.signer).swapBorrowRateMode(usdc.address, RateMode.Stable)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 2 tries to rebalance stable borrow rate', async () => {
|
||||
const {pool, dai, users, configurator} = testEnv;
|
||||
const user = users[1];
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
await expect(
|
||||
pool.connect(user.signer).rebalanceStableBorrowRate(dai.address, user.address)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
|
||||
it('User 2 tries to rebalance stable borrow rate', async () => {
|
||||
const {pool, weth, users, configurator} = testEnv;
|
||||
const user = users[1];
|
||||
|
||||
const amountWETHToDeposit = parseEther('1');
|
||||
await weth.connect(user.signer).mint(amountWETHToDeposit);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(weth.address, amountWETHToDeposit, user.address, '0');
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
await expect(
|
||||
pool.connect(user.signer).setUserUseReserveAsCollateral(weth.address, false)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
|
@ -639,51 +639,4 @@ makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
|
|||
|
||||
expect(wethUserDataAfter.usageAsCollateralEnabled).to.be.false;
|
||||
});
|
||||
|
||||
it('User 6 deposits WETH and DAI, then borrows USDC at Variable', async () => {
|
||||
const {pool, weth, dai, usdc, users} = testEnv;
|
||||
const user = users[4];
|
||||
const amountWETHToDeposit = parseEther('10');
|
||||
const amountDAIToDeposit = parseEther('120');
|
||||
const amountToBorrow = parseUnits('65', 6);
|
||||
|
||||
await weth.connect(user.signer).mint(amountWETHToDeposit);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(weth.address, amountWETHToDeposit, user.address, '0');
|
||||
|
||||
await dai.connect(user.signer).mint(amountDAIToDeposit);
|
||||
await dai.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(dai.address, amountDAIToDeposit, user.address, '0');
|
||||
|
||||
await pool.connect(user.signer).borrow(usdc.address, amountToBorrow, 2, 0);
|
||||
});
|
||||
|
||||
it('User 6 tries to repay his USDC loan by swapping his WETH collateral, should not revert even with WETH collateral disabled', async () => {
|
||||
const {pool, weth, usdc, users, mockSwapAdapter, oracle, configurator} = testEnv;
|
||||
const user = users[5];
|
||||
|
||||
const amountToRepay = parseUnits('65', 6);
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
|
||||
// Pause pool
|
||||
await configurator.pausePool();
|
||||
|
||||
// Try to repay
|
||||
await expect(
|
||||
pool
|
||||
.connect(user.signer)
|
||||
.repayWithCollateral(
|
||||
weth.address,
|
||||
usdc.address,
|
||||
user.address,
|
||||
amountToRepay,
|
||||
mockSwapAdapter.address,
|
||||
'0x'
|
||||
)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.unpausePool();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user