Skip to content

Commit

Permalink
feat: port the node task to hardhat v3
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Dec 6, 2024
1 parent 7f07720 commit 94da3a2
Show file tree
Hide file tree
Showing 10 changed files with 802 additions and 16 deletions.
58 changes: 43 additions & 15 deletions pnpm-lock.yaml

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

12 changes: 11 additions & 1 deletion 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 @@ -135,7 +136,7 @@ Please double check whether you have multiple versions of the same plugin instal
ENV_VAR_NOT_FOUND: {
number: 7,
messageTemplate: `Configuration Variable '{name}' not found.
You can define it using a plugin like hardhat-keystore, or set it as an environment variable.`,
websiteTitle: "Configuration variable not found",
websiteDescription: `A configuration variable was expected to be set as an environment variable, but it wasn't.`,
Expand Down Expand Up @@ -1224,4 +1225,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.12.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)) {
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
Loading

0 comments on commit 94da3a2

Please sign in to comment.