From c6dbc98926ea94230b84419df04b4c950586c9b2 Mon Sep 17 00:00:00 2001 From: The3D Date: Thu, 6 May 2021 16:21:55 +0200 Subject: [PATCH] test: initial test for mintToTreasury() --- .../test-aave/mint-to-treasury.spec.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test-suites/test-aave/mint-to-treasury.spec.ts diff --git a/test-suites/test-aave/mint-to-treasury.spec.ts b/test-suites/test-aave/mint-to-treasury.spec.ts new file mode 100644 index 00000000..29813520 --- /dev/null +++ b/test-suites/test-aave/mint-to-treasury.spec.ts @@ -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()); + + }); + + +});