Skip to content

Commit

Permalink
Merge pull request #114 from meTokens/chore/standard-descriptions
Browse files Browse the repository at this point in the history
Standardise test description
  • Loading branch information
Carter Carlson authored Feb 14, 2022
2 parents aa59b85 + 4d98f49 commit 8cf98ee
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 54 deletions.
37 changes: 13 additions & 24 deletions test/integration/Hub/UpdateCurveDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import {
passHours,
passSeconds,
setAutomine,
setNextBlockTimestamp,
} from "../../utils/hardhatNode";
import { ICurve } from "../../../artifacts/types/ICurve";
import { start } from "repl";
import { WeightedAverage } from "../../../artifacts/types/WeightedAverage";
const setup = async () => {
describe("Hub - update CurveDetails", () => {
Expand Down Expand Up @@ -117,7 +115,7 @@ const setup = async () => {
const name = "Carl0 meToken";
const symbol = "CARL";

const tx = await meTokenRegistry
await meTokenRegistry
.connect(account0)
.subscribe(name, symbol, firstHubId, 0);
const meTokenAddr = await meTokenRegistry.getOwnerMeToken(
Expand All @@ -130,12 +128,10 @@ const setup = async () => {
await token.connect(account1).approve(singleAssetVault.address, max);
await token.connect(account2).approve(singleAssetVault.address, max);

const balBefore = await meToken.balanceOf(account2.address);
const vaultBalBefore = await token.balanceOf(singleAssetVault.address);
await foundry
.connect(account2)
.mint(meTokenAddr, tokenDeposited, account2.address);
const balAfter = await meToken.balanceOf(account2.address);
const vaultBalAfter = await token.balanceOf(singleAssetVault.address);
expect(vaultBalAfter.sub(vaultBalBefore)).to.equal(tokenDeposited);
//setWarmup for 2 days
Expand All @@ -161,7 +157,7 @@ const setup = async () => {
});

describe("Warmup", () => {
it("should revert if targetCurve is the current curve", async () => {
it("should revert initUpdate() if targetCurve is the current curve", async () => {
const updatedEncodedCurveDetails = ethers.utils.defaultAbiCoder.encode(
["uint256", "uint32"],
[updatedBaseY, updatedReserveWeight]
Expand All @@ -175,7 +171,7 @@ const setup = async () => {
)
).to.be.revertedWith("targetCurve==curve");
});
it("Assets received based on initial curveDetails", async () => {
it("Assets received based on initial initialCurveDetails", async () => {
const updatedEncodedCurveDetails = ethers.utils.defaultAbiCoder.encode(
["uint256", "uint32"],
[updatedBaseY, updatedReserveWeight]
Expand Down Expand Up @@ -283,7 +279,7 @@ const setup = async () => {
before(async () => {
await passHours(1);
});
it("Assets received for buyer based on weighted average burning full supply ", async () => {
it("Assets received for buyer based on weighted average of curveDetails on burning full supply ", async () => {
//move forward 3 Days
await passDays(3);
const tokenDepositedInETH = 100;
Expand Down Expand Up @@ -365,7 +361,7 @@ const setup = async () => {
toETHNumber(balDaiAfterBurn.sub(balDaiAfterMint))
).to.be.approximately(assetsReturned, 0.000000000000001);
});
it("Assets received for buyer based on weighted average not burning full supply ", async () => {
it("Assets received for buyer based on weighted average of curveDetails on not burning full supply ", async () => {
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
tokenDepositedInETH.toString()
Expand Down Expand Up @@ -447,7 +443,7 @@ const setup = async () => {
toETHNumber(balDaiAfterBurn.sub(balDaiAfterMint))
).to.be.approximately(assetsReturned, 0.000000000000001);
});
it("Assets received for owner based on weighted average not burning full supply ", async () => {
it("Assets received for owner based on weighted average of curveDetails on not burning full supply ", async () => {
// TODO: calculate weighted refundRatio based on current time relative to duration
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
Expand Down Expand Up @@ -537,7 +533,7 @@ const setup = async () => {
toETHNumber(balDaiAfterBurn.sub(balDaiAfterMint))
).to.be.approximately(assetsReturned, 0.0000000000001);
});
it("mint(): assets received based on weighted average", async () => {
it("mint(): assets received based on weighted average of curveDetails", async () => {
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
tokenDepositedInETH.toString()
Expand Down Expand Up @@ -603,17 +599,10 @@ const setup = async () => {
});

describe("Cooldown", () => {
it("initUpdate() cannot be called", async () => {
const {
active,
refundRatio,
updating,
startTime,
endTime,
endCooldown,
reconfigure,
targetRefundRatio,
} = await hub.getDetails(1);
it("should revert initUpdate() if before cool down", async () => {
const { active, updating, endTime, reconfigure } = await hub.getDetails(
1
);
expect(active).to.be.true;
expect(updating).to.be.true;
expect(reconfigure).to.be.false;
Expand All @@ -632,7 +621,7 @@ const setup = async () => {
).to.be.revertedWith("Still cooling down");
});

it("burn() and mint() by owner should use the targetCurve", async () => {
it("burn() and mint() by owner should use the targetCurveDetails", async () => {
// TODO: calculate weighted refundRatio based on current time relative to duration
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
Expand Down Expand Up @@ -733,7 +722,7 @@ const setup = async () => {
toETHNumber(balDaiAfterBurn.sub(balDaiAfterMint))
).to.be.approximately(assetsReturned, 0.00000000001);
});
it("burn() and mint() by buyer should use the targetCurve", async () => {
it("burn() and mint() by buyer should use the targetCurveDetails", async () => {
// TODO: calculate weighted refundRatio based on current time relative to duration
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
Expand Down
23 changes: 8 additions & 15 deletions test/integration/Hub/UpdateRefundRatio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethers, getNamedAccounts } from "hardhat";
import {
calculateCollateralReturned,
calculateTokenReturned,
deploy,
getContractAt,
toETHNumber,
Expand Down Expand Up @@ -50,8 +49,6 @@ const setup = async () => {
const firstRefundRatio = 5000;
const targetedRefundRatio = 500000; // 50%
before(async () => {
// TODO: pre-load contracts
// NOTE: hub.register() should have already been called
baseY = one.mul(1000);
let DAI;
({ DAI } = await getNamedAccounts());
Expand Down Expand Up @@ -103,7 +100,7 @@ const setup = async () => {
const name = "Carl0 meToken";
const symbol = "CARL";

const tx = await meTokenRegistry
await meTokenRegistry
.connect(account0)
.subscribe(name, "CARL", firstHubId, 0);
const meTokenAddr = await meTokenRegistry.getOwnerMeToken(
Expand All @@ -112,12 +109,10 @@ const setup = async () => {
meToken = await getContractAt<MeToken>("MeToken", meTokenAddr);

const tokenDeposited = ethers.utils.parseEther("100");
const balBefore = await meToken.balanceOf(account2.address);
const vaultBalBefore = await token.balanceOf(singleAssetVault.address);
await foundry
.connect(account2)
.mint(meTokenAddr, tokenDeposited, account2.address);
const balAfter = await meToken.balanceOf(account2.address);
const vaultBalAfter = await token.balanceOf(singleAssetVault.address);
expect(vaultBalAfter.sub(vaultBalBefore)).to.equal(tokenDeposited);
//setWarmup for 2 days
Expand All @@ -142,7 +137,7 @@ const setup = async () => {
expect(duration).to.equal(604800);
});

describe("During warmup", () => {
describe("Warmup", () => {
before(async () => {
await hub.initUpdate(
firstHubId,
Expand All @@ -151,12 +146,11 @@ const setup = async () => {
ethers.utils.toUtf8Bytes("")
);
});
it("initUpdate() cannot be called", async () => {
// TODO: fast fwd a little bit
it("should revert initUpdate() if already updating", async () => {
// fast fwd a little bit
let lastBlock = await ethers.provider.getBlock("latest");
await passDays(1);
lastBlock = await ethers.provider.getBlock("latest");
//await hub.setWarmup(172801);
lastBlock = await ethers.provider.getBlock("latest");
await expect(
hub.initUpdate(1, bancorABDK.address, 1000, encodedCurveDetails)
Expand Down Expand Up @@ -243,14 +237,13 @@ const setup = async () => {
before(async () => {
await passHours(1);
});
it("initUpdate() cannot be called", async () => {
// TODO: fast to active duration
it("should revert initUpdate() if already updating", async () => {
await expect(
hub.initUpdate(1, bancorABDK.address, 1000, encodedCurveDetails)
).to.be.revertedWith("already updating");
});

it("Assets received for owner are not based on weighted average refund ratio only applies to buyer", async () => {
it("Assets received for owner should not apply refund ratio", async () => {
//move forward 2 Days
await passDays(2);
const tokenDepositedInETH = 100;
Expand Down Expand Up @@ -306,7 +299,7 @@ const setup = async () => {
);
});

it("Assets received for buyer based on weighted average", async () => {
it("Assets received for buyer based on weighted average refundRatio", async () => {
//move forward 3 Days
await passDays(3);
// TODO: calculate weighted refundRatio based on current time relative to duration
Expand Down Expand Up @@ -407,7 +400,7 @@ const setup = async () => {
).to.be.revertedWith("Still cooling down");
});

it("Before refundRatio set, burn() for owner should not use the targetRefundRatio", async () => {
it("Before refundRatio set, burn() for owner should not apply refund ratio", async () => {
const tokenDepositedInETH = 100;
const tokenDeposited = ethers.utils.parseEther(
tokenDepositedInETH.toString()
Expand Down
9 changes: 6 additions & 3 deletions test/integration/MeTokenRegistry/ResubscribeCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ const setup = async () => {

describe("Warmup", () => {
before(async () => {
// BlockTime < startTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.startTime).to.be.gt(block.timestamp);
});
it("mint(): meTokens received based on initial Curve", async () => {
it("mint() [buyer]: meTokens received based on initial Curve", async () => {
const vaultDAIBefore = await dai.balanceOf(singleAssetVault.address);
const meTokenTotalSupplyBefore = await meToken.totalSupply();
expect(meTokenTotalSupplyBefore).to.be.equal(0);
Expand Down Expand Up @@ -351,6 +352,7 @@ const setup = async () => {

describe("Duration", () => {
before(async () => {
// IncreaseBlockTime > startTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
Expand All @@ -359,7 +361,7 @@ const setup = async () => {
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.startTime).to.be.lt(block.timestamp);
});
it("mint(): meTokens received based on weighted average of Curves", async () => {
it("mint() [buyer]: meTokens received based on weighted average of Curves", async () => {
const vaultDAIBefore = await dai.balanceOf(singleAssetVault.address);
const migrationWETHBefore = await weth.balanceOf(migration.address);
const meTokenTotalSupplyBefore = await meToken.totalSupply();
Expand Down Expand Up @@ -560,6 +562,7 @@ const setup = async () => {

describe("Cooldown", () => {
before(async () => {
// IncreaseBlockTime > endTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
Expand All @@ -568,7 +571,7 @@ const setup = async () => {
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.endTime).to.be.lt(block.timestamp);
});
it("mint(): assets received based on target Curve", async () => {
it("mint() [buyer]: assets received based on target Curve", async () => {
const vaultWETHBefore = await weth.balanceOf(singleAssetVault.address);
const migrationWETHBefore = await weth.balanceOf(migration.address);
const meTokenTotalSupplyBefore = await meToken.totalSupply();
Expand Down
9 changes: 6 additions & 3 deletions test/integration/MeTokenRegistry/ResubscribeCurveDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ const setup = async () => {

describe("Warmup", () => {
before(async () => {
// BlockTime < startTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.startTime).to.be.gt(block.timestamp);
});
it("mint(): meTokens received based on initial Curve details", async () => {
it("mint() [buyer]: meTokens received based on initial Curve details", async () => {
const vaultDAIBefore = await dai.balanceOf(singleAssetVault.address);
const meTokenTotalSupplyBefore = await meToken.totalSupply();
expect(meTokenTotalSupplyBefore).to.be.equal(0);
Expand Down Expand Up @@ -342,6 +343,7 @@ const setup = async () => {

describe("Duration", () => {
before(async () => {
// IncreaseBlockTime > startTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
Expand All @@ -350,7 +352,7 @@ const setup = async () => {
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.startTime).to.be.lt(block.timestamp);
});
it("mint(): meTokens received based on weighted average curve details", async () => {
it("mint() [buyer]: meTokens received based on weighted average curve details", async () => {
const vaultDAIBefore = await dai.balanceOf(singleAssetVault.address);
const migrationWETHBefore = await weth.balanceOf(migration.address);
const meTokenTotalSupplyBefore = await meToken.totalSupply();
Expand Down Expand Up @@ -547,6 +549,7 @@ const setup = async () => {

describe("Cooldown", () => {
before(async () => {
// IncreaseBlockTime > endTime
const metokenDetails = await meTokenRegistry.getDetails(
meToken.address
);
Expand All @@ -555,7 +558,7 @@ const setup = async () => {
const block = await ethers.provider.getBlock("latest");
expect(metokenDetails.endTime).to.be.lt(block.timestamp);
});
it("burn(): finish migration must be called", async () => {
it("burn() [buyer]: finish migration must be called", async () => {
const ownerMeToken = await meToken.balanceOf(account0.address);
const migrationWETHBefore = await weth.balanceOf(migration.address);
const meTokenTotalSupply = await meToken.totalSupply();
Expand Down
Loading

0 comments on commit 8cf98ee

Please sign in to comment.