Skip to content

Commit

Permalink
Fix FeeArithmeticTest (#95)
Browse files Browse the repository at this point in the history
`minutesPassedSinceLastFeeOp()` tests:

- Do not mine a new block if the time increase is `0`.
- Replace “hours” by “minutes”.

All tests:

- Migrate from `th.fastForwardTime()` to `time.increase()` (better reliability with the hardhat’s ethereum client).
  • Loading branch information
bpierre authored Apr 4, 2024
1 parent a3e5d0c commit bb58f3b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 168 deletions.
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
14 changes: 7 additions & 7 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,17 +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 (testPair of secondsToMinutesRoundedDown) {
for (const [seconds, expectedMinutesPassed] of secondsToMinutesRoundedDown) {
await troveManagerTester.setLastFeeOpTimeToNow()

const seconds = testPair[0]
const expectedHoursPassed = testPair[1]

await th.fastForwardTime(seconds, web3.currentProvider)
if (seconds > 0) {
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

0 comments on commit bb58f3b

Please sign in to comment.