mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
use object spec for tests
This commit is contained in:
parent
c0507e9264
commit
4df8b8bf56
126
test/liquity.js
126
test/liquity.js
|
|
@ -1,5 +1,6 @@
|
||||||
const { expect } = require("chai");
|
const { expect } = require("chai");
|
||||||
const hardhatConfig = require("../hardhat.config");
|
const hardhatConfig = require("../hardhat.config");
|
||||||
|
|
||||||
const { BigNumber } = hre.ethers;
|
const { BigNumber } = hre.ethers;
|
||||||
|
|
||||||
// Deterministic block number to run these tests from on forked mainnet. If you change this, tests will break.
|
// Deterministic block number to run these tests from on forked mainnet. If you change this, tests will break.
|
||||||
|
|
@ -13,28 +14,37 @@ const PRICE_FEED_ADDRESS = "0x4c517D4e2C851CA76d7eC94B805269Df0f2201De";
|
||||||
const PRICE_FEED_ABI = ["function fetchPrice() external returns (uint)"];
|
const PRICE_FEED_ABI = ["function fetchPrice() external returns (uint)"];
|
||||||
|
|
||||||
/* Begin: Mock test data (based on specified BLOCK_NUMBER and JUSTIN_SUN_ADDRESS) */
|
/* Begin: Mock test data (based on specified BLOCK_NUMBER and JUSTIN_SUN_ADDRESS) */
|
||||||
const expectedTrovePosition = [
|
const expectedTrovePosition = {
|
||||||
/* collateral */ BigNumber.from("582880000000000000000000"),
|
collateral: BigNumber.from("582880000000000000000000"),
|
||||||
/* debt */ BigNumber.from("372000200000000000000000000"),
|
debt: BigNumber.from("372000200000000000000000000"),
|
||||||
/* icr */ BigNumber.from("3859882210893925325"),
|
icr: BigNumber.from("3859882210893925325"),
|
||||||
];
|
};
|
||||||
const expectedStabilityPosition = [
|
const expectedStabilityPosition = {
|
||||||
/* deposit */ BigNumber.from("299979329615565997640451998"),
|
deposit: BigNumber.from("299979329615565997640451998"),
|
||||||
/* ethGain */ BigNumber.from("8629038660000000000"),
|
ethGain: BigNumber.from("8629038660000000000"),
|
||||||
/* lqtyGain */ BigNumber.from("53244322633874479119945"),
|
lqtyGain: BigNumber.from("53244322633874479119945"),
|
||||||
];
|
};
|
||||||
const expectedStakePosition = [
|
const expectedStakePosition = {
|
||||||
/* amount */ BigNumber.from("981562996504090969804965"),
|
amount: BigNumber.from("981562996504090969804965"),
|
||||||
/* ethGain */ BigNumber.from("18910541408996344243"),
|
ethGain: BigNumber.from("18910541408996344243"),
|
||||||
/* lusdGain */ BigNumber.from("66201062534511228032281"),
|
lusdGain: BigNumber.from("66201062534511228032281"),
|
||||||
];
|
};
|
||||||
|
const expectedSystemState = {
|
||||||
const expectedSystemState = [
|
borrowFee: BigNumber.from("6900285109012952"),
|
||||||
/* borrowFee */ BigNumber.from("6900285109012952"),
|
ethTvl: BigNumber.from("852500462432421494350957"),
|
||||||
/* ethTvl */ BigNumber.from("852500462432421494350957"),
|
tcr: BigNumber.from("3250195441371082828"),
|
||||||
/* tcr */ BigNumber.from("3250195441371082828"),
|
isInRecoveryMode: false,
|
||||||
/* isInRecoveryMode */ false,
|
};
|
||||||
];
|
const expectedTrovePositionHints = {
|
||||||
|
upperHint: "0xbf9a4eCC4151f28C03100bA2C0555a3D3e439e69",
|
||||||
|
lowerHint: "0xa4FC81A7AB93360543eb1e814D0127f466012CED",
|
||||||
|
};
|
||||||
|
const expectedRedemptionPositionHints = {
|
||||||
|
partialRedemptionHintNicr: "69529933762909647",
|
||||||
|
firstHint: "0xc16aDd8bA17ab81B27e930Da8a67848120565d8c",
|
||||||
|
upperHint: "0x66882C005188F0F4d95825ED7A7F78ed3055f167",
|
||||||
|
lowerHint: "0x0C22C11a8ed4C23ffD19629283548B1692b58e92",
|
||||||
|
};
|
||||||
/* End: Mock test data */
|
/* End: Mock test data */
|
||||||
|
|
||||||
describe("InstaLiquityResolver", () => {
|
describe("InstaLiquityResolver", () => {
|
||||||
|
|
@ -55,6 +65,7 @@ describe("InstaLiquityResolver", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
liquity = await liquityFactory.deploy();
|
liquity = await liquityFactory.deploy();
|
||||||
|
|
||||||
await liquity.deployed();
|
await liquity.deployed();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -69,7 +80,11 @@ describe("InstaLiquityResolver", () => {
|
||||||
JUSTIN_SUN_ADDRESS,
|
JUSTIN_SUN_ADDRESS,
|
||||||
oracleEthPrice
|
oracleEthPrice
|
||||||
);
|
);
|
||||||
expect(trovePosition).to.eql(expectedTrovePosition);
|
expect(trovePosition.collateral).to.equal(
|
||||||
|
expectedTrovePosition.collateral
|
||||||
|
);
|
||||||
|
expect(trovePosition.debt).to.equal(expectedTrovePosition.debt);
|
||||||
|
expect(trovePosition.icr).to.equal(expectedTrovePosition.icr);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -78,14 +93,24 @@ describe("InstaLiquityResolver", () => {
|
||||||
const stabilityPosition = await liquity.getStabilityDeposit(
|
const stabilityPosition = await liquity.getStabilityDeposit(
|
||||||
JUSTIN_SUN_ADDRESS
|
JUSTIN_SUN_ADDRESS
|
||||||
);
|
);
|
||||||
expect(stabilityPosition).to.eql(expectedStabilityPosition);
|
expect(stabilityPosition.deposit).to.equal(
|
||||||
|
expectedStabilityPosition.deposit
|
||||||
|
);
|
||||||
|
expect(stabilityPosition.ethGain).to.equal(
|
||||||
|
expectedStabilityPosition.ethGain
|
||||||
|
);
|
||||||
|
expect(stabilityPosition.lqtyGain).to.equal(
|
||||||
|
expectedStabilityPosition.lqtyGain
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getStake()", () => {
|
describe("getStake()", () => {
|
||||||
it("returns a user's Stake position", async () => {
|
it("returns a user's Stake position", async () => {
|
||||||
const stakePosition = await liquity.getStake(JUSTIN_SUN_ADDRESS);
|
const stakePosition = await liquity.getStake(JUSTIN_SUN_ADDRESS);
|
||||||
expect(stakePosition).to.eql(expectedStakePosition);
|
expect(stakePosition.amount).to.equal(expectedStakePosition.amount);
|
||||||
|
expect(stakePosition.ethGain).to.equal(expectedStakePosition.ethGain);
|
||||||
|
expect(stakePosition.lusdGain).to.equal(expectedStakePosition.lusdGain);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -96,12 +121,30 @@ describe("InstaLiquityResolver", () => {
|
||||||
JUSTIN_SUN_ADDRESS,
|
JUSTIN_SUN_ADDRESS,
|
||||||
oracleEthPrice
|
oracleEthPrice
|
||||||
);
|
);
|
||||||
const expectedPosition = [
|
const expectedPosition = {
|
||||||
expectedTrovePosition,
|
trove: expectedTrovePosition,
|
||||||
expectedStabilityPosition,
|
stability: expectedStabilityPosition,
|
||||||
expectedStakePosition,
|
stake: expectedStakePosition,
|
||||||
];
|
};
|
||||||
expect(position).to.eql(expectedPosition);
|
expect(position.trove.collateral).to.equal(
|
||||||
|
expectedPosition.trove.collateral
|
||||||
|
);
|
||||||
|
expect(position.trove.debt).to.equal(expectedPosition.trove.debt);
|
||||||
|
expect(position.trove.icr).to.equal(expectedPosition.trove.icr);
|
||||||
|
|
||||||
|
expect(position.stability.deposit).to.equal(
|
||||||
|
expectedPosition.stability.deposit
|
||||||
|
);
|
||||||
|
expect(position.stability.ethGain).to.equal(
|
||||||
|
expectedPosition.stability.ethGain
|
||||||
|
);
|
||||||
|
expect(position.stability.lqtyGain).to.equal(
|
||||||
|
expectedPosition.stability.lqtyGain
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(position.stake.amount).to.equal(expectedPosition.stake.amount);
|
||||||
|
expect(position.stake.ethGain).to.equal(expectedPosition.stake.ethGain);
|
||||||
|
expect(position.stake.lusdGain).to.equal(expectedPosition.stake.lusdGain);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -109,7 +152,12 @@ describe("InstaLiquityResolver", () => {
|
||||||
it("returns Liquity system state", async () => {
|
it("returns Liquity system state", async () => {
|
||||||
const oracleEthPrice = await liquityPriceOracle.callStatic.fetchPrice();
|
const oracleEthPrice = await liquityPriceOracle.callStatic.fetchPrice();
|
||||||
const systemState = await liquity.getSystemState(oracleEthPrice);
|
const systemState = await liquity.getSystemState(oracleEthPrice);
|
||||||
expect(systemState).to.eql(expectedSystemState);
|
expect(systemState.borrowFee).to.equal(expectedSystemState.borrowFee);
|
||||||
|
expect(systemState.ethTvl).to.equal(expectedSystemState.ethTvl);
|
||||||
|
expect(systemState.tcr).to.equal(expectedSystemState.tcr);
|
||||||
|
expect(systemState.isInRecoveryMode).to.equal(
|
||||||
|
expectedSystemState.isInRecoveryMode
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -124,8 +172,8 @@ describe("InstaLiquityResolver", () => {
|
||||||
searchIterations
|
searchIterations
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(upperHint).eq("0xbf9a4eCC4151f28C03100bA2C0555a3D3e439e69");
|
expect(upperHint).eq(expectedTrovePositionHints.upperHint);
|
||||||
expect(lowerHint).eq("0xa4FC81A7AB93360543eb1e814D0127f466012CED");
|
expect(lowerHint).eq(expectedTrovePositionHints.lowerHint);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -145,10 +193,12 @@ describe("InstaLiquityResolver", () => {
|
||||||
searchIterations
|
searchIterations
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(partialRedemptionHintNicr).eq("69529933762909647");
|
expect(partialRedemptionHintNicr).eq(
|
||||||
expect(firstHint).eq("0xc16aDd8bA17ab81B27e930Da8a67848120565d8c");
|
expectedRedemptionPositionHints.partialRedemptionHintNicr
|
||||||
expect(upperHint).eq("0x66882C005188F0F4d95825ED7A7F78ed3055f167");
|
);
|
||||||
expect(lowerHint).eq("0x0C22C11a8ed4C23ffD19629283548B1692b58e92");
|
expect(firstHint).eq(expectedRedemptionPositionHints.firstHint);
|
||||||
|
expect(upperHint).eq(expectedRedemptionPositionHints.upperHint);
|
||||||
|
expect(lowerHint).eq(expectedRedemptionPositionHints.lowerHint);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user