test: added test for main market with floashloan debts mode 2

This commit is contained in:
Hadrien Charlanes 2021-05-14 17:46:51 +02:00
parent 2168a627eb
commit 7da7c1a9ce
2 changed files with 44 additions and 8 deletions

View File

@ -30,9 +30,14 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
before(async () => { before(async () => {
_mockFlashLoanReceiver = await getMockFlashLoanReceiver(); _mockFlashLoanReceiver = await getMockFlashLoanReceiver();
}); });
it('Authorize a flash bororwer', async () => { it('Authorize flash borowers', async () => {
const { deployer, pool, weth, configurator } = testEnv; const { deployer, pool, weth, configurator, users } = testEnv;
await configurator.authorizeFlashBorrower(deployer.address); await configurator.authorizeFlashBorrower(deployer.address);
await configurator.authorizeFlashBorrower(users[1].address);
await configurator.authorizeFlashBorrower(users[2].address);
await configurator.authorizeFlashBorrower(users[3].address);
await configurator.authorizeFlashBorrower(users[4].address);
await configurator.authorizeFlashBorrower(users[5].address);
}); });
it('Deposits WETH into the reserve', async () => { it('Deposits WETH into the reserve', async () => {
@ -179,6 +184,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
await pool.connect(caller.signer).deposit(dai.address, amountToDeposit, caller.address, '0'); await pool.connect(caller.signer).deposit(dai.address, amountToDeposit, caller.address, '0');
const borrowedAmount = await convertToCurrencyDecimals(weth.address, '0.8');
await _mockFlashLoanReceiver.setFailExecutionTransfer(true); await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
await pool await pool
@ -186,7 +193,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
.flashLoan( .flashLoan(
_mockFlashLoanReceiver.address, _mockFlashLoanReceiver.address,
[weth.address], [weth.address],
[ethers.utils.parseEther('0.8')], [borrowedAmount],
[2], [2],
caller.address, caller.address,
'0x10', '0x10',
@ -195,6 +202,19 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address weth.address
); );
ethers.utils.parseUnits('10000');
const fees = 0;
const reserveData = await helpersContract.getReserveData(weth.address);
let totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
.plus(reserveData.totalStableDebt.toString())
.plus(reserveData.totalVariableDebt.toString());
expect(totalLiquidity.toString()).to.be.equal(
ethers.BigNumber.from('1000000000000000000').add(fees)
);
const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress); const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress);

View File

@ -175,14 +175,16 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
await pool.connect(caller.signer).deposit(dai.address, amountToDeposit, caller.address, '0'); await pool.connect(caller.signer).deposit(dai.address, amountToDeposit, caller.address, '0');
await _mockFlashLoanReceiver.setFailExecutionTransfer(true); const borrowedAmount = await convertToCurrencyDecimals(weth.address, '0.8');
await _mockFlashLoanReceiver.setFailExecutionTransfer(false);
await pool await pool
.connect(caller.signer) .connect(caller.signer)
.flashLoan( .flashLoan(
_mockFlashLoanReceiver.address, _mockFlashLoanReceiver.address,
[weth.address], [weth.address],
[ethers.utils.parseEther('0.8')], [borrowedAmount],
[2], [2],
caller.address, caller.address,
'0x10', '0x10',
@ -191,6 +193,19 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
weth.address weth.address
); );
ethers.utils.parseUnits('10000');
const fees = borrowedAmount.mul(9).div(10000);
const reserveData = await helpersContract.getReserveData(weth.address);
const totalLiquidity = new BigNumber(reserveData.availableLiquidity.toString())
.plus(reserveData.totalStableDebt.toString())
.plus(reserveData.totalVariableDebt.toString());
expect(totalLiquidity.toString()).to.be.equal(
ethers.BigNumber.from('1001620648000000000').add(fees)
);
const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress); const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
@ -290,13 +305,13 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
expect(currentUserBalance.toString()).to.be.equal(expectedLiquidity, 'Invalid user balance'); expect(currentUserBalance.toString()).to.be.equal(expectedLiquidity, 'Invalid user balance');
}); });
it('Takes out a 500 USDC flashloan with mode = 0, does not return the funds. (revert expected)', async () => { it('Takes out a 500 USDC flashloan with mode = 2, does not return the funds. (revert expected)', async () => {
const { usdc, pool, users } = testEnv; const { usdc, pool, users } = testEnv;
const caller = users[2]; const caller = users[2];
const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500'); const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500');
await _mockFlashLoanReceiver.setFailExecutionTransfer(true); await _mockFlashLoanReceiver.setFailExecutionTransfer(false);
await expect( await expect(
pool pool
@ -326,7 +341,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
await pool.connect(caller.signer).deposit(weth.address, amountToDeposit, caller.address, '0'); await pool.connect(caller.signer).deposit(weth.address, amountToDeposit, caller.address, '0');
await _mockFlashLoanReceiver.setFailExecutionTransfer(true); await _mockFlashLoanReceiver.setFailExecutionTransfer(false);
const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500'); const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500');
@ -341,6 +356,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10', '0x10',
'0' '0'
); );
const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses(
usdc.address usdc.address
); );