fixed tests

This commit is contained in:
pradyuman-verma 2021-12-10 01:02:08 +05:30 committed by Ishan Jain
parent 46b0c02e18
commit 92b99247ea
17 changed files with 100 additions and 87 deletions

View File

@ -1,4 +1,4 @@
export const addresses: Record<string, any> = {
export default {
mainnet: {
connectors: {
basic: "0xe5398f279175962E56fE4c5E0b62dc7208EF36c6",

View File

@ -1,7 +1,7 @@
import hre from "hardhat";
import { expect } from "chai";
import { abis } from "../../../scripts/constant/abis";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";

View File

@ -1,7 +1,7 @@
import { expect } from "chai";
import hre from "hardhat";
import { abis } from "../../../scripts/constant/abis";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";

View File

@ -7,7 +7,7 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant";
import { ConnectV2BCompound__factory } from "../../../typechain";

View File

@ -7,7 +7,7 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { tokens } from "../../../scripts/constant/tokens";
import { ConnectV2BMakerDAO__factory } from "../../../typechain";

View File

@ -8,7 +8,7 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"
import addresses from "../../../scripts/constant/addresses"
import { abis } from "../../../scripts/constant/abis"
import type { Signer, Contract } from "ethers";

View File

@ -8,7 +8,7 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"
import addresses from "../../../scripts/constant/addresses"
import { abis } from "../../../scripts/constant/abis"
import type { Signer, Contract } from "ethers";

View File

@ -9,7 +9,7 @@ import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnable
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant";
import { ConnectV2Compound__factory } from "../../../typechain";

View File

@ -9,7 +9,7 @@ import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import encodeFlashcastData from "../../../scripts/tests/encodeFlashcastData"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import type { Signer, Contract } from "ethers";
import { ConnectV2Compound__factory } from "../../../typechain";

View File

@ -69,7 +69,7 @@ const COLL_SURPLUS_ABI = [
"function getCollateral(address _account) external view returns (uint)",
];
module.exports = {
export default {
TROVE_MANAGER_ADDRESS,
TROVE_MANAGER_ABI,
BORROWER_OPERATIONS_ADDRESS,

View File

@ -3,30 +3,31 @@ import { ethers } from "hardhat";
import hardhatConfig from "../../../hardhat.config";
// Instadapp deployment and testing helpers
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
// Instadapp instadappAddresses/ABIs
import { instadappAddresses } from "../../../scripts/important/addresses";
import { instadappAbi } from "../../../scripts/constant/abis";
import instadappAddresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
// Instadapp Liquity Connector artifacts
import { ConnectV2Liquity__factory, ConnectV2Basic__factory } from "../../../typechain";
// Instadapp uses a fake address to represent native ETH
import { constants } from "../../../scripts/constant/constant.js";
import type { Signer, Contract } from "ethers";
import { constants } from "../../../scripts/constant/constant";
import type { Signer, Contract, BigNumber } from "ethers";
const LIQUITY_CONNECTOR = "LIQUITY-v1-TEST";
const LUSD_GAS_COMPENSATION = hre.ethers.utils.parseUnits("200", 18); // 200 LUSD gas compensation repaid after loan repayment
const LIQUIDATABLE_TROVES_BLOCK_NUMBER = 12478159; // Deterministic block number for tests to run against, if you change this, tests will break.
const JUSTIN_SUN_ADDRESS = "0x903d12bf2c57a29f32365917c706ce0e1a84cce3"; // LQTY whale address
const LIQUIDATABLE_TROVE_ADDRESS = "0xafbeb4cb97f3b08ec2fe07ef0dac15d37013a347"; // Trove which is liquidatable at blockNumber: LIQUIDATABLE_TROVES_BLOCK_NUMBER
// const MAX_GAS = hardhatConfig.networks.hardhat.blockGasLimit; // Maximum gas limit (12000000)
// @ts-ignore
const MAX_GAS = hardhatConfig.networks.hardhat.blockGasLimit ?? 12000000; // Maximum gas limit (12000000)
const INSTADAPP_BASIC_V1_CONNECTOR = "Basic-v1";
const ETH = constants.native_address
const openTroveSpell = async (
dsa: any,
@ -121,24 +122,26 @@ const resetHardhatBlockNumber = async (blockNumber: number) => {
const deployAndConnect = async (contracts: any, isDebug = false) => {
// Pin Liquity tests to a particular block number to create deterministic state (Ether price etc.)
await resetHardhatBlockNumber(LIQUIDATABLE_TROVES_BLOCK_NUMBER);
let liquity = {
type Liquidity = {
troveManager: Contract,
borrowerOperations: null,
stabilityPool: null,
lusdToken: null,
lqtyToken: null,
activePool: null,
priceFeed: null,
hintHelpers: null,
sortedTroves: null,
staking: null,
collSurplus: null,
borrowerOperations: Contract,
stabilityPool: Contract,
lusdToken: Contract,
lqtyToken: Contract,
activePool: Contract,
priceFeed: Contract,
hintHelpers: Contract,
sortedTroves: Contract,
staking: Contract,
collSurplus: Contract,
};
const liquity = {} as Liquidity
const masterSigner = await getMasterSigner();
const instaConnectorsV2 = await ethers.getContractAt(
instadappAbi.core.connectorsV2,
instadappAddresses.core.connectorsV2
abis.core.connectorsV2,
instadappAddresses.mainnet.core.connectorsV2
);
const connector = await deployAndEnableConnector({
connectorName: LIQUITY_CONNECTOR,
@ -225,7 +228,7 @@ const deployAndConnect = async (contracts: any, isDebug = false) => {
return liquity;
};
const getTroveInsertionHints = async (depositAmount, borrowAmount, liquity: any) => {
const getTroveInsertionHints = async (depositAmount: BigNumber, borrowAmount: BigNumber, liquity: any) => {
const nominalCR = await liquity.hintHelpers.computeNominalCR(
depositAmount,
borrowAmount
@ -259,7 +262,7 @@ const getTroveInsertionHints = async (depositAmount, borrowAmount, liquity: any)
let randomSeed = 4223;
const getRedemptionHints = async (amount, liquity) => {
const getRedemptionHints = async (amount: any, liquity: any) => {
const ethPrice = await liquity.priceFeed.callStatic.fetchPrice();
const [
firstRedemptionHint,
@ -299,7 +302,7 @@ const getRedemptionHints = async (amount, liquity) => {
};
};
const redeem = async (amount, from, wallet, liquity) => {
const redeem = async (amount: any, from: any, wallet: { address: any; }, liquity: any) => {
await sendToken(liquity.lusdToken, amount, from, wallet.address);
const {
partialRedemptionHintNicr,
@ -325,7 +328,7 @@ const redeem = async (amount, from, wallet, liquity) => {
);
};
module.exports = {
export default {
deployAndConnect,
resetInitialState,
createDsaTrove,
@ -339,5 +342,5 @@ module.exports = {
LIQUIDATABLE_TROVE_ADDRESS,
MAX_GAS,
INSTADAPP_BASIC_V1_CONNECTOR,
ETH_ADDRESS,
ETH,
};

View File

@ -3,13 +3,14 @@ import { expect } from "chai";
// Instadapp deployment and testing helpers
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
// Liquity smart contracts
import contracts from "./liquity.contracts";
// Liquity helpers
import helpers from "./liquity.helpers";
import { Contract, Signer } from "ethers";
describe("Liquity", () => {
const { waffle, ethers } = hre;
@ -17,8 +18,8 @@ describe("Liquity", () => {
// Waffle test account 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (holds 1000 ETH)
const userWallet = provider.getWallets()[0];
let dsa = null;
let liquity = null;
let dsa: any;
let liquity: any;
before(async () => {
await hre.network.provider.request({
@ -26,6 +27,7 @@ describe("Liquity", () => {
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
@ -143,7 +145,7 @@ describe("Liquity", () => {
const depositEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "deposit",
args: [helpers.ETH_ADDRESS, depositAmount, 0, depositId],
args: [helpers.ETH, depositAmount, 0, depositId],
};
const openTroveSpell = {
@ -321,8 +323,9 @@ describe("Liquity", () => {
}
);
const receipt = await openTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
expect(castLogEvent.eventNames[0]).eq(
"LogOpen(address,uint256,uint256,uint256,uint256[],uint256[])"
);
@ -541,7 +544,7 @@ describe("Liquity", () => {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "withdraw",
args: [
helpers.ETH_ADDRESS,
helpers.ETH,
0, // amount comes from the previous spell's setId
dsa.address,
collateralWithdrawId,
@ -612,8 +615,9 @@ describe("Liquity", () => {
.cast(...encodeSpells([closeTroveSpell]), userWallet.address);
const receipt = await closeTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256"],
[dsa.address, 0]
@ -673,7 +677,7 @@ describe("Liquity", () => {
const depositEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "deposit",
args: [helpers.ETH_ADDRESS, topupAmount, 0, depositId],
args: [helpers.ETH, topupAmount, 0, depositId],
};
const upperHint = ethers.constants.AddressZero;
@ -725,8 +729,9 @@ describe("Liquity", () => {
});
const receipt = await depositTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256"],
[dsa.address, topupAmount, 0, 0]
@ -796,7 +801,7 @@ describe("Liquity", () => {
const withdrawEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "withdraw",
args: [helpers.ETH_ADDRESS, 0, userWallet.address, withdrawId, 0],
args: [helpers.ETH, 0, userWallet.address, withdrawId, 0],
};
const spells = [withdrawEthFromTroveSpell, withdrawEthSpell];
await dsa
@ -844,8 +849,9 @@ describe("Liquity", () => {
.cast(...encodeSpells([withdrawEthSpell]), userWallet.address);
const receipt = await withdrawTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256"],
[dsa.address, withdrawAmount, 0, 0]
@ -973,8 +979,9 @@ describe("Liquity", () => {
.cast(...encodeSpells([borrowSpell]), userWallet.address);
const receipt = await borrowTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256"],
[dsa.address, borrowAmount, 0, 0]
@ -1130,8 +1137,9 @@ describe("Liquity", () => {
});
const receipt = await repayTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256"],
[dsa.address, repayAmount, 0, 0]
@ -1295,7 +1303,7 @@ describe("Liquity", () => {
const depositEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "deposit",
args: [helpers.ETH_ADDRESS, depositAmount, 0, ethDepositId],
args: [helpers.ETH, depositAmount, 0, ethDepositId],
};
const depositLusdSpell = {
@ -1403,13 +1411,7 @@ describe("Liquity", () => {
const withdrawEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "withdraw",
args: [
helpers.ETH_ADDRESS,
0,
userWallet.address,
ethWithdrawId,
0,
],
args: [helpers.ETH, 0, userWallet.address, ethWithdrawId, 0],
};
const withdrawLusdSpell = {
@ -1484,8 +1486,9 @@ describe("Liquity", () => {
});
const receipt = await adjustTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
[
"address",
@ -1645,8 +1648,9 @@ describe("Liquity", () => {
);
const receipt = await claimTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"],
[dsa.address, claimAmount, setId]
@ -1768,7 +1772,7 @@ describe("Liquity", () => {
// Fast forward in time so we have an LQTY gain
await provider.send("evm_increaseTime", [600]);
await provider.send("evm_mine");
await provider.send("evm_mine", []);
// Create a Stability Pool deposit with a differen DSA so that LQTY gains can be calculated
// See: https://github.com/liquity/dev/#lqty-reward-events-and-payouts
@ -1796,8 +1800,9 @@ describe("Liquity", () => {
.cast(...encodeSpells([stabilityDepositSpell]), userWallet.address);
const receipt = await depositAgainTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
[
"address",
@ -1992,7 +1997,7 @@ describe("Liquity", () => {
// Fast forward in time so we have an LQTY gain
await provider.send("evm_increaseTime", [600]);
await provider.send("evm_mine");
await provider.send("evm_mine", []);
// Create another Stability Pool deposit so that LQTY gains are realized
// See: https://github.com/liquity/dev/#lqty-reward-events-and-payouts
@ -2034,8 +2039,9 @@ describe("Liquity", () => {
);
const receipt = await withdrawTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
[
"address",
@ -2172,8 +2178,9 @@ describe("Liquity", () => {
const receipt = await moveEthGainTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256"],
[dsa.address, ethGainFromLiquidation]
@ -2293,8 +2300,9 @@ describe("Liquity", () => {
const receipt = await stakeTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256", "uint256"],
[
@ -2457,8 +2465,9 @@ describe("Liquity", () => {
const receipt = await unstakeTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256", "uint256"],
[
@ -2601,7 +2610,7 @@ describe("Liquity", () => {
const withdrawEthSpell = {
connector: helpers.INSTADAPP_BASIC_V1_CONNECTOR,
method: "withdraw",
args: [helpers.ETH_ADDRESS, 0, userWallet.address, ethGainId, 0],
args: [helpers.ETH, 0, userWallet.address, ethGainId, 0],
};
const withdrawLusdSpell = {
@ -2702,8 +2711,9 @@ describe("Liquity", () => {
const receipt = await claimGainsTx.wait();
const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args;
const castLogEvent = receipt.events.find(
(e: { event: string }) => e.event === "LogCast"
).args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256"],
[stakerDsa.address, ethGain, lusdGain, setEthGainId, setLusdGainId]

View File

@ -8,7 +8,7 @@ import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant";
import { tokens } from "../../../scripts/constant/tokens";

View File

@ -8,7 +8,7 @@ import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addLiquidity } from "../../../scripts/tests/addLiquidity";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import type { Signer, Contract } from "ethers";

View File

@ -9,7 +9,7 @@ import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addLiquidity } from "../../../scripts/tests/addLiquidity";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { abi } from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json"
import type { Signer, Contract } from "ethers";

View File

@ -8,7 +8,7 @@ import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { tokens } from "../../../scripts/constant/tokens";
import { Signer, Contract, BigNumber } from "ethers";

View File

@ -10,7 +10,7 @@ import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/constant/addresses";
import addresses from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { tokens } from "../../../scripts/constant/tokens";
import type { Signer, Contract } from "ethers";