From 7da7c1a9ce5af20527b777633b9d460376b58fe2 Mon Sep 17 00:00:00 2001 From: Hadrien Charlanes Date: Fri, 14 May 2021 17:46:51 +0200 Subject: [PATCH] test: added test for main market with floashloan debts mode 2 --- .../test-aave/authorized-flashloan.spec.ts | 26 ++++++++++++++++--- test-suites/test-aave/flashloan.spec.ts | 26 +++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/test-suites/test-aave/authorized-flashloan.spec.ts b/test-suites/test-aave/authorized-flashloan.spec.ts index a66c6276..5aaa2bc1 100644 --- a/test-suites/test-aave/authorized-flashloan.spec.ts +++ b/test-suites/test-aave/authorized-flashloan.spec.ts @@ -30,9 +30,14 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { before(async () => { _mockFlashLoanReceiver = await getMockFlashLoanReceiver(); }); - it('Authorize a flash bororwer', async () => { - const { deployer, pool, weth, configurator } = testEnv; + it('Authorize flash borowers', async () => { + const { deployer, pool, weth, configurator, users } = testEnv; 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 () => { @@ -179,6 +184,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { 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 pool @@ -186,7 +193,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { .flashLoan( _mockFlashLoanReceiver.address, [weth.address], - [ethers.utils.parseEther('0.8')], + [borrowedAmount], [2], caller.address, '0x10', @@ -195,6 +202,19 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( 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); diff --git a/test-suites/test-aave/flashloan.spec.ts b/test-suites/test-aave/flashloan.spec.ts index 911c4adc..57c74a49 100644 --- a/test-suites/test-aave/flashloan.spec.ts +++ b/test-suites/test-aave/flashloan.spec.ts @@ -175,14 +175,16 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { 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 .connect(caller.signer) .flashLoan( _mockFlashLoanReceiver.address, [weth.address], - [ethers.utils.parseEther('0.8')], + [borrowedAmount], [2], caller.address, '0x10', @@ -191,6 +193,19 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( 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); @@ -290,13 +305,13 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { 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 caller = users[2]; const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500'); - await _mockFlashLoanReceiver.setFailExecutionTransfer(true); + await _mockFlashLoanReceiver.setFailExecutionTransfer(false); await expect( pool @@ -326,7 +341,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { 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'); @@ -341,6 +356,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { '0x10', '0' ); + const { variableDebtTokenAddress } = await helpersContract.getReserveTokensAddresses( usdc.address );