mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Migrated all the scenarios tests, except for borrow-repay-variable
This commit is contained in:
parent
ef3e5b2cbb
commit
595d169f5d
|
@ -32,3 +32,16 @@ export const evmSnapshot = async () =>
|
||||||
|
|
||||||
export const evmRevert = async (id: string) =>
|
export const evmRevert = async (id: string) =>
|
||||||
BRE.ethereum.send("evm_revert", [id]);
|
BRE.ethereum.send("evm_revert", [id]);
|
||||||
|
|
||||||
|
export const timeLatest = async () => {
|
||||||
|
const block = await BRE.ethers.provider.getBlock("latest");
|
||||||
|
return new BigNumber(block.timestamp);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const advanceBlock = async (timestamp: number) =>
|
||||||
|
await BRE.ethers.provider.send("evm_mine", [timestamp]);
|
||||||
|
|
||||||
|
export const increaseTime = async (secondsToIncrease: number) =>
|
||||||
|
await BRE.ethers.provider.send("evm_increaseTime", [secondsToIncrease]);
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,19 @@
|
||||||
import {TestEnv, SignerWithAddress} from "./make-suite";
|
import {TestEnv, SignerWithAddress} from "./make-suite";
|
||||||
import {mint, approve, deposit} from "./actions";
|
import {
|
||||||
|
mint,
|
||||||
|
approve,
|
||||||
|
deposit,
|
||||||
|
borrow,
|
||||||
|
redeem,
|
||||||
|
repay,
|
||||||
|
setUseAsCollateral,
|
||||||
|
swapBorrowRateMode,
|
||||||
|
rebalanceStableBorrowRate,
|
||||||
|
redirectInterestStream,
|
||||||
|
redirectInterestStreamOf,
|
||||||
|
allowInterestRedirectionTo,
|
||||||
|
} from "./actions";
|
||||||
|
import {RateMode} from "../../helpers/types";
|
||||||
|
|
||||||
export interface Action {
|
export interface Action {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -31,7 +45,7 @@ const executeAction = async (
|
||||||
users: SignerWithAddress[],
|
users: SignerWithAddress[],
|
||||||
testEnv: TestEnv
|
testEnv: TestEnv
|
||||||
) => {
|
) => {
|
||||||
const {reserve, user} = action.args;
|
const {reserve, user: userIndex} = action.args;
|
||||||
const {name, expected, revertMessage} = action;
|
const {name, expected, revertMessage} = action;
|
||||||
|
|
||||||
if (!name || name === "") {
|
if (!name || name === "") {
|
||||||
|
@ -40,7 +54,7 @@ const executeAction = async (
|
||||||
if (!reserve || reserve === "") {
|
if (!reserve || reserve === "") {
|
||||||
throw "Invalid reserve selected for deposit";
|
throw "Invalid reserve selected for deposit";
|
||||||
}
|
}
|
||||||
if (!user || user === "") {
|
if (!userIndex || userIndex === "") {
|
||||||
throw `Invalid user selected to deposit into the ${reserve} reserve`;
|
throw `Invalid user selected to deposit into the ${reserve} reserve`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +62,7 @@ const executeAction = async (
|
||||||
throw `An expected resut for action ${name} is required`;
|
throw `An expected resut for action ${name} is required`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userAddress = users[parseInt(user)];
|
const user = users[parseInt(userIndex)];
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "mint":
|
case "mint":
|
||||||
|
@ -58,11 +72,11 @@ const executeAction = async (
|
||||||
throw `Invalid amount of ${reserve} to mint`;
|
throw `Invalid amount of ${reserve} to mint`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await mint(reserve, amount, userAddress);
|
await mint(reserve, amount, user);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "approve":
|
case "approve":
|
||||||
await approve(reserve, userAddress, testEnv);
|
await approve(reserve, user, testEnv);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "deposit":
|
case "deposit":
|
||||||
|
@ -76,7 +90,7 @@ const executeAction = async (
|
||||||
await deposit(
|
await deposit(
|
||||||
reserve,
|
reserve,
|
||||||
amount,
|
amount,
|
||||||
userAddress,
|
user,
|
||||||
sendValue,
|
sendValue,
|
||||||
expected,
|
expected,
|
||||||
testEnv,
|
testEnv,
|
||||||
|
@ -85,181 +99,189 @@ const executeAction = async (
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case "redeem":
|
case "redeem":
|
||||||
// {
|
{
|
||||||
// const {amount} = action.args;
|
const {amount} = action.args;
|
||||||
|
|
||||||
// if (!amount || amount === "") {
|
if (!amount || amount === "") {
|
||||||
// throw `Invalid amount to redeem from the ${reserve} reserve`;
|
throw `Invalid amount to redeem from the ${reserve} reserve`;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await redeem(reserve, amount, userAddress, expected, revertMessage);
|
await redeem(reserve, amount, user, expected, testEnv, revertMessage);
|
||||||
// }
|
}
|
||||||
// break;
|
break;
|
||||||
// case "borrow":
|
case "borrow":
|
||||||
// {
|
{
|
||||||
// const {amount, borrowRateMode, timeTravel} = action.args;
|
const {amount, borrowRateMode, timeTravel} = action.args;
|
||||||
|
|
||||||
// if (!amount || amount === "") {
|
if (!amount || amount === "") {
|
||||||
// throw `Invalid amount to borrow from the ${reserve} reserve`;
|
throw `Invalid amount to borrow from the ${reserve} reserve`;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// let rateMode: string = RateMode.None;
|
let rateMode: string = RateMode.None;
|
||||||
|
|
||||||
// if (borrowRateMode === "none") {
|
if (borrowRateMode === "none") {
|
||||||
// RateMode.None;
|
RateMode.None;
|
||||||
// } else if (borrowRateMode === "stable") {
|
} else if (borrowRateMode === "stable") {
|
||||||
// rateMode = RateMode.Stable;
|
rateMode = RateMode.Stable;
|
||||||
// } else if (borrowRateMode === "variable") {
|
} else if (borrowRateMode === "variable") {
|
||||||
// rateMode = RateMode.Variable;
|
rateMode = RateMode.Variable;
|
||||||
// } else {
|
} else {
|
||||||
// //random value, to test improper selection of the parameter
|
//random value, to test improper selection of the parameter
|
||||||
// rateMode = "4";
|
rateMode = "4";
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await borrow(
|
await borrow(
|
||||||
// reserve,
|
reserve,
|
||||||
// amount,
|
amount,
|
||||||
// rateMode,
|
rateMode,
|
||||||
// userAddress,
|
user,
|
||||||
// timeTravel,
|
timeTravel,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "repay":
|
case "repay":
|
||||||
// {
|
{
|
||||||
// const {amount, sendValue} = action.args;
|
const {amount, sendValue} = action.args;
|
||||||
// let {onBehalfOf} = action.args;
|
let {onBehalfOf: onBehalfOfIndex} = action.args;
|
||||||
|
|
||||||
// if (!amount || amount === "") {
|
if (!amount || amount === "") {
|
||||||
// throw `Invalid amount to repay into the ${reserve} reserve`;
|
throw `Invalid amount to repay into the ${reserve} reserve`;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (!onBehalfOf || onBehalfOf === "") {
|
let userToRepayOnBehalf: SignerWithAddress;
|
||||||
// console.log(
|
if (!onBehalfOfIndex || onBehalfOfIndex === "") {
|
||||||
// "WARNING: No onBehalfOf specified for a repay action. Defaulting to the repayer address"
|
console.log(
|
||||||
// );
|
"WARNING: No onBehalfOf specified for a repay action. Defaulting to the repayer address"
|
||||||
// onBehalfOf = userAddress;
|
);
|
||||||
// } else {
|
userToRepayOnBehalf = user;
|
||||||
// onBehalfOf = users[parseInt(onBehalfOf)];
|
} else {
|
||||||
// }
|
userToRepayOnBehalf = users[parseInt(onBehalfOfIndex)];
|
||||||
|
}
|
||||||
|
|
||||||
// await repay(
|
await repay(
|
||||||
// reserve,
|
reserve,
|
||||||
// amount,
|
amount,
|
||||||
// userAddress,
|
user,
|
||||||
// onBehalfOf,
|
userToRepayOnBehalf,
|
||||||
// sendValue,
|
sendValue,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "setUseAsCollateral":
|
case "setUseAsCollateral":
|
||||||
// {
|
{
|
||||||
// const {useAsCollateral} = action.args;
|
const {useAsCollateral} = action.args;
|
||||||
|
|
||||||
// if (!useAsCollateral || useAsCollateral === "") {
|
if (!useAsCollateral || useAsCollateral === "") {
|
||||||
// throw `A valid value for useAsCollateral needs to be set when calling setUseReserveAsCollateral on reserve ${reserve}`;
|
throw `A valid value for useAsCollateral needs to be set when calling setUseReserveAsCollateral on reserve ${reserve}`;
|
||||||
// }
|
}
|
||||||
// await setUseAsCollateral(
|
await setUseAsCollateral(
|
||||||
// reserve,
|
reserve,
|
||||||
// userAddress,
|
user,
|
||||||
// useAsCollateral,
|
useAsCollateral,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "swapBorrowRateMode":
|
case "swapBorrowRateMode":
|
||||||
// await swapBorrowRateMode(reserve, userAddress, expected, revertMessage);
|
await swapBorrowRateMode(reserve, user, expected, testEnv, revertMessage);
|
||||||
// break;
|
break;
|
||||||
|
|
||||||
// case "rebalanceStableBorrowRate":
|
case "rebalanceStableBorrowRate":
|
||||||
// {
|
{
|
||||||
// const {target} = action.args;
|
const {target: targetIndex} = action.args;
|
||||||
|
|
||||||
// if (!target || target === "") {
|
if (!targetIndex || targetIndex === "") {
|
||||||
// throw `A target must be selected when trying to rebalance a stable rate`;
|
throw `A target must be selected when trying to rebalance a stable rate`;
|
||||||
// }
|
}
|
||||||
// const targetAddress = users[parseInt(target)];
|
const target = users[parseInt(targetIndex)];
|
||||||
|
|
||||||
// await rebalanceStableBorrowRate(
|
await rebalanceStableBorrowRate(
|
||||||
// reserve,
|
reserve,
|
||||||
// userAddress,
|
user,
|
||||||
// targetAddress,
|
target,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "redirectInterestStream":
|
case "redirectInterestStream":
|
||||||
// {
|
{
|
||||||
// const {to} = action.args;
|
const {to: toIndex} = action.args;
|
||||||
|
|
||||||
// if (!to || to === "") {
|
if (!toIndex || toIndex === "") {
|
||||||
// throw `A target must be selected when trying to redirect the interest`;
|
throw `A target must be selected when trying to redirect the interest`;
|
||||||
// }
|
}
|
||||||
// const toAddress = users[parseInt(to)];
|
const toUser = users[parseInt(toIndex)];
|
||||||
|
|
||||||
// await redirectInterestStream(
|
await redirectInterestStream(
|
||||||
// reserve,
|
reserve,
|
||||||
// userAddress,
|
user,
|
||||||
// toAddress,
|
toUser.address,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "redirectInterestStreamOf":
|
case "redirectInterestStreamOf":
|
||||||
// {
|
{
|
||||||
// const {from, to} = action.args;
|
const {from: fromIndex, to: toIndex} = action.args;
|
||||||
|
|
||||||
// if (!from || from === "") {
|
if (!fromIndex || fromIndex === "") {
|
||||||
// throw `A from address must be specified when trying to redirect the interest`;
|
throw `A from address must be specified when trying to redirect the interest`;
|
||||||
// }
|
}
|
||||||
// if (!to || to === "") {
|
if (!toIndex || toIndex === "") {
|
||||||
// throw `A target must be selected when trying to redirect the interest`;
|
throw `A target must be selected when trying to redirect the interest`;
|
||||||
// }
|
}
|
||||||
// const toAddress = users[parseInt(to)];
|
const toUser = users[parseInt(toIndex)];
|
||||||
// const fromAddress = users[parseInt(from)];
|
const fromUser = users[parseInt(fromIndex)];
|
||||||
|
|
||||||
// await redirectInterestStreamOf(
|
await redirectInterestStreamOf(
|
||||||
// reserve,
|
reserve,
|
||||||
// userAddress,
|
user,
|
||||||
// fromAddress,
|
fromUser.address,
|
||||||
// toAddress,
|
toUser.address,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// case "allowInterestRedirectionTo":
|
case "allowInterestRedirectionTo":
|
||||||
// {
|
{
|
||||||
// const {to} = action.args;
|
const {to: toIndex} = action.args;
|
||||||
|
|
||||||
// if (!to || to === "") {
|
if (!toIndex || toIndex === "") {
|
||||||
// throw `A target must be selected when trying to redirect the interest`;
|
throw `A target must be selected when trying to redirect the interest`;
|
||||||
// }
|
}
|
||||||
// const toAddress = users[parseInt(to)];
|
const toUser = users[parseInt(toIndex)];
|
||||||
|
|
||||||
// await allowInterestRedirectionTo(
|
await allowInterestRedirectionTo(
|
||||||
// reserve,
|
reserve,
|
||||||
// userAddress,
|
user,
|
||||||
// toAddress,
|
toUser.address,
|
||||||
// expected,
|
expected,
|
||||||
// revertMessage
|
testEnv,
|
||||||
// );
|
revertMessage
|
||||||
// }
|
);
|
||||||
// break;
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw `Invalid action requested: ${name}`;
|
throw `Invalid action requested: ${name}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,21 @@ BigNumber.config({DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN});
|
||||||
const scenarioFolder = "./test/helpers/scenarios/";
|
const scenarioFolder = "./test/helpers/scenarios/";
|
||||||
|
|
||||||
fs.readdirSync(scenarioFolder).forEach((file) => {
|
fs.readdirSync(scenarioFolder).forEach((file) => {
|
||||||
if (file !== "deposit.json") return;
|
if (
|
||||||
|
![
|
||||||
|
"borrow-negatives.json",
|
||||||
|
"borrow-repay-stable.json",
|
||||||
|
"deposit.json",
|
||||||
|
"redeem-negatives.json",
|
||||||
|
"redeem.json",
|
||||||
|
"set-use-as-collateral.json",
|
||||||
|
"swap-rate-mode.json",
|
||||||
|
"rebalance-stable-rate.json",
|
||||||
|
"interest-redirection.json",
|
||||||
|
"interest-redirection-negatives.json",
|
||||||
|
].includes(file)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
const scenario = require(`./helpers/scenarios/${file}`);
|
const scenario = require(`./helpers/scenarios/${file}`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user