From de8e0b417c6e2c32927cd89cd8513b4d6f33eb83 Mon Sep 17 00:00:00 2001 From: Valia Fetisov Date: Fri, 21 Oct 2022 14:25:37 +0200 Subject: [PATCH] fix tests --- core/simulations/configs/vaultLiquidation.ts | 56 ++++--------------- .../helpers/createVaultWithCollateral.ts | 18 +++++- core/test/vault-test.ts | 2 +- 3 files changed, 29 insertions(+), 47 deletions(-) diff --git a/core/simulations/configs/vaultLiquidation.ts b/core/simulations/configs/vaultLiquidation.ts index 95ccd4165..797d59012 100644 --- a/core/simulations/configs/vaultLiquidation.ts +++ b/core/simulations/configs/vaultLiquidation.ts @@ -1,53 +1,13 @@ import { warpTime, resetNetworkAndSetupWallet } from '../../helpers/hardhat/network'; import { addDaiToBalance, addMkrToBalance } from '../../helpers/hardhat/balance'; import { Simulation } from '../types'; -import prompts from 'prompts'; -import COLLATERALS from '../../src/constants/COLLATERALS'; import { collectStabilityFees, fetchVault, liquidateVault } from '../../src/vaults'; import { TEST_NETWORK } from '../../helpers/constants'; import createVaultWithCollateral, { calculateMinCollateralAmountToOpenVault, + getLiquidatableCollateralTypes, } from '../helpers/createVaultWithCollateral'; - -const UNSUPPORTED_COLLATERAL_TYPES = [ - 'CRVV1ETHSTETH-A', // collateral handled differently - 'UNIV2DAIUSDC-A', // Liquidation limit too high (fails with "Dog/liquidation-limit-hit") - 'WSTETH-B', // does not accumulate stability fee rate at all. -]; - -export const getLiquidatableCollateralTypes = () => { - return Object.keys(COLLATERALS).filter(collateralType => !UNSUPPORTED_COLLATERAL_TYPES.includes(collateralType)); -}; - -const getCollateralType = async () => { - const { collateralType } = await prompts([ - { - type: 'select', - name: 'collateralType', - message: 'Select the collateral symbol to add to the VAT.', - choices: getLiquidatableCollateralTypes() - .sort() - .map(collateral => ({ - title: collateral, - value: collateral, - })), - }, - ]); - return collateralType; -}; - -const getBaseContext = async () => { - const collateralType = await getCollateralType(); - const decimals = COLLATERALS[collateralType].decimals; - const collateralOwned = await calculateMinCollateralAmountToOpenVault(collateralType); - - console.info(`Collateral in the VAT initially: ${collateralOwned.toFixed()}`); - return { - collateralType, - decimals, - collateralOwned, - }; -}; +import promptToSelectOneOption from '../helpers/promptToSelectOneOption'; const simulation: Simulation = { title: 'Simulate liquidation Auctions', @@ -56,13 +16,21 @@ const simulation: Simulation = { title: 'Reset blockchain fork', entry: async () => { await resetNetworkAndSetupWallet(); - return getBaseContext(); + const collateralType = await promptToSelectOneOption( + 'Select the collateral symbol to add to the VAT.', + getLiquidatableCollateralTypes() + ); + return { + collateralType, + }; }, }, { title: 'Create the vault', entry: async context => { - const latestVaultId = await createVaultWithCollateral(context.collateralType, context.collateralOwned); + const collateralOwned = await calculateMinCollateralAmountToOpenVault(context.collateralType); + console.info(`Minimum collateral amount to open vault: ${collateralOwned.toFixed()}`); + const latestVaultId = await createVaultWithCollateral(context.collateralType, collateralOwned); return { ...context, latestVaultId }; }, }, diff --git a/core/simulations/helpers/createVaultWithCollateral.ts b/core/simulations/helpers/createVaultWithCollateral.ts index 009fef2e9..e9d70b08a 100644 --- a/core/simulations/helpers/createVaultWithCollateral.ts +++ b/core/simulations/helpers/createVaultWithCollateral.ts @@ -1,6 +1,7 @@ +import { ethers } from 'ethers'; +import BigNumber from '../../src/bignumber'; import { setCollateralInVat } from '../../helpers/hardhat/balance'; import { getCollateralConfigByType } from '../../src/constants/COLLATERALS'; -import BigNumber from '../../src/bignumber'; import { changeVaultContents, fetchVault, openVault, fetchVaultCollateralParameters } from '../../src/vaults'; import { HARDHAT_PUBLIC_KEY, TEST_NETWORK } from '../../helpers/constants'; import { @@ -17,9 +18,22 @@ import { } from '../../src/wallet'; import { MAX } from '../../src/constants/UNITS'; import { CollateralConfig, CollateralType } from '../../src/types'; -import { ethers } from 'ethers'; import { roundDownToFirstSignificantDecimal, roundUpToFirstSignificantDecimal } from '../../helpers/hex'; import { determineBalanceSlot, setCollateralInWallet } from '../../helpers/hardhat/erc20'; +import { getAllCollateralTypes } from '../../src/constants/COLLATERALS'; + +const UNSUPPORTED_COLLATERAL_TYPES = [ + 'CRVV1ETHSTETH-A', // Collateral handled differently + 'UNIV2DAIUSDC-A', // Liquidation limit too high (fails with "Dog/liquidation-limit-hit") + 'WSTETH-B', // Does not accumulate stability fee rate at all + 'RETH-A', // [temporary] this collateral is not yet deployed, tested via different flow +]; + +export const getLiquidatableCollateralTypes = () => { + return Object.keys(getAllCollateralTypes()).filter( + collateralType => !UNSUPPORTED_COLLATERAL_TYPES.includes(collateralType) + ); +}; const setAndCheckCollateralInVat = async (collateralType: CollateralType, collateralOwned: BigNumber) => { console.info(`Setting ${collateralType} balance in VAT...`); diff --git a/core/test/vault-test.ts b/core/test/vault-test.ts index 9a8c6cb11..b0dc05d41 100644 --- a/core/test/vault-test.ts +++ b/core/test/vault-test.ts @@ -21,8 +21,8 @@ import { fetchAuctionByCollateralTypeAndAuctionIndex } from '../src/fetch'; import { fetchVATbalanceDAI } from '../src/wallet'; import createVaultWithCollateral, { calculateMinCollateralAmountToOpenVault, + getLiquidatableCollateralTypes, } from '../simulations/helpers/createVaultWithCollateral'; -import { getLiquidatableCollateralTypes } from '../simulations/configs/vaultLiquidation'; import { MAX } from '../src/constants/UNITS'; chai.use(deepEqualInAnyOrder);