Skip to content

Commit 57de046

Browse files
committed
swap polkavm for polkadot
1 parent 08dc408 commit 57de046

File tree

9 files changed

+54
-54
lines changed

9 files changed

+54
-54
lines changed

packages/hardhat-polkadot-node/src/constants.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export const PLUGIN_NAME = "hardhat-revive-node"
1+
export const PLUGIN_NAME = "hardhat-polkadot-node"
22

3-
export const TASK_NODE_POLKAVM = "node-polkavm"
4-
export const TASK_NODE_POLKAVM_CREATE_SERVER = "node-polkavm:create-server"
5-
export const TASK_NODE_POLKAVM_CREATE_ETH_ADAPTER = "node-polkavm:create-eth-adapter"
6-
export const TASK_RUN_POLKAVM_NODE_IN_SEPARATE_PROCESS = "node-polkavm:run-in-separate-process"
3+
export const TASK_NODE_POLKADOT = "node-polkadot"
4+
export const TASK_NODE_POLKADOT_CREATE_SERVER = "node-polkadot:create-server"
5+
export const TASK_NODE_POLKADOT_CREATE_ETH_ADAPTER = "node-polkadot:create-eth-adapter"
6+
export const TASK_RUN_POLKADOT_NODE_IN_SEPARATE_PROCESS = "node-polkadot:run-in-separate-process"
77

88
export const PROCESS_TERMINATION_SIGNALS = ["SIGINT", "SIGTERM", "SIGKILL"]
99

@@ -13,12 +13,12 @@ export const MAX_PORT_ATTEMPTS = 10
1313
export const PORT_CHECK_DELAY = 500
1414
export const RPC_ENDPOINT_PATH = "eth_chainId"
1515

16-
export const POLKAVM_TEST_NODE_NETWORK_NAME = "Kitchensink"
16+
export const POLKADOT_TEST_NODE_NETWORK_NAME = "Kitchensink"
1717

1818
export const BASE_URL = `http://127.0.0.1`
1919
export const NETWORK_ACCOUNTS = {
2020
REMOTE: "remote",
21-
POLKAVM: [
21+
POLKADOT: [
2222
"0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133",
2323
"0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5b0000a702133",
2424
"0x5fb92c48bebcd6e98884f76de468fa3f6278f880713595d45af5b0000a702133",

packages/hardhat-polkadot-node/src/core/global-interceptor.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ import { HardhatRuntimeEnvironment, RunSuperFunction, TaskArguments } from "hard
22
import { GlobalWithHardhatContext } from "hardhat/src/internal/context"
33
import { HARDHAT_NETWORK_NAME } from "hardhat/plugins"
44
import { configureNetwork, startServer, waitForNodeToBeReady } from "../utils"
5-
import { PolkaVMTasksWithWrappedNode } from "./global-task"
5+
import { PolkadotTasksWithWrappedNode } from "./global-task"
66
import { Environment } from "hardhat/internal/core/runtime-environment"
77

88
export function interceptAndWrapTasksWithNode() {
9-
const polkaVMGlobal = global as PolkaVMTasksWithWrappedNode & GlobalWithHardhatContext
10-
const taskMap = polkaVMGlobal.__hardhatContext.tasksDSL.getTaskDefinitions()
9+
const polkadotGlobal = global as PolkadotTasksWithWrappedNode & GlobalWithHardhatContext
10+
const taskMap = polkadotGlobal.__hardhatContext.tasksDSL.getTaskDefinitions()
1111

12-
if (!polkaVMGlobal._polkaVMTasksForWrapping) {
12+
if (!polkadotGlobal._polkadotTasksForWrapping) {
1313
return
1414
}
1515

16-
polkaVMGlobal._polkaVMTasksForWrapping.taskNames.forEach((taskName) => {
16+
polkadotGlobal._polkadotTasksForWrapping.taskNames.forEach((taskName) => {
1717
const foundTask = taskMap[taskName]
1818

1919
if (!foundTask) {
2020
return
2121
}
2222

2323
if (foundTask.isSubtask) {
24-
polkaVMGlobal.__hardhatContext.tasksDSL.subtask(
24+
polkadotGlobal.__hardhatContext.tasksDSL.subtask(
2525
foundTask.name,
2626
foundTask.description,
2727
wrapTaskWithNode,
2828
)
2929
}
3030

31-
polkaVMGlobal.__hardhatContext.tasksDSL.task(
31+
polkadotGlobal.__hardhatContext.tasksDSL.task(
3232
foundTask.name,
3333
foundTask.description,
3434
wrapTaskWithNode,
@@ -44,7 +44,7 @@ async function wrapTaskWithNode(
4444
if (env.network.polkavm !== true || env.network.name !== HARDHAT_NETWORK_NAME) {
4545
return await runSuper(taskArgs)
4646
}
47-
const polkaVMGlobal = global as PolkaVMTasksWithWrappedNode;
47+
const polkadotGlobal = global as PolkadotTasksWithWrappedNode;
4848

4949
const { commandArgs, server, port } = await startServer({
5050
forking: env.config.networks.hardhat.forking,
@@ -58,10 +58,10 @@ async function wrapTaskWithNode(
5858
const oldNetwork = env.network;
5959
await configureNetwork(env.config, env.network, port);
6060
(env as unknown as Environment).injectToGlobal();
61-
polkaVMGlobal._polkaVMNodeNetwork = env.network;
61+
polkadotGlobal._polkadotNodeNetwork = env.network;
6262
const result = await runSuper(taskArgs);
6363
(env as unknown as Environment).network = oldNetwork;
64-
delete polkaVMGlobal._polkaVMNodeNetwork;
64+
delete polkadotGlobal._polkadotNodeNetwork;
6565
(env as unknown as Environment).injectToGlobal();
6666
return result
6767
} finally {

packages/hardhat-polkadot-node/src/core/global-task.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Network } from "hardhat/types"
22

3-
export type PolkaVMTasksWithWrappedNode = typeof global & {
4-
_polkaVMTasksForWrapping: PolkaVMTasksForWrapping
5-
_polkaVMNodeNetwork?: Network
3+
export type PolkadotTasksWithWrappedNode = typeof global & {
4+
_polkadotTasksForWrapping: PolkadotTasksForWrapping
5+
_polkadotNodeNetwork?: Network
66
}
77

8-
export class PolkaVMTasksForWrapping {
8+
export class PolkadotTasksForWrapping {
99
public taskNames: string[] = []
1010

1111
constructor() {

packages/hardhat-polkadot-node/src/core/register.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { LazyInitializationProviderAdapter } from "hardhat/internal/core/provide
1414
import { log } from "console"
1515
import { createProvider } from "hardhat/internal/core/providers/construction"
1616
import { Artifacts } from "hardhat/internal/artifacts"
17-
import { BASE_URL, POLKAVM_TEST_NODE_NETWORK_NAME } from "../constants"
17+
import { BASE_URL, POLKADOT_TEST_NODE_NETWORK_NAME } from "../constants"
1818
import { getNetworkConfig } from "../utils"
1919
import "source-map-support/register";
2020

@@ -48,9 +48,9 @@ if (!HardhatContext.isCreated()) {
4848
ctx.providerExtenders,
4949
)
5050

51-
const polkaVMNodePort = process.env.PolkaVMNodePort
52-
const url = `${BASE_URL}:${polkaVMNodePort}`
53-
const networkName = POLKAVM_TEST_NODE_NETWORK_NAME
51+
const polkadotNodePort = process.env.polkadotNodePort
52+
const url = `${BASE_URL}:${polkadotNodePort}`
53+
const networkName = POLKADOT_TEST_NODE_NETWORK_NAME
5454

5555
env.network.name = networkName
5656
Object.assign(env.network.config, getNetworkConfig(url))

packages/hardhat-polkadot-node/src/core/script-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function runScript(
2525
await server.listen(commandArgs.nodeCommands, commandArgs.adapterCommands, false)
2626
await waitForNodeToBeReady(port)
2727

28-
const envVars = { ...process.env, ...extraEnvVars, PolkaVMNodePort: port.toString() }
28+
const envVars = { ...process.env, ...extraEnvVars, polkadotNodePort: port.toString() }
2929

3030
return new Promise((resolve, reject) => {
3131
const childProcess = fork(scriptPath, scriptArgs, {

packages/hardhat-polkadot-node/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HardhatPluginError } from "hardhat/plugins"
22
import { PLUGIN_NAME } from "./constants"
33

4-
export class PolkaVMNodePluginError extends HardhatPluginError {
4+
export class PolkadotNodePluginError extends HardhatPluginError {
55
constructor(message: string, parentError?: Error) {
66
super(PLUGIN_NAME, message, parentError)
77
}

packages/hardhat-polkadot-node/src/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
NODE_START_PORT,
1717
ETH_RPC_ADAPTER_START_PORT,
1818
MAX_PORT_ATTEMPTS,
19-
TASK_NODE_POLKAVM,
20-
TASK_NODE_POLKAVM_CREATE_SERVER,
21-
TASK_RUN_POLKAVM_NODE_IN_SEPARATE_PROCESS,
19+
TASK_NODE_POLKADOT,
20+
TASK_NODE_POLKADOT_CREATE_SERVER,
21+
TASK_RUN_POLKADOT_NODE_IN_SEPARATE_PROCESS,
2222
} from "./constants"
2323
import { JsonRpcServer } from "./server"
2424
import {
@@ -28,7 +28,7 @@ import {
2828
getAvailablePort,
2929
waitForNodeToBeReady,
3030
} from "./utils"
31-
import { PolkaVMNodePluginError } from "./errors"
31+
import { PolkadotNodePluginError } from "./errors"
3232
import { interceptAndWrapTasksWithNode } from "./core/global-interceptor"
3333
import { runScriptWithHardhat } from "./core/script-runner"
3434
import { AdapterConfig, NodeConfig, RpcServer } from "./types"
@@ -52,23 +52,23 @@ task(TASK_RUN).setAction(async (args, hre, runSuper) => {
5252
);
5353
});
5454

55-
subtask(TASK_NODE_POLKAVM_CREATE_SERVER, 'Creates a JSON-RPC server for PolkaVM node')
55+
subtask(TASK_NODE_POLKADOT_CREATE_SERVER, 'Creates a JSON-RPC server for Polkadot node')
5656
.addOptionalParam('nodePath', 'Path to the node binary file', undefined, types.string)
5757
.addOptionalParam('adapterPath', 'Path to the Eth Rpc Adapter binary file', undefined, types.string)
5858
.setAction(async ({ nodePath, adapterPath }: { nodePath: string; adapterPath: string }) => {
5959
const server: JsonRpcServer = new JsonRpcServer(nodePath, adapterPath);
6060
return server;
6161
});
6262

63-
task(TASK_NODE, 'Start a PolkaVM Node').setAction(async (args: TaskArguments, { network, run }, runSuper) => {
63+
task(TASK_NODE, 'Start a Polkadot Node').setAction(async (args: TaskArguments, { network, run }, runSuper) => {
6464
if (network.polkavm !== true || network.name !== HARDHAT_NETWORK_NAME) {
6565
return await runSuper();
6666
}
6767

68-
await run(TASK_NODE_POLKAVM, args);
68+
await run(TASK_NODE_POLKADOT, args);
6969
});
7070

71-
task(TASK_NODE_POLKAVM, 'Starts a JSON-RPC server for PolkaVM node')
71+
task(TASK_NODE_POLKADOT, 'Starts a JSON-RPC server for Polkadot node')
7272
.addOptionalParam('nodeBinaryPath', 'Path to the substrate node binary', undefined, types.string)
7373
.addOptionalParam('rpcPort', 'Port where the node will listen on - default: 8000', undefined, types.int)
7474
.addOptionalParam('adapterBinaryPath', 'Path to the eth-rpc-adapter binary', undefined, types.string)
@@ -133,7 +133,7 @@ task(TASK_NODE_POLKAVM, 'Starts a JSON-RPC server for PolkaVM node')
133133
? adapterBinaryPath
134134
: userConfig.networks?.hardhat?.adapterConfig?.adapterBinaryPath;
135135

136-
const server: RpcServer = await run(TASK_NODE_POLKAVM_CREATE_SERVER, {
136+
const server: RpcServer = await run(TASK_NODE_POLKADOT_CREATE_SERVER, {
137137
nodePath,
138138
adapterPath,
139139
})
@@ -142,21 +142,21 @@ task(TASK_NODE_POLKAVM, 'Starts a JSON-RPC server for PolkaVM node')
142142
await server.listen(commandArgs.nodeCommands, commandArgs.adapterCommands)
143143
// eslint-disable-next-line @typescript-eslint/no-explicit-any
144144
} catch (error: any) {
145-
throw new PolkaVMNodePluginError(`Failed when running node: ${error.message}`)
145+
throw new PolkadotNodePluginError(`Failed when running node: ${error.message}`)
146146
}
147147
},
148148
)
149149

150150
subtask(
151-
TASK_RUN_POLKAVM_NODE_IN_SEPARATE_PROCESS,
152-
"Runs a Hardhat PolkaVM task in a separate process.",
151+
TASK_RUN_POLKADOT_NODE_IN_SEPARATE_PROCESS,
152+
"Runs a Hardhat Polkadot task in a separate process.",
153153
)
154-
.addVariadicPositionalParam("taskArgs", "Arguments for the Hardhat PolkaVM task.")
154+
.addVariadicPositionalParam("taskArgs", "Arguments for the Hardhat Polkadot task.")
155155
.setAction(async ({ taskArgs = [] }, _hre) => {
156156
const currentPort = await getAvailablePort(ETH_RPC_ADAPTER_START_PORT, MAX_PORT_ATTEMPTS)
157157
const adjustedArgs = adjustTaskArgsForPort(taskArgs, currentPort)
158158

159-
const taskProcess = spawn("npx", ["hardhat", TASK_NODE_POLKAVM, ...adjustedArgs], {
159+
const taskProcess = spawn("npx", ["hardhat", TASK_NODE_POLKADOT, ...adjustedArgs], {
160160
detached: true,
161161
})
162162

@@ -256,7 +256,7 @@ task(
256256
return testFailures
257257
// eslint-disable-next-line @typescript-eslint/no-explicit-any
258258
} catch (error: any) {
259-
throw new PolkaVMNodePluginError(`Failed when running node: ${error.message}`)
259+
throw new PolkadotNodePluginError(`Failed when running node: ${error.message}`)
260260
}
261261
},
262262
)

packages/hardhat-polkadot-node/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chalk from "chalk"
33

44
import { NODE_START_PORT, ETH_RPC_ADAPTER_START_PORT } from "./constants"
55
import { RpcServer } from "./types"
6-
import { PolkaVMNodePluginError } from "./errors"
6+
import { PolkadotNodePluginError } from "./errors"
77

88
export class JsonRpcServer implements RpcServer {
99
private serverProcess: ChildProcess | null = null
@@ -46,7 +46,7 @@ export class JsonRpcServer implements RpcServer {
4646
const adapterCommand = this.adapterBinaryPath
4747

4848
if (!adapterCommand) {
49-
throw new PolkaVMNodePluginError('A path for the Eth RPC Adapter must be provided.');
49+
throw new PolkadotNodePluginError('A path for the Eth RPC Adapter must be provided.');
5050
}
5151

5252
const adapterPortArg = adapterArgs.find((arg) => arg.startsWith('--port='));

packages/hardhat-polkadot-node/src/utils.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
NETWORK_GAS_PRICE,
1313
NODE_START_PORT,
1414
ETH_RPC_ADAPTER_START_PORT,
15-
POLKAVM_TEST_NODE_NETWORK_NAME,
15+
POLKADOT_TEST_NODE_NETWORK_NAME,
1616
RPC_ENDPOINT_PATH,
1717
} from './constants';
18-
import { PolkaVMNodePluginError } from './errors';
18+
import { PolkadotNodePluginError } from './errors';
1919
import { CliCommands, CommandArguments, SplitCommands } from './types';
2020
import { JsonRpcServer } from './server';
2121

@@ -45,7 +45,7 @@ export function constructCommandArgs(args?: CommandArguments, cliCommands?: CliC
4545
if (cliCommands.adapterPort && cliCommands.adapterPort !== cliCommands.rpcPort) {
4646
adapterCommands.push(`--rpc-port=${cliCommands.adapterPort}`);
4747
} else if (cliCommands.adapterPort && cliCommands.adapterPort === cliCommands.rpcPort) {
48-
throw new PolkaVMNodePluginError('Adapter and node cannot share the same port.');
48+
throw new PolkadotNodePluginError('Adapter and node cannot share the same port.');
4949
}
5050

5151
if (cliCommands.buildBlockMode && cliCommands.fork) {
@@ -69,7 +69,7 @@ export function constructCommandArgs(args?: CommandArguments, cliCommands?: CliC
6969
} else if (args.nodeCommands?.nodeBinaryPath && !cliCommands?.nodeBinaryPath) {
7070
nodeCommands.push(args.nodeCommands?.nodeBinaryPath);
7171
} else {
72-
throw new PolkaVMNodePluginError('Binary path not specified.');
72+
throw new PolkadotNodePluginError('Binary path not specified.');
7373
}
7474

7575
if (args.nodeCommands?.rpcPort && !cliCommands?.rpcPort) {
@@ -88,7 +88,7 @@ export function constructCommandArgs(args?: CommandArguments, cliCommands?: CliC
8888
args.adapterCommands?.adapterPort &&
8989
args.adapterCommands?.adapterPort === args.nodeCommands?.rpcPort
9090
) {
91-
throw new PolkaVMNodePluginError('Adapter and node cannot share the same port.');
91+
throw new PolkadotNodePluginError('Adapter and node cannot share the same port.');
9292
}
9393

9494
if (args.adapterCommands?.buildBlockMode && !!cliCommands?.buildBlockMode) {
@@ -169,7 +169,7 @@ export async function waitForNodeToBeReady(
169169
waitTime = Math.min(waitTime * backoffFactor, maxWaitTime);
170170
}
171171

172-
throw new PolkaVMNodePluginError("Server didn't respond after multiple attempts");
172+
throw new PolkadotNodePluginError("Server didn't respond after multiple attempts");
173173
}
174174

175175
export async function getAvailablePort(startPort: number, maxAttempts: number): Promise<number> {
@@ -180,7 +180,7 @@ export async function getAvailablePort(startPort: number, maxAttempts: number):
180180
}
181181
currentPort++;
182182
}
183-
throw new PolkaVMNodePluginError("Couldn't find an available port after several attempts");
183+
throw new PolkadotNodePluginError("Couldn't find an available port after several attempts");
184184
}
185185

186186
export function adjustTaskArgsForPort(taskArgs: string[], currentPort: number): string[] {
@@ -190,7 +190,7 @@ export function adjustTaskArgsForPort(taskArgs: string[], currentPort: number):
190190
if (portArgIndex + 1 < taskArgs.length) {
191191
taskArgs[portArgIndex + 1] = `${currentPort}`;
192192
} else {
193-
throw new PolkaVMNodePluginError(
193+
throw new PolkadotNodePluginError(
194194
'Invalid task arguments: --port provided without a following port number.',
195195
);
196196
}
@@ -202,7 +202,7 @@ export function adjustTaskArgsForPort(taskArgs: string[], currentPort: number):
202202

203203
export function getNetworkConfig(url: string, chainId?: number) {
204204
return {
205-
accounts: NETWORK_ACCOUNTS.POLKAVM,
205+
accounts: NETWORK_ACCOUNTS.POLKADOT,
206206
gas: NETWORK_GAS.AUTO,
207207
gasPrice: NETWORK_GAS_PRICE.AUTO,
208208
gasMultiplier: 1,
@@ -230,7 +230,7 @@ export async function configureNetwork(config: HardhatConfig, network: any, port
230230
// If it fails, it will just try again
231231
}
232232

233-
network.name = POLKAVM_TEST_NODE_NETWORK_NAME;
233+
network.name = POLKADOT_TEST_NODE_NETWORK_NAME;
234234
network.config = getNetworkConfig(url, chainId);
235235
config.networks[network.name] = network.config;
236236
network.provider = await createProvider(config, network.name);

0 commit comments

Comments
 (0)