From d0d1db5e4d7e686ad44993310526282a158bc239 Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 14 Sep 2020 20:04:49 +0200 Subject: [PATCH] Initial fix of the borrow tests --- test/helpers/utils/calculations.ts | 28 ++++++++++------------------ test/scenario.spec.ts | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/test/helpers/utils/calculations.ts b/test/helpers/utils/calculations.ts index 98d52cf2..4c6d951e 100644 --- a/test/helpers/utils/calculations.ts +++ b/test/helpers/utils/calculations.ts @@ -30,12 +30,12 @@ export const calcExpectedUserDataAfterDeposit = ( ): UserReserveData => { const expectedUserData = {}; - expectedUserData.currentStableDebt = expectedUserData.principalStableDebt = calcExpectedStableDebtTokenBalance( + expectedUserData.currentStableDebt = calcExpectedStableDebtTokenBalance( userDataBeforeAction, txTimestamp ); - expectedUserData.currentVariableDebt = expectedUserData.principalStableDebt = calcExpectedVariableDebtTokenBalance( + expectedUserData.currentVariableDebt = calcExpectedVariableDebtTokenBalance( reserveDataBeforeAction, userDataBeforeAction, txTimestamp @@ -285,22 +285,23 @@ export const calcExpectedReserveDataAfterBorrow = ( const amountBorrowedBN = new BigNumber(amountBorrowed); - const userStableDebt = calcExpectedStableDebtTokenBalance(userDataBeforeAction, txTimestamp); - - const userVariableDebt = calcExpectedVariableDebtTokenBalance( + expectedReserveData.liquidityIndex = calcExpectedLiquidityIndex( + reserveDataBeforeAction, + txTimestamp + ); + expectedReserveData.variableBorrowIndex = calcExpectedVariableBorrowIndex( reserveDataBeforeAction, - userDataBeforeAction, txTimestamp ); if (borrowRateMode == RateMode.Stable) { + + expectedReserveData. const debtAccrued = userStableDebt.minus(userDataBeforeAction.principalStableDebt); expectedReserveData.totalLiquidity = reserveDataBeforeAction.totalLiquidity.plus(debtAccrued); - expectedReserveData.totalStableDebt = reserveDataBeforeAction.totalStableDebt - .plus(amountBorrowedBN) - .plus(debtAccrued); + expectedReserveData.averageStableBorrowRate = calcExpectedAverageStableBorrowRate( reserveDataBeforeAction.averageStableBorrowRate, @@ -347,15 +348,6 @@ export const calcExpectedReserveDataAfterBorrow = ( expectedReserveData.variableBorrowRate = rates[2]; - expectedReserveData.liquidityIndex = calcExpectedLiquidityIndex( - reserveDataBeforeAction, - txTimestamp - ); - expectedReserveData.variableBorrowIndex = calcExpectedVariableBorrowIndex( - reserveDataBeforeAction, - txTimestamp - ); - expectedReserveData.lastUpdateTimestamp = txTimestamp; return expectedReserveData; diff --git a/test/scenario.spec.ts b/test/scenario.spec.ts index ee45a08f..98e0c164 100644 --- a/test/scenario.spec.ts +++ b/test/scenario.spec.ts @@ -10,7 +10,7 @@ import {executeStory} from './helpers/scenario-engine'; const scenarioFolder = './test/helpers/scenarios/'; -const selectedScenarios: string[] = ['withdraw.json']; +const selectedScenarios: string[] = ['borrow-repay-variable.json']; fs.readdirSync(scenarioFolder).forEach((file) => { if (selectedScenarios.length > 0 && !selectedScenarios.includes(file)) return;