Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace th.fastForwardTime() by Hardhat’s time.increase() #96

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions contracts/test/CollSurplusPool.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const deploymentHelper = require("../utils/deploymentHelpers.js");
const testHelpers = require("../utils/testHelpers.js");
const { fundAccounts } = require("../utils/fundAccounts.js");
Expand Down Expand Up @@ -64,10 +65,7 @@ contract("CollSurplusPool", async (accounts) => {
});

// skip bootstrapping phase
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_WEEK * 2,
web3.currentProvider
);
await time.increase(timeValues.SECONDS_IN_ONE_WEEK * 2);

// At ETH:USD = 100, this redemption should leave 1 ether of coll surplus
await th.redeemCollateralAndGetTxObject(A, contracts, B_netDebt);
Expand Down
9 changes: 5 additions & 4 deletions contracts/test/FeeArithmeticTest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const Decimal = require("decimal.js");
const deploymentHelper = require("../utils/deploymentHelpers.js")
const { BNConverter } = require("../utils/BNConverter.js")
Expand All @@ -19,7 +20,7 @@ contract('Fee arithmetic tests', async accounts => {
const [bountyAddress, lpRewardsAddress, multisig] = accounts.slice(997, 1000)

// see: https://docs.google.com/spreadsheets/d/1RbD8VGzq7xFgeK1GOkz_9bbKVIx-xkOz0VsVelnUFdc/edit#gid=0
// Results array, maps seconds to expected hours passed output (rounded down to nearest hour).
// Results array, maps seconds to expected minutes passed output (rounded down to nearest hour).

const secondsToMinutesRoundedDown = [
[0, 0],
Expand Down Expand Up @@ -351,16 +352,16 @@ contract('Fee arithmetic tests', async accounts => {
})

it("minutesPassedSinceLastFeeOp(): returns minutes passed between time of last fee operation and current block.timestamp, rounded down to nearest minutes", async () => {
for (const [seconds, expectedHoursPassed] of secondsToMinutesRoundedDown) {
for (const [seconds, expectedMinutesPassed] of secondsToMinutesRoundedDown) {
await troveManagerTester.setLastFeeOpTimeToNow()

if (seconds > 0) {
await th.fastForwardTime(seconds, web3.currentProvider)
await time.increase(seconds)
}

const minutesPassed = await troveManagerTester.minutesPassedSinceLastFeeOp()

assert.equal(expectedHoursPassed.toString(), minutesPassed.toString())
assert.equal(expectedMinutesPassed.toString(), minutesPassed.toString())
}
})

Expand Down
26 changes: 6 additions & 20 deletions contracts/test/StabilityPoolTest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { time } = require('@nomicfoundation/hardhat-network-helpers');
const deploymentHelper = require("../utils/deploymentHelpers.js");
const testHelpers = require("../utils/testHelpers.js");
const { fundAccounts } = require("../utils/fundAccounts.js");
Expand Down Expand Up @@ -1102,10 +1103,7 @@ contract("StabilityPool", async (accounts) => {
await stabilityPool.provideToSP(dec(105, 18), { from: D });

// time passes
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_HOUR,
web3.currentProvider
);
await time.increase(timeValues.SECONDS_IN_ONE_HOUR);

// B deposits
await stabilityPool.provideToSP(dec(5, 18), { from: B });
Expand Down Expand Up @@ -2210,10 +2208,7 @@ contract("StabilityPool", async (accounts) => {
await th.ICRbetween100and110(defaulter_1_TroveId, troveManager, price)
);

await th.fastForwardTime(
timeValues.MINUTES_IN_ONE_WEEK,
web3.currentProvider
);
await time.increase(timeValues.MINUTES_IN_ONE_WEEK);

// Liquidate d1
await troveManager.liquidate(defaulter_1_TroveId);
Expand Down Expand Up @@ -2897,10 +2892,7 @@ contract("StabilityPool", async (accounts) => {
await stabilityPool.provideToSP(dec(10000, 18), { from: E });

// Fast-forward time and make a second deposit
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_HOUR,
web3.currentProvider
);
await time.increase(timeValues.SECONDS_IN_ONE_HOUR);
await stabilityPool.provideToSP(dec(10000, 18), { from: E });

// perform a liquidation to make 0 < P < 1, and S > 0
Expand Down Expand Up @@ -3008,10 +3000,7 @@ contract("StabilityPool", async (accounts) => {
// SETUP: Execute a series of operations to trigger ETH rewards for depositor A

// Fast-forward time and make a second deposit
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_HOUR,
web3.currentProvider
);
await time.increase(timeValues.SECONDS_IN_ONE_HOUR);
await stabilityPool.provideToSP(dec(100, 18), { from: A });

// perform a liquidation to make 0 < P < 1, and S > 0
Expand Down Expand Up @@ -3711,10 +3700,7 @@ contract("StabilityPool", async (accounts) => {
await stabilityPool.provideToSP(dec(40, 18), { from: D });

// fastforward time, and E makes a deposit
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_HOUR,
web3.currentProvider
);
await time.increase(timeValues.SECONDS_IN_ONE_HOUR);
await openTrove({
extraBoldAmount: toBN(dec(3000, 18)),
ICR: toBN(dec(2, 18)),
Expand Down
Loading
Loading