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

Hardhat-network-helpers: TODOs as soon as V3 node is ready #5882

Merged
merged 12 commits into from
Oct 29, 2024
5 changes: 1 addition & 4 deletions v-next/example-project/scripts/network-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/**
* How to run this script:
* 1) Start a Hardhat V2 node (until the V3 node is ready)
* 3) Run this script with `npx hardhat run scripts/network-helpers.ts`.
* Run this script with `npx hardhat run scripts/network-helpers.ts`.
*/

import hre from "@ignored/hardhat-vnext";
// Example on how to import load fixture
// import { loadFixture } from "@ignored/hardhat-vnext-network-helpers/load-fixture";

const { networkHelpers } = await hre.network.connect();

Expand Down
4 changes: 1 addition & 3 deletions v-next/hardhat-network-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/src/index.js",
"./load-fixture": "./dist/src/load-fixture.js"
".": "./dist/src/index.js"
},
"keywords": [
"ethereum",
Expand All @@ -27,7 +26,6 @@
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
"test": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:tmp": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test-tmp/*.ts\" \"test-tmp/duration/*.ts\" && node --import tsx/esm ./run-tests.ts",
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude src/internal/types.ts --exclude src/internal/ui/direct-user-interruption-manager.ts --src src node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/!(fixture-projects|helpers)/**/*.ts\"",
"pretest": "pnpm build",
Expand Down
46 changes: 0 additions & 46 deletions v-next/hardhat-network-helpers/run-tests.ts

This file was deleted.

40 changes: 0 additions & 40 deletions v-next/hardhat-network-helpers/test-tmp/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Time } from "../../src/internal/network-helpers/time/time.js";
import type { EthereumProvider } from "@ignored/hardhat-vnext/types/providers";

import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre";
import { assertHardhatInvariant } from "@ignored/hardhat-vnext-errors";

import { NetworkHelpers } from "../../src/internal/network-helpers/network-helpers.js";

// TODO: revisit as soon as the V3 node is ready
export async function initializeNetwork(): Promise<{
provider: EthereumProvider;
networkHelpers: NetworkHelpers;
Expand All @@ -17,16 +15,9 @@ export async function initializeNetwork(): Promise<{

const networkHelpers = new NetworkHelpers(provider);

await networkHelpers.reset();

return { provider, networkHelpers };
}

export async function initializeTime(): Promise<Time> {
const { networkHelpers } = await initializeNetwork();
return networkHelpers.time;
}

export function rpcQuantityToNumber(quantity: string): number {
return parseInt(quantity, 16);
}
Expand Down
41 changes: 40 additions & 1 deletion v-next/hardhat-network-helpers/test/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
// TODO: revisit as soon as the V3 node is ready: move tests from TMP folder to this folder
import type { NetworkHelpers } from "../src/internal/network-helpers/network-helpers.js";
import type { HardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/types/hre";

import { beforeEach, describe, it } from "node:test";

import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre";

import hardhatNetworkHelpersPlugin from "../src/index.js";

describe("hardhat-network-helpers plugin initialization", () => {
// Check that the plugin is correctly initialized

let hre: HardhatRuntimeEnvironment;
let networkHelpers: NetworkHelpers;

beforeEach(async () => {
hre = await createHardhatRuntimeEnvironment({
plugins: [hardhatNetworkHelpersPlugin],
});

({ networkHelpers } = await hre.network.connect());
});

describe("network-helpers class and its sub classes", () => {
it("should correctly set up the network-helpers class", async () => {
// Test a method from the network-helpers class to be sure that it is correctly set up
await networkHelpers.takeSnapshot();
});

it("should correctly set up the time class", async () => {
// Test a method from the time class to be sure that it is correctly set up
await networkHelpers.time.latest();
});

it("should correctly set up the duration class", async () => {
// Test a method from the duration class to be sure that it is correctly set up
networkHelpers.time.duration.days(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@ignored/hardhat-vnext-errors";
import { assertRejectsWithHardhatError } from "@nomicfoundation/hardhat-test-utils";

import { initializeNetwork } from "../../test-tmp/helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("network-helpers - loadFixture", () => {
let networkHelpers: NetworkHelpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { before, describe, it } from "node:test";
import { numberToHexString } from "@ignored/hardhat-vnext-utils/hex";

import { toBigInt } from "../../src/internal/conversion.js";
import { initializeTime } from "../helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("time - increaseTo", () => {
let time: Time;

before(async () => {
time = await initializeTime();
const { networkHelpers } = await initializeNetwork();
time = networkHelpers.time;
});

it("should mine a new block with the given timestamp", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { before, describe, it } from "node:test";
import { HardhatError } from "@ignored/hardhat-vnext-errors";
import { assertRejectsWithHardhatError } from "@nomicfoundation/hardhat-test-utils";

import { initializeTime } from "../helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("time - increase", () => {
let time: Time;

before(async () => {
time = await initializeTime();
const { networkHelpers } = await initializeNetwork();
time = networkHelpers.time;
});

it("should mine a new block with the timestamp increased by a given number of seconds", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { Time } from "../../src/internal/network-helpers/time/time.js";
import assert from "node:assert/strict";
import { before, describe, it } from "node:test";

import { initializeNetwork, initializeTime } from "../helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("time -latestBlock", () => {
let time: Time;
let networkHelpers: NetworkHelpers;

before(async () => {
({ networkHelpers } = await initializeNetwork());
time = await initializeTime();
time = networkHelpers.time;
});

it("should retrieve the height of the latest block", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { Time } from "../../src/internal/network-helpers/time/time.js";
import assert from "node:assert/strict";
import { before, describe, it } from "node:test";

import { initializeTime } from "../helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("time - latest", () => {
let time: Time;

before(async () => {
time = await initializeTime();
const { networkHelpers } = await initializeNetwork();
time = networkHelpers.time;
});

it("should retrieve the timestamp of the latest block", async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { Time } from "../../src/internal/network-helpers/time/time.js";
import assert from "node:assert/strict";
import { before, describe, it } from "node:test";

import { initializeNetwork, initializeTime } from "../helpers/helpers.js";
import { initializeNetwork } from "../helpers/helpers.js";

describe("time - setNextBlockTimestamp", () => {
let time: Time;
let networkHelpers: NetworkHelpers;

before(async () => {
({ networkHelpers } = await initializeNetwork());
time = await initializeTime();
time = networkHelpers.time;
});

it("should not mine a new block", async () => {
Expand Down