From 77ca4b47f820c531bafada7a5837e431cf7bc70d Mon Sep 17 00:00:00 2001 From: andyk Date: Wed, 9 Sep 2020 12:36:13 +0300 Subject: [PATCH] add failing test for setUsingAsCollateral --- test/collateral-swap.spec.ts | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/collateral-swap.spec.ts b/test/collateral-swap.spec.ts index 867875a0..a67cd55e 100644 --- a/test/collateral-swap.spec.ts +++ b/test/collateral-swap.spec.ts @@ -7,6 +7,7 @@ import {APPROVAL_AMOUNT_LENDING_POOL} from '../helpers/constants'; import {getContractsData, getTxCostAndTimestamp} from './helpers/actions'; import {calcExpectedATokenBalance} from './helpers/utils/calculations'; import {waitForTx} from './__setup.spec'; +import {advanceBlock, timeLatest} from '../helpers/misc-utils'; const {expect} = require('chai'); @@ -133,4 +134,46 @@ makeSuite('LendingPool CollateralSwap function', (testEnv: TestEnv) => { pool.collateralSwap(_mockSwapAdapter.address, weth.address, dai.address, amountToSwap, '0x10') ).to.be.revertedWith(HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD); }); + + it('Should set usage as collateral to false if no leftovers after swap', async () => { + const {pool, weth, dai, aEth} = testEnv; + const userAddress = await pool.signer.getAddress(); + + // cleanup borrowings, to be abe to swap whole weth + const amountToRepay = ethers.utils.parseEther('0.2'); + await weth.mint(amountToRepay); + await pool.repay(weth.address, amountToRepay, '1', userAddress); + const txTimestamp = (await timeLatest()).plus(100); + + const { + reserveData: wethReserveDataBefore, + userData: wethUserDataBefore, + } = await getContractsData(weth.address, userAddress, testEnv); + const amountToSwap = calcExpectedATokenBalance( + wethReserveDataBefore, + wethUserDataBefore, + txTimestamp + ); + + await advanceBlock(txTimestamp.toNumber()); + + console.log('before', amountToSwap.toString()); + await pool.collateralSwap( + _mockSwapAdapter.address, + weth.address, + dai.address, + '1'.toString(), + '0x10' + ); + console.log('after', (await aEth.balanceOf(userAddress)).toString()); + const {userData: wethUserDataAfter} = await getContractsData( + weth.address, + userAddress, + testEnv + ); + expect(wethUserDataAfter.usageAsCollateralEnabled).to.be.equal( + false, + 'usageAsCollateralEnabled are not set to false' + ); + }); });