mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
test: added mintToTreasury() test
This commit is contained in:
parent
0326259c03
commit
d013c6e9ce
|
@ -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
|
* @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 {
|
function mintToTreasury(address[] calldata reserves) public {
|
||||||
for (uint256 i = 0; i < _reservesCount; i++) {
|
for (uint256 i = 0; i < reserves.length; i++) {
|
||||||
address reserveAddress = _reservesList[i];
|
address reserveAddress = reserves[i];
|
||||||
|
|
||||||
// if a reserve has been dropped this might happen
|
|
||||||
if(reserveAddress == address(0)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTypes.ReserveData storage reserve = _reserves[reserveAddress];
|
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;
|
uint256 accruedToTreasury = reserve.accruedToTreasury;
|
||||||
|
|
||||||
if (accruedToTreasury != 0) {
|
if (accruedToTreasury != 0) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import './helpers/utils/math';
|
||||||
const { expect } = require('chai');
|
const { expect } = require('chai');
|
||||||
|
|
||||||
makeSuite('Mint to treasury', (testEnv: TestEnv) => {
|
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 { users, pool, dai, helpersContract } = testEnv;
|
||||||
|
|
||||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||||
|
@ -61,9 +61,30 @@ makeSuite('Mint to treasury', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const { accruedToTreasury } = await pool.getReserveData(dai.address);
|
const { accruedToTreasury } = await pool.getReserveData(dai.address);
|
||||||
|
|
||||||
|
console.log("Accrued to treasury ", accruedToTreasury.toString());
|
||||||
|
|
||||||
expect(accruedToTreasury.toString()).to.be.bignumber.almostEqual(
|
expect(accruedToTreasury.toString()).to.be.bignumber.almostEqual(
|
||||||
expectedAccruedToTreasury,
|
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");
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user