From 5fa09f5a7cced188fa6cbc459b6c6ec3ecb34af2 Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Fri, 20 Aug 2021 17:24:00 +0200 Subject: [PATCH] feat: Add missing cases for `LiqudationLogic` --- test-suites/liquidation-edge.spec.ts | 77 ++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test-suites/liquidation-edge.spec.ts diff --git a/test-suites/liquidation-edge.spec.ts b/test-suites/liquidation-edge.spec.ts new file mode 100644 index 000000000..5f34332ce --- /dev/null +++ b/test-suites/liquidation-edge.spec.ts @@ -0,0 +1,77 @@ +import { APPROVAL_AMOUNT_POOL, MAX_UINT_AMOUNT, RAY, ZERO_ADDRESS } from '../helpers/constants'; +import { convertToCurrencyDecimals } from '../helpers/contracts-helpers'; +import { expect } from 'chai'; +import { ethers } from 'ethers'; +import { RateMode, ProtocolErrors } from '../helpers/types'; +import { makeSuite, TestEnv } from './helpers/make-suite'; +import { DRE, evmRevert, evmSnapshot } from '../helpers/misc-utils'; +import { formatUnits, parseEther, parseUnits } from 'ethers/lib/utils'; +import { deposit } from './helpers/actions'; +import BigNumber from 'bignumber.js'; + +makeSuite('Validation-logic: reverting edge cases', (testEnv: TestEnv) => { + const { + VL_NO_ACTIVE_RESERVE, + VL_RESERVE_FROZEN, + VL_INVALID_AMOUNT, + VL_BORROWING_NOT_ENABLED, + VL_STABLE_BORROWING_NOT_ENABLED, + VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY, + VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE, + VL_NO_DEBT_OF_SELECTED_TYPE, + VL_SAME_BLOCK_BORROW_REPAY, + VL_HEALTH_FACTOR_NOT_BELOW_THRESHOLD, + VL_INVALID_INTEREST_RATE_MODE_SELECTED, + VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0, + VL_INCONSISTENT_FLASHLOAN_PARAMS, + VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, + } = ProtocolErrors; + + let snap: string; + + beforeEach(async () => { + snap = await evmSnapshot(); + }); + afterEach(async () => { + await evmRevert(snap); + }); + + it('executeLiquidationCall() 0 < vars.userVariableDebt < vars.actualDebtToLiquidate', async () => { + const { pool, users, dai, weth, oracle } = testEnv; + + const depositor = users[0]; + const borrower = users[1]; + + // Deposit 1000 dai + await dai.connect(depositor.signer).mint(parseUnits('1000000', 18)); + await dai.connect(depositor.signer).approve(pool.address, MAX_UINT_AMOUNT); + await pool + .connect(depositor.signer) + .deposit(dai.address, parseUnits('10000', 18), depositor.address, 0); + + // Deposit eth, borrow dai + await weth.connect(borrower.signer).mint(parseUnits('1', 18)); + await weth.connect(borrower.signer).approve(pool.address, MAX_UINT_AMOUNT); + await pool + .connect(borrower.signer) + .deposit(weth.address, parseUnits('1', 18), borrower.address, 0); + + await oracle.setAssetPrice(dai.address, parseUnits('0.001', 18)); + + // Borrow 500 dai stable + await pool + .connect(borrower.signer) + .borrow(dai.address, parseUnits('500', 18), RateMode.Stable, 0, borrower.address); + + // Borrow 200 dai variable + await pool + .connect(borrower.signer) + .borrow(dai.address, parseUnits('200', 18), RateMode.Variable, 0, borrower.address); + + await oracle.setAssetPrice(dai.address, parseUnits('0.002', 18)); + + await pool + .connect(depositor.signer) + .liquidationCall(weth.address, dai.address, borrower.address, MAX_UINT_AMOUNT, false); + }); +});