Skip to content

Commit 6474989

Browse files
committed
feat: Emit Edr network events
1 parent 72e4a2d commit 6474989

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import chalk from "chalk";
3838
import debug from "debug";
3939

4040
import {
41-
HARDHAT_NETWORK_RESET_EVENT,
42-
HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT,
41+
EDR_NETWORK_RESET_EVENT,
42+
EDR_NETWORK_REVERT_SNAPSHOT_EVENT,
4343
} from "../../../constants.js";
4444
import { DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS } from "../accounts/constants.js";
4545
import { BaseProvider } from "../base-provider.js";
@@ -271,9 +271,9 @@ export class EdrProvider extends BaseProvider {
271271
}
272272

273273
if (args.method === "hardhat_reset") {
274-
this.emit(HARDHAT_NETWORK_RESET_EVENT);
274+
this.emit(EDR_NETWORK_RESET_EVENT);
275275
} else if (args.method === "evm_revert") {
276-
this.emit(HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT);
276+
this.emit(EDR_NETWORK_REVERT_SNAPSHOT_EVENT);
277277
}
278278

279279
// this can only happen if a wrapper doesn't call the default

v-next/hardhat/src/internal/builtin-plugins/network-manager/http-provider.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
ResponseStatusCodeError,
2323
} from "@ignored/hardhat-vnext-utils/request";
2424

25+
import {
26+
EDR_NETWORK_RESET_EVENT,
27+
EDR_NETWORK_REVERT_SNAPSHOT_EVENT,
28+
} from "../../constants.js";
2529
import { getHardhatVersion } from "../../utils/package.js";
2630

2731
import { BaseProvider } from "./base-provider.js";
@@ -141,7 +145,12 @@ export class HttpProvider extends BaseProvider {
141145
throw error;
142146
}
143147

144-
// TODO: emit hardhat network events (hardhat_reset, evm_revert)
148+
if (jsonRpcRequest.method === "hardhat_reset") {
149+
this.emit(EDR_NETWORK_RESET_EVENT);
150+
}
151+
if (jsonRpcRequest.method === "evm_revert") {
152+
this.emit(EDR_NETWORK_REVERT_SNAPSHOT_EVENT);
153+
}
145154

146155
return jsonRpcResponse.result;
147156
}

v-next/hardhat/src/internal/constants.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ export const HARDHAT_PACKAGE_NAME = "hardhat";
22
export const HARDHAT_NAME = "Hardhat";
33
export const HARDHAT_WEBSITE_URL = "https://hardhat.org/";
44

5-
export const HARDHAT_NETWORK_RESET_EVENT = "hardhatNetworkReset";
6-
export const HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT =
7-
"hardhatNetworkRevertSnapshot";
5+
export const EDR_NETWORK_RESET_EVENT = "hardhatNetworkReset";
6+
export const EDR_NETWORK_REVERT_SNAPSHOT_EVENT = "hardhatNetworkRevertSnapshot";
87

98
export const GENERIC_CHAIN_TYPE = "generic";
109
export const L1_CHAIN_TYPE = "l1";

0 commit comments

Comments
 (0)