Updating withdrawal tests

This commit is contained in:
The3D 2020-09-08 16:14:32 +02:00
parent e3c422468d
commit 2e8f6ee02c
2 changed files with 15 additions and 11 deletions

View File

@ -11,6 +11,8 @@ import {
import {IAToken} from './interfaces/IAToken.sol';
import {IERC20} from '../interfaces/IERC20.sol';
import {SafeERC20} from "../misc/SafeERC20.sol";
import "@nomiclabs/buidler/console.sol";
/**
* @title Aave ERC20 AToken
@ -118,7 +120,9 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
uint256 currentBalance = balanceOf(user);
require(currentBalance <= amount, Errors.INVALID_ATOKEN_BALANCE);
console.log("Amount is %s, balance is %s", amount, currentBalance);
require(amount <= currentBalance, Errors.INVALID_ATOKEN_BALANCE);
uint256 index = _pool.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS);
@ -240,6 +244,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
return _interestRedirectionIndexes[user];
}
/**
* @dev calculates the total supply of the specific aToken
* since the balance of every single user increases over time, the total supply

View File

@ -65,8 +65,6 @@ export const calcExpectedUserDataAfterDeposit = (
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.minus(amountDeposited);
expectedUserData.scaledATokenBalance = calcExpectedScaledATokenBalance(reserveDataAfterAction, userDataBeforeAction, new BigNumber(amountDeposited), new BigNumber(0));
expectedUserData.currentATokenBalance = calcExpectedATokenBalance(
reserveDataBeforeAction,
userDataBeforeAction,
@ -121,23 +119,26 @@ export const calcExpectedUserDataAfterWithdraw = (
amountWithdrawn = aTokenBalance.toFixed(0);
}
expectedUserData.principalATokenBalance = expectedUserData.currentATokenBalance = aTokenBalance.minus(
expectedUserData.scaledATokenBalance = calcExpectedScaledATokenBalance(reserveDataAfterAction, userDataBeforeAction, new BigNumber(0), new BigNumber(amountWithdrawn));
expectedUserData.currentATokenBalance = aTokenBalance.minus(
amountWithdrawn
);
expectedUserData.currentStableDebt = expectedUserData.principalStableDebt = calcExpectedStableDebtTokenBalance(
expectedUserData.principalStableDebt = userDataBeforeAction.principalStableDebt;
expectedUserData.principalVariableDebt = userDataBeforeAction.principalVariableDebt;
expectedUserData.currentStableDebt = calcExpectedStableDebtTokenBalance(
userDataBeforeAction,
txTimestamp
);
expectedUserData.currentVariableDebt = expectedUserData.principalStableDebt = calcExpectedVariableDebtTokenBalance(
expectedUserData.currentVariableDebt = calcExpectedVariableDebtTokenBalance(
reserveDataBeforeAction,
userDataBeforeAction,
txTimestamp
);
expectedUserData.principalStableDebt = userDataBeforeAction.principalStableDebt;
expectedUserData.principalVariableDebt = userDataBeforeAction.principalVariableDebt;
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
expectedUserData.stableBorrowRate = userDataBeforeAction.stableBorrowRate;
expectedUserData.stableRateLastUpdated = userDataBeforeAction.stableRateLastUpdated;
@ -155,9 +156,7 @@ export const calcExpectedUserDataAfterWithdraw = (
}
}
expectedUserData.variableBorrowIndex = userDataBeforeAction.variableBorrowIndex;
expectedUserData.walletBalance = userDataBeforeAction.walletBalance.plus(amountWithdrawn);
expectedUserData.redirectedBalance = userDataBeforeAction.redirectedBalance;
if (expectedUserData.currentATokenBalance.eq(0) && expectedUserData.redirectedBalance.eq(0)) {
@ -1038,7 +1037,7 @@ const calcExpectedScaledATokenBalance = (
amountTaken: BigNumber
) => {
return userDataBeforeAction.scaledATokenBalance.plus(amountAdded.rayDiv(reserveDataAfterAction.liquidityIndex));
return userDataBeforeAction.scaledATokenBalance.plus(amountAdded.rayDiv(reserveDataAfterAction.liquidityIndex)).minus(amountTaken.rayDiv(reserveDataAfterAction.liquidityIndex));
}
const calcExpectedATokenBalance = (