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

feat: port the node task to hardhat v3 #6025

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 41 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const ERROR_CATEGORIES: {
},
SOLIDITY: { min: 1200, max: 1299, websiteTitle: "Solidity errors" },
VIEM: { min: 1300, max: 1399, websiteTitle: "Hardhat-viem errors" },
NODE: { min: 1400, max: 1499, websiteTitle: "Hardhat node errors" },
};

export const ERRORS = {
Expand Down Expand Up @@ -1247,4 +1248,13 @@ Please check Hardhat's output for more details.`,
"The deployment transaction was mined but its receipt doesn't contain a contract address.",
},
},
NODE: {
INVALID_NETWORK_TYPE: {
number: 1400,
messageTemplate:
"The provided node network type {networkType} for network {networkName} is not recognized, only `edr` is supported.",
websiteTitle: "Invalid node network type",
websiteDescription: `The node only supports the 'edr' network type.`,
},
},
} as const;
3 changes: 3 additions & 0 deletions v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/debug": "^4.1.4",
"@types/node": "^20.14.9",
"@types/semver": "^7.5.8",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"eslint": "8.57.0",
Expand Down Expand Up @@ -96,9 +97,11 @@
"ethereum-cryptography": "^2.2.1",
"micro-eth-signer": "^0.13.0",
"p-map": "^7.0.2",
"raw-body": "^2.4.1",
"semver": "^7.6.3",
"solc": "^0.8.27",
"tsx": "^4.11.0",
"ws": "^8.18.0",
"zod": "^3.23.8"
}
}
3 changes: 3 additions & 0 deletions v-next/hardhat/src/internal/builtin-plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import artifacts from "./artifacts/index.js";
import clean from "./clean/index.js";
import console from "./console/index.js";
import networkManager from "./network-manager/index.js";
import node from "./node/index.js";
import run from "./run/index.js";
import solidity from "./solidity/index.js";
import solidityTest from "./solidity-test/index.js";
Expand All @@ -19,6 +20,7 @@ export type * from "./network-manager/index.js";
export type * from "./clean/index.js";
export type * from "./console/index.js";
export type * from "./run/index.js";
export type * from "./node/index.js";

// This array should be kept in order, respecting the dependencies between the
// plugins.
Expand All @@ -31,4 +33,5 @@ export const builtinPlugins: HardhatPlugin[] = [
clean,
console,
run,
node,
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
JsonRpcRequest,
JsonRpcResponse,
RequestArguments,
SuccessfulJsonRpcResponse,
} from "../../../types/providers.js";

import { HardhatError } from "@ignored/hardhat-vnext-errors";
Expand Down Expand Up @@ -56,6 +57,30 @@ export function parseJsonRpcResponse(
}
}

export function isJsonRpcRequest(payload: unknown): payload is JsonRpcRequest {
if (!isObject(payload)) {
return false;
}

if (payload.jsonrpc !== "2.0") {
return false;
}

if (typeof payload.id !== "number" && typeof payload.id !== "string") {
return false;
}

if (typeof payload.method !== "string") {
return false;
}

if (payload.params !== undefined && !Array.isArray(payload.params)) {
galargh marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

return true;
}

export function isJsonRpcResponse(
payload: unknown,
): payload is JsonRpcResponse {
Expand Down Expand Up @@ -96,6 +121,12 @@ export function isJsonRpcResponse(
return true;
}

export function isSuccessfulJsonRpcResponse(
payload: JsonRpcResponse,
): payload is SuccessfulJsonRpcResponse {
return "result" in payload;
}

export function isFailedJsonRpcResponse(
payload: JsonRpcResponse,
): payload is FailedJsonRpcResponse {
Expand Down
59 changes: 59 additions & 0 deletions v-next/hardhat/src/internal/builtin-plugins/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { HardhatPlugin } from "../../../types/plugins.js";

import { ArgumentType } from "../../../types/arguments.js";
import { task } from "../../core/config.js";

const hardhatPlugin: HardhatPlugin = {
id: "builtin:node",
tasks: [
task("node", "Starts a JSON-RPC server on top of Hardhat Network")
.addOption({
name: "hostname",
description:
"The host to which to bind to for new connections (Defaults to 127.0.0.1 running locally, and 0.0.0.0 in Docker)",
defaultValue: "",
})
.addOption({
name: "port",
description: "The port on which to listen for new connections",
type: ArgumentType.INT,
defaultValue: 8545,
})
.addOption({
name: "chainType",
description:
"The chain type to connect to. If not specified, the default chain type will be used.",
defaultValue: "",
})
.addOption({
name: "chainId",
description:
"The chain id to connect to. If not specified, the default chain id will be used.",
type: ArgumentType.INT,
defaultValue: -1,
})
.addOption({
name: "fork",
description: "The URL of the JSON-RPC server to fork from",
defaultValue: "",
})
.addOption({
name: "forkBlockNumber",
description: "The block number to fork from",
type: ArgumentType.INT,
defaultValue: -1,
})
.setAction(import.meta.resolve("./task-action.js"))
.build(),
],
dependencies: [
async () => {
const { default: networkManagerBuiltinPlugin } = await import(
"../network-manager/index.js"
);
return networkManagerBuiltinPlugin;
},
],
};

export default hardhatPlugin;
Loading
Loading