From d013c6e9cee48a0676d0dffb3d6fc584e40e6494 Mon Sep 17 00:00:00 2001 From: The3D Date: Thu, 3 Jun 2021 11:09:48 +0200 Subject: [PATCH] test: added mintToTreasury() test --- .../protocol/lendingpool/LendingPool.sol | 18 +++++++------ .../test-aave/mint-to-treasury.spec.ts | 25 +++++++++++++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index de5ea403..0ea6f302 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -539,17 +539,19 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage /** * @dev Mints the assets accrued through the reserve factor to the treasury in the form of aTokens + * @param reserves The list of reserves for which the minting needs to be executed **/ - function mintToTreasury() public { - for (uint256 i = 0; i < _reservesCount; i++) { - address reserveAddress = _reservesList[i]; - - // if a reserve has been dropped this might happen - if(reserveAddress == address(0)){ - continue; - } + function mintToTreasury(address[] calldata reserves) public { + for (uint256 i = 0; i < reserves.length; i++) { + address reserveAddress = reserves[i]; DataTypes.ReserveData storage reserve = _reserves[reserveAddress]; + + // this cover both inactive reserves and invalid reserves since the flag will be 0 for both + if(!reserve.configuration.getActive()){ + continue; + } + uint256 accruedToTreasury = reserve.accruedToTreasury; if (accruedToTreasury != 0) { diff --git a/test-suites/test-aave/mint-to-treasury.spec.ts b/test-suites/test-aave/mint-to-treasury.spec.ts index 00e24e83..1ed83274 100644 --- a/test-suites/test-aave/mint-to-treasury.spec.ts +++ b/test-suites/test-aave/mint-to-treasury.spec.ts @@ -9,7 +9,7 @@ import './helpers/utils/math'; const { expect } = require('chai'); makeSuite('Mint to treasury', (testEnv: TestEnv) => { - it('User 0 deposits 1000 DAI. Borrower borrows 100 DAI. Clock moved forward one year. Calculates and verifies the amount earned by the treasury', async () => { + it('User 0 deposits 1000 DAI. Borrower borrows 100 DAI. Clock moved forward one year. Calculates and verifies the amount accrued to the treasury', async () => { const { users, pool, dai, helpersContract } = testEnv; const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000'); @@ -61,9 +61,30 @@ makeSuite('Mint to treasury', (testEnv: TestEnv) => { const { accruedToTreasury } = await pool.getReserveData(dai.address); + console.log("Accrued to treasury ", accruedToTreasury.toString()); + expect(accruedToTreasury.toString()).to.be.bignumber.almostEqual( expectedAccruedToTreasury, - 'Invalid amount accrued to treasury' + 'Invalid amount accrued to the treasury' ); }); + + it('Mints the accrued to the treasury', async () => { + const { users, pool, dai, aDai, helpersContract } = testEnv; + + const treasuryAddress = await aDai.RESERVE_TREASURY_ADDRESS(); + const { accruedToTreasury } = await pool.getReserveData(dai.address); + + await waitForTx(await pool.connect(users[0].signer).mintToTreasury([dai.address])); + const normalizedIncome = await pool.getReserveNormalizedIncome(dai.address); + + const treasuryBalance = await aDai.balanceOf(treasuryAddress); + + const expectedTreasuryBalance = new BigNumber(accruedToTreasury.toString()).rayMul( + new BigNumber(normalizedIncome.toString()) + ); + + expect(treasuryBalance.toString()).to.be.bignumber.almostEqual(expectedTreasuryBalance, "Invalid treasury balance after minting"); + + }); });