test: initial test for mintToTreasury()

This commit is contained in:
The3D 2021-05-06 16:21:55 +02:00
parent 5f0fb4bec9
commit c6dbc98926

View File

@ -0,0 +1,62 @@
import { makeSuite, TestEnv } from './helpers/make-suite';
import { ProtocolErrors, RateMode } from '../../helpers/types';
import { APPROVAL_AMOUNT_LENDING_POOL, oneEther, ONE_YEAR } 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 { advanceTimeAndBlock, waitForTx } from '../../helpers/misc-utils';
const { expect } = require('chai');
makeSuite('Mint to treasury', (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
const {
LP_IS_PAUSED,
INVALID_FROM_BALANCE_AFTER_TRANSFER,
INVALID_TO_BALANCE_AFTER_TRANSFER,
} = ProtocolErrors;
before(async () => {
_mockFlashLoanReceiver = await getMockFlashLoanReceiver();
});
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 () => {
const { users, pool, dai, aDai, configurator } = testEnv;
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
const amountDAItoBorrow = await convertToCurrencyDecimals(dai.address, '100');
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
// user 0 deposits 1000 DAI
await dai.connect(users[0].signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
await pool
.connect(users[0].signer)
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
await pool
.connect(users[0].signer)
.borrow(dai.address, amountDAItoBorrow, RateMode.Variable, '0', users[0].address);
await advanceTimeAndBlock(parseInt(ONE_YEAR));
await dai.connect(users[0].signer).mint(amountDAItoDeposit);
await pool
.connect(users[0].signer)
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0');
const reserveData = await pool.getReserveData(dai.address);
console.log(reserveData.accruedToTreasury.toString());
});
});