fixed redeem tests, removed console.log

This commit is contained in:
The3D 2020-07-04 09:32:54 +02:00
parent 30ab5ddec2
commit 34efb0c917
4 changed files with 21 additions and 42 deletions

View File

@ -376,8 +376,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
if(CoreLibrary.InterestRateMode(_interestRateMode) == CoreLibrary.InterestRateMode.STABLE) { if(CoreLibrary.InterestRateMode(_interestRateMode) == CoreLibrary.InterestRateMode.STABLE) {
IStableDebtToken(reserve.stableDebtTokenAddress).mint(msg.sender, _amount, userStableRate); IStableDebtToken(reserve.stableDebtTokenAddress).mint(msg.sender, _amount, userStableRate);
uint40 stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated(msg.sender); uint40 stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated(msg.sender);
console.log("Stable rate last updated in borrow is %s", stableRateLastUpdated);
} }
else { else {
IVariableDebtToken(reserve.variableDebtTokenAddress).mint(msg.sender, _amount); IVariableDebtToken(reserve.variableDebtTokenAddress).mint(msg.sender, _amount);
@ -391,10 +389,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
(uint256 stableBalance, uint256 variableBalance) = UserLogic.getUserBorrowBalances(msg.sender, reserve); (uint256 stableBalance, uint256 variableBalance) = UserLogic.getUserBorrowBalances(msg.sender, reserve);
console.log("Debt balances: %s %s", stableBalance, variableBalance);
console.log("User variable borrow index %s reserve index %s", IVariableDebtToken(reserve.variableDebtTokenAddress).getUserIndex(msg.sender), reserve.lastVariableBorrowCumulativeIndex);
console.log("User stable rate %s", IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(msg.sender));
emit Borrow( emit Borrow(
_reserve, _reserve,
msg.sender, msg.sender,
@ -437,33 +431,21 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
CoreLibrary.ReserveData storage reserve = reserves[_reserve]; CoreLibrary.ReserveData storage reserve = reserves[_reserve];
CoreLibrary.UserReserveData storage user = usersReserveData[_onBehalfOf][_reserve]; CoreLibrary.UserReserveData storage user = usersReserveData[_onBehalfOf][_reserve];
console.log("Getting balances...");
( (
vars.stableBorrowBalance, vars.stableBorrowBalance,
vars.variableBorrowBalance vars.variableBorrowBalance
) = UserLogic.getUserBorrowBalances(_onBehalfOf, reserve); ) = UserLogic.getUserBorrowBalances(_onBehalfOf, reserve);
console.log("Balances calculated, %s %s", vars.stableBorrowBalance, vars.variableBorrowBalance);
console.log("Interest rate mode %s", _rateMode);
CoreLibrary.InterestRateMode rateMode = CoreLibrary.InterestRateMode(_rateMode); CoreLibrary.InterestRateMode rateMode = CoreLibrary.InterestRateMode(_rateMode);
console.log("Interest rate mode %s", _rateMode);
//default to max amount //default to max amount
vars.paybackAmount = rateMode == CoreLibrary.InterestRateMode.STABLE ? vars.stableBorrowBalance : vars.variableBorrowBalance; vars.paybackAmount = rateMode == CoreLibrary.InterestRateMode.STABLE ? vars.stableBorrowBalance : vars.variableBorrowBalance;
console.log("Payback amount %s stable rate %s", vars.paybackAmount, IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(_onBehalfOf));
if (_amount != UINT_MAX_VALUE && _amount < vars.paybackAmount) { if (_amount != UINT_MAX_VALUE && _amount < vars.paybackAmount) {
vars.paybackAmount = _amount; vars.paybackAmount = _amount;
} }
console.log("Validating repay...");
ValidationLogic.validateRepay( ValidationLogic.validateRepay(
reserve, reserve,
_reserve, _reserve,
@ -478,7 +460,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
reserve.updateCumulativeIndexesAndTimestamp(); reserve.updateCumulativeIndexesAndTimestamp();
console.log("Burning tokens...");
//burns an equivalent amount of debt tokens //burns an equivalent amount of debt tokens
if(rateMode == CoreLibrary.InterestRateMode.STABLE) { if(rateMode == CoreLibrary.InterestRateMode.STABLE) {
IStableDebtToken(reserve.stableDebtTokenAddress).burn(_onBehalfOf, vars.paybackAmount); IStableDebtToken(reserve.stableDebtTokenAddress).burn(_onBehalfOf, vars.paybackAmount);
@ -894,7 +875,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
liquidityRate = reserve.currentLiquidityRate; liquidityRate = reserve.currentLiquidityRate;
stableBorrowRate = IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(_user); stableBorrowRate = IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(_user);
stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated(_user); stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated(_user);
console.log("Stable rate last updated is %s", stableRateLastUpdated);
usageAsCollateralEnabled = usersReserveData[_user][_reserve].useAsCollateral; usageAsCollateralEnabled = usersReserveData[_user][_reserve].useAsCollateral;
variableBorrowIndex = IVariableDebtToken(reserve.variableDebtTokenAddress).getUserIndex(_user); variableBorrowIndex = IVariableDebtToken(reserve.variableDebtTokenAddress).getUserIndex(_user);
} }

View File

@ -123,7 +123,8 @@
"reserve": "DAI", "reserve": "DAI",
"amount": "-1", "amount": "-1",
"user": "1", "user": "1",
"onBehalfOf": "1" "onBehalfOf": "1",
"borrowRateMode": "stable"
}, },
"expected": "success" "expected": "success"
}, },

View File

@ -152,7 +152,7 @@ export const calcExpectedUserDataAfterRedeem = (
txTimestamp txTimestamp
); );
expectedUserData.principalATokenBalance = userDataBeforeAction.principalStableBorrowBalance; expectedUserData.principalStableBorrowBalance = userDataBeforeAction.principalStableBorrowBalance;
expectedUserData.principalVariableBorrowBalance = expectedUserData.principalVariableBorrowBalance =
userDataBeforeAction.principalVariableBorrowBalance; userDataBeforeAction.principalVariableBorrowBalance;
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex; expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;

View File

@ -1,33 +1,31 @@
import {configuration as actionsConfiguration} from "./helpers/actions"; import {configuration as actionsConfiguration} from './helpers/actions';
import {configuration as calculationsConfiguration} from "./helpers/utils/calculations"; import {configuration as calculationsConfiguration} from './helpers/utils/calculations';
import fs from "fs"; import fs from 'fs';
import BigNumber from "bignumber.js"; import BigNumber from 'bignumber.js';
import {makeSuite} from "./helpers/make-suite"; import {makeSuite} from './helpers/make-suite';
import {MOCK_ETH_ADDRESS, getReservesConfigByPool} from "../helpers/constants"; import {MOCK_ETH_ADDRESS, getReservesConfigByPool} from '../helpers/constants';
import {AavePools, iAavePoolAssets, IReserveParams} from "../helpers/types"; import {AavePools, iAavePoolAssets, IReserveParams} from '../helpers/types';
import {executeStory} from "./helpers/scenario-engine"; import {executeStory} from './helpers/scenario-engine';
BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN}); BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN});
const scenarioFolder = "./test/helpers/scenarios/"; const scenarioFolder = './test/helpers/scenarios/';
const selectedScenarios: string[] = [];
fs.readdirSync(scenarioFolder).forEach((file) => { fs.readdirSync(scenarioFolder).forEach((file) => {
if (![ if (selectedScenarios.length > 0 && !selectedScenarios.includes(file)) return;
"borrow-repay-variable.json",
].includes(file)
)
return;
const scenario = require(`./helpers/scenarios/${file}`); const scenario = require(`./helpers/scenarios/${file}`);
makeSuite(scenario.title, async (testEnv) => { makeSuite(scenario.title, async (testEnv) => {
before("Initializing configuration", async () => { before('Initializing configuration', async () => {
actionsConfiguration.skipIntegrityCheck = false; //set this to true to execute solidity-coverage actionsConfiguration.skipIntegrityCheck = false; //set this to true to execute solidity-coverage
calculationsConfiguration.reservesParams = < calculationsConfiguration.reservesParams = <iAavePoolAssets<IReserveParams>>(
iAavePoolAssets<IReserveParams> getReservesConfigByPool(AavePools.proto)
>getReservesConfigByPool(AavePools.proto); );
calculationsConfiguration.ethereumAddress = MOCK_ETH_ADDRESS; calculationsConfiguration.ethereumAddress = MOCK_ETH_ADDRESS;
}); });