From d056de8c0664415b91a826c44479c01410215ce3 Mon Sep 17 00:00:00 2001 From: miguelmtzinf Date: Tue, 7 Sep 2021 13:12:42 +0200 Subject: [PATCH] fix: Fix errors in atoken repay tests --- ...ay-atoken.spec.ts => atoken-repay.spec.ts} | 56 ++++++++----------- 1 file changed, 22 insertions(+), 34 deletions(-) rename test-suites/{repay-atoken.spec.ts => atoken-repay.spec.ts} (60%) diff --git a/test-suites/repay-atoken.spec.ts b/test-suites/atoken-repay.spec.ts similarity index 60% rename from test-suites/repay-atoken.spec.ts rename to test-suites/atoken-repay.spec.ts index 4d5c4144f..ff4213921 100644 --- a/test-suites/repay-atoken.spec.ts +++ b/test-suites/atoken-repay.spec.ts @@ -1,15 +1,10 @@ +import { expect } from 'chai'; +import { utils } from 'ethers'; +import { MAX_UINT_AMOUNT } from '../helpers/constants'; +import { setBlocktime, timeLatest } from '../helpers/misc-utils'; import { TestEnv, makeSuite } from './helpers/make-suite'; -import { MAX_UINT_AMOUNT, MAX_SUPPLY_CAP } from '../helpers/constants'; -import { ProtocolErrors } from '../helpers/types'; -import { MintableERC20, WETH9Mocked } from '../types'; -import { parseEther } from '@ethersproject/units'; -import { BigNumber } from '@ethersproject/bignumber'; -import { setBlocktime, timeLatest, waitForTx } from '../helpers/misc-utils'; -import { zeroPad } from '@ethersproject/bytes'; -const { expect } = require('chai'); - -makeSuite('Repay with aTokens', (testEnv: TestEnv) => { +makeSuite('AToken: Repay', (testEnv: TestEnv) => { before('User 0 deposits 100 DAI, user 1 deposits 1 WETH, borrows 50 DAI', async () => { const { weth, @@ -18,22 +13,22 @@ makeSuite('Repay with aTokens', (testEnv: TestEnv) => { users: [user0, user1], } = testEnv; - const daiAmount = parseEther('100'); - const wethAmount = parseEther('1'); + const daiAmount = utils.parseEther('100'); + const wethAmount = utils.parseEther('1'); await dai.connect(user0.signer).mint(daiAmount); await weth.connect(user1.signer).mint(wethAmount); await dai.connect(user0.signer).approve(pool.address, MAX_UINT_AMOUNT); await weth.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT); - await waitForTx( + await expect( await pool.connect(user0.signer).deposit(dai.address, daiAmount, user0.address, 0) ); - await waitForTx( + await expect( await pool.connect(user1.signer).deposit(weth.address, wethAmount, user1.address, 0) ); - await waitForTx( + await expect( await pool.connect(user1.signer).borrow(dai.address, daiAmount.div(2), 2, 0, user1.address) ); }); @@ -44,7 +39,7 @@ makeSuite('Repay with aTokens', (testEnv: TestEnv) => { dai, users: [, user1], } = testEnv; - const repayAmount = parseEther('25'); + const repayAmount = utils.parseEther('25'); await expect( pool.connect(user1.address).repayWithATokens(dai.address, repayAmount, 2, user1.address) @@ -60,30 +55,25 @@ makeSuite('Repay with aTokens', (testEnv: TestEnv) => { users: [user0, user1], } = testEnv; - const repayAmount = parseEther('25'); + const repayAmount = utils.parseEther('25'); - await waitForTx(await aDai.connect(user0.signer).transfer(user1.address, repayAmount)); + await expect(await aDai.connect(user0.signer).transfer(user1.address, repayAmount)); const time = await timeLatest(); - await setBlocktime(time.plus(1).toNumber()); + await setBlocktime(time.add(1).toNumber()); - const balanceBefore: BigNumber = await aDai.balanceOf(user1.address, { blockTag: 'pending' }); + const balanceBefore = await aDai.balanceOf(user1.address, { blockTag: 'pending' }); const debtBefore = await variableDebtDai.balanceOf(user1.address, { blockTag: 'pending' }); - await waitForTx( + await expect( await pool.connect(user1.signer).repayWithATokens(dai.address, repayAmount, 2, user1.address) ); - const balanceAfter = await aDai.balanceOf(user1.address); const debtAfter = await variableDebtDai.balanceOf(user1.address); - expect(balanceAfter.toString()).to.be.bignumber.almostEqual( - balanceBefore.sub(repayAmount).toString() - ); - expect(debtAfter.toString()).to.be.bignumber.almostEqual( - debtBefore.sub(repayAmount).toString() - ); + expect(balanceAfter).to.be.closeTo(balanceBefore.sub(repayAmount), 2); + expect(debtAfter).to.be.closeTo(debtBefore.sub(repayAmount), 2); }); it('User 0 repays the rest of the debt on behalf of user 1 using aTokens', async () => { @@ -97,21 +87,19 @@ makeSuite('Repay with aTokens', (testEnv: TestEnv) => { const time = await timeLatest(); - await setBlocktime(time.plus(1).toNumber()); + await setBlocktime(time.add(1).toNumber()); - const balanceBefore: BigNumber = await aDai.balanceOf(user0.address, { blockTag: 'pending' }); + const balanceBefore = await aDai.balanceOf(user0.address, { blockTag: 'pending' }); const debtBefore = await variableDebtDai.balanceOf(user1.address, { blockTag: 'pending' }); - await waitForTx( + await expect( await pool.connect(user0.signer).repayWithATokens(dai.address, debtBefore, 2, user1.address) ); const balanceAfter = await aDai.balanceOf(user0.address); const debtAfter = await variableDebtDai.balanceOf(user1.address); - expect(balanceAfter.toString()).to.be.bignumber.almostEqual( - balanceBefore.sub(debtBefore).toString() - ); + expect(balanceAfter).to.be.closeTo(balanceBefore.sub(debtBefore), 2); expect(debtAfter).to.be.equal(0); }); });