test: tested drop reserve

This commit is contained in:
Hadrien Charlanes 2021-06-07 10:18:37 +02:00
parent 46d14e9124
commit 648604930e
2 changed files with 107 additions and 0 deletions

View File

@ -184,6 +184,9 @@ export enum ProtocolErrors {
LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85',
VL_RESERVE_PAUSED = '86',
LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87',
RL_ATOKEN_SUPPLY_NOT_ZERO = '88',
RL_STABLE_DEBT_NOT_ZERO = '89',
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90',
// old

View File

@ -0,0 +1,104 @@
import { makeSuite, TestEnv } from './helpers/make-suite';
import { ProtocolErrors, RateMode } from '../../helpers/types';
import { APPROVAL_AMOUNT_LENDING_POOL, MAX_UINT_AMOUNT, oneEther } from '../../helpers/constants';
import { convertToCurrencyDecimals } from '../../helpers/contracts-helpers';
import { parseEther, parseUnits } from 'ethers/lib/utils';
import { BigNumber } from 'bignumber.js';
import { MockFlashLoanReceiver } from '../../types/MockFlashLoanReceiver';
import { getMockFlashLoanReceiver } from '../../helpers/contracts-getters';
import { domainToUnicode } from 'url';
const { expect } = require('chai');
makeSuite('Pause Reserve', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const {
RL_ATOKEN_SUPPLY_NOT_ZERO,
RL_STABLE_DEBT_NOT_ZERO,
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO,
} = ProtocolErrors;
before(async () => {
_mockFlashLoanReceiver = await getMockFlashLoanReceiver();
});
it('User 1 deposits Dai, User 2 borrow Dai stable and variable, should fail to drop Dai reserve', async () => {
const {
deployer,
users: [user1],
pool,
dai,
aDai,
weth,
configurator,
} = testEnv;
const depositedAmount = parseEther('1000');
const borrowedAmount = parseEther('100');
console.log((await aDai.totalSupply()).toString());
// setting reserve factor to 0 to ease tests, no aToken accrued in reserve
await configurator.setReserveFactor(dai.address, 0);
await dai.mint(depositedAmount);
await dai.approve(pool.address, depositedAmount);
await dai.connect(user1.signer).mint(depositedAmount);
await dai.connect(user1.signer).approve(pool.address, depositedAmount);
await weth.connect(user1.signer).mint(depositedAmount);
await weth.connect(user1.signer).approve(pool.address, depositedAmount);
await pool.deposit(dai.address, depositedAmount, deployer.address, 0);
await expect(configurator.dropReserve(dai.address)).to.be.revertedWith(
RL_ATOKEN_SUPPLY_NOT_ZERO
);
await pool.connect(user1.signer).deposit(weth.address, depositedAmount, user1.address, 0);
await pool.connect(user1.signer).borrow(dai.address, borrowedAmount, 2, 0, user1.address);
await expect(configurator.dropReserve(dai.address)).to.be.revertedWith(
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO
);
await pool.connect(user1.signer).borrow(dai.address, borrowedAmount, 1, 0, user1.address);
await expect(configurator.dropReserve(dai.address)).to.be.revertedWith(RL_STABLE_DEBT_NOT_ZERO);
});
it('User 2 repays debts, drop Dai reserve should fail', async () => {
const {
deployer,
users: [user1],
pool,
dai,
weth,
configurator,
} = testEnv;
await pool.connect(user1.signer).repay(dai.address, MAX_UINT_AMOUNT, 1, user1.address);
await expect(configurator.dropReserve(dai.address)).to.be.revertedWith(
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO
);
await pool.connect(user1.signer).repay(dai.address, MAX_UINT_AMOUNT, 2, user1.address);
await expect(configurator.dropReserve(dai.address)).to.be.revertedWith(
RL_ATOKEN_SUPPLY_NOT_ZERO
);
});
it('User 1 withdraw Dai, drop Dai reserve should succeed', async () => {
const {
deployer,
users: [user1],
pool,
dai,
aDai,
weth,
configurator,
} = testEnv;
await pool.withdraw(dai.address, MAX_UINT_AMOUNT, deployer.address);
console.log((await aDai.totalSupply()).toString());
await configurator.dropReserve(dai.address);
const tokens = await pool.getReservesList();
expect(tokens.includes(dai.address)).to.be.false;
});
});