Skip to content

Commit a3d397d

Browse files
authored
Merge pull request #7041 from NomicFoundation/remove_hardhat_reset
Remove hardhat_reset usage from the codebase
2 parents e42af55 + 3010c73 commit a3d397d

File tree

9 files changed

+48
-311
lines changed

9 files changed

+48
-311
lines changed

.changeset/fast-actors-cough.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-network-helpers": patch
3+
"@nomicfoundation/hardhat-ethers": patch
4+
---
5+
6+
Remove `hardhat_reset` ([#6110](https://github.com/NomicFoundation/hardhat/issues/6110))

v-next/hardhat-ethers/test/hardhat-ethers-provider.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@ describe("hardhat ethers provider", () => {
222222
});
223223

224224
describe("getBalance", () => {
225-
beforeEach(async () => {
226-
await ethereumProvider.request({
227-
method: "hardhat_reset",
228-
});
229-
});
230-
231225
it("should return the balance of an address", async () => {
232226
const balance = await ethers.provider.getBalance(
233227
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
@@ -305,12 +299,6 @@ describe("hardhat ethers provider", () => {
305299
});
306300

307301
describe("getTransactionCount", () => {
308-
beforeEach(async () => {
309-
await ethereumProvider.request({
310-
method: "hardhat_reset",
311-
});
312-
});
313-
314302
it("should return the transaction count of an address", async () => {
315303
const balance = await ethers.provider.getTransactionCount(
316304
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
@@ -829,7 +817,6 @@ describe("hardhat ethers provider", () => {
829817

830818
describe("broadcastTransaction", () => {
831819
it("should send a raw transaction", async () => {
832-
await ethers.provider.send("hardhat_reset");
833820
// private key of the first unlocked account
834821
const wallet = new ethers.Wallet(
835822
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
@@ -852,7 +839,6 @@ describe("hardhat ethers provider", () => {
852839

853840
describe("getBlock", () => {
854841
it("should accept latest and earliest block tags", async () => {
855-
await ethers.provider.send("hardhat_reset");
856842
await ethers.provider.send("hardhat_mine");
857843
await ethers.provider.send("hardhat_mine");
858844
await ethers.provider.send("hardhat_mine");
@@ -867,7 +853,6 @@ describe("hardhat ethers provider", () => {
867853
});
868854

869855
it("should accept numbers", async () => {
870-
await ethers.provider.send("hardhat_reset");
871856
await ethers.provider.send("hardhat_mine");
872857
await ethers.provider.send("hardhat_mine");
873858
await ethers.provider.send("hardhat_mine");
@@ -882,8 +867,6 @@ describe("hardhat ethers provider", () => {
882867
});
883868

884869
it("should accept block hashes", async () => {
885-
await ethers.provider.send("hardhat_reset");
886-
887870
const blockByNumber = await ethers.provider.getBlock(0);
888871
assertIsNotNull(blockByNumber);
889872
assertIsNotNull(blockByNumber.hash);

v-next/hardhat-ethers/test/hardhat-ethers-signer.ts

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ExampleContract } from "./helpers/example-contracts.js";
22
import type { HardhatEthers } from "../src/types.js";
33
import type { AuthorizationRequest } from "ethers";
4-
import type { EthereumProvider } from "hardhat/types/providers";
54

65
import assert from "node:assert/strict";
76
import { beforeEach, describe, it } from "node:test";
@@ -40,12 +39,7 @@ describe("hardhat ethers signer", () => {
4039
passphrase: "",
4140
};
4241

43-
async function testStringPrivateKeys(
44-
hhEthers: HardhatEthers,
45-
hhProvider: EthereumProvider,
46-
) {
47-
await hhProvider.request({ method: "hardhat_reset" });
48-
42+
async function testStringPrivateKeys(hhEthers: HardhatEthers) {
4943
const signer = await hhEthers.provider.getSigner(0);
5044
const receiver = await hhEthers.provider.getSigner(1);
5145

@@ -68,12 +62,7 @@ describe("hardhat ethers signer", () => {
6862
assert.equal(res.signature.networkV, null);
6963
}
7064

71-
async function testHdAccounts(
72-
hhEthers: HardhatEthers,
73-
hhProvider: EthereumProvider,
74-
) {
75-
await hhProvider.request({ method: "hardhat_reset" });
76-
65+
async function testHdAccounts(hhEthers: HardhatEthers) {
7766
const signer = await hhEthers.provider.getSigner(0);
7867
const receiver = await hhEthers.provider.getSigner(1);
7968

@@ -122,66 +111,62 @@ describe("hardhat ethers signer", () => {
122111
});
123112

124113
it(`should work with array of private keys as strings`, async () => {
125-
const { ethers: hhEthers, provider: hhProvider } =
126-
await initializeTestEthers([], {
127-
networks: {
128-
localhost: {
129-
type: "http",
130-
url: LOCALHOST_URL,
131-
accounts: [TEST_P_KEY_1, TEST_P_KEY_2],
132-
},
114+
const { ethers: hhEthers } = await initializeTestEthers([], {
115+
networks: {
116+
localhost: {
117+
type: "http",
118+
url: LOCALHOST_URL,
119+
accounts: [TEST_P_KEY_1, TEST_P_KEY_2],
133120
},
134-
});
121+
},
122+
});
135123

136-
await testStringPrivateKeys(hhEthers, hhProvider);
124+
await testStringPrivateKeys(hhEthers);
137125
});
138126

139127
it(`should work with hd accounts`, async () => {
140-
const { ethers: hhEthers, provider: hhProvider } =
141-
await initializeTestEthers([], {
142-
networks: {
143-
localhost: {
144-
type: "http",
145-
url: LOCALHOST_URL,
146-
accounts: HD_ACCOUNTS,
147-
},
128+
const { ethers: hhEthers } = await initializeTestEthers([], {
129+
networks: {
130+
localhost: {
131+
type: "http",
132+
url: LOCALHOST_URL,
133+
accounts: HD_ACCOUNTS,
148134
},
149-
});
135+
},
136+
});
150137

151-
await testHdAccounts(hhEthers, hhProvider);
138+
await testHdAccounts(hhEthers);
152139
});
153140
});
154141

155142
describe("hardhat accounts", () => {
156143
it(`should work with an array that has private keys as strings`, async () => {
157-
const { ethers: hhEthers, provider: hhProvider } =
158-
await initializeTestEthers([], {
159-
networks: {
160-
default: {
161-
type: "edr",
162-
accounts: [
163-
{ balance: "1000000000000000000", privateKey: TEST_P_KEY_1 },
164-
{ balance: "1000000000000000000", privateKey: TEST_P_KEY_2 },
165-
],
166-
},
144+
const { ethers: hhEthers } = await initializeTestEthers([], {
145+
networks: {
146+
default: {
147+
type: "edr",
148+
accounts: [
149+
{ balance: "1000000000000000000", privateKey: TEST_P_KEY_1 },
150+
{ balance: "1000000000000000000", privateKey: TEST_P_KEY_2 },
151+
],
167152
},
168-
});
153+
},
154+
});
169155

170-
await testStringPrivateKeys(hhEthers, hhProvider);
156+
await testStringPrivateKeys(hhEthers);
171157
});
172158

173159
it(`should work`, async () => {
174-
const { ethers: hhEthers, provider: hhProvider } =
175-
await initializeTestEthers([], {
176-
networks: {
177-
default: {
178-
type: "edr",
179-
accounts: HD_ACCOUNTS,
180-
},
160+
const { ethers: hhEthers } = await initializeTestEthers([], {
161+
networks: {
162+
default: {
163+
type: "edr",
164+
accounts: HD_ACCOUNTS,
181165
},
182-
});
166+
},
167+
});
183168

184-
await testHdAccounts(hhEthers, hhProvider);
169+
await testHdAccounts(hhEthers);
185170
});
186171
});
187172
});

v-next/hardhat-ethers/test/plugin-functionalities.ts

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -967,107 +967,6 @@ describe("Ethers plugin", () => {
967967
// });
968968
});
969969

970-
describe("hardhat_reset", () => {
971-
it("should return the correct block number after a hardhat_reset", async () => {
972-
let blockNumber = await ethers.provider.getBlockNumber();
973-
assert.equal(blockNumber.toString(), "0");
974-
975-
await ethers.provider.send("evm_mine", []);
976-
await ethers.provider.send("evm_mine", []);
977-
blockNumber = await ethers.provider.getBlockNumber();
978-
assert.equal(blockNumber.toString(), "2");
979-
980-
await ethers.provider.send("hardhat_reset", []);
981-
blockNumber = await ethers.provider.getBlockNumber();
982-
assert.equal(blockNumber.toString(), "0");
983-
});
984-
985-
it("should return the correct block after a hardhat_reset", async () => {
986-
await ethers.provider.send("evm_mine", []);
987-
988-
let blockOne = await ethers.provider.getBlock(1);
989-
let blockTwo = await ethers.provider.getBlock(2);
990-
assert.notEqual(blockOne, null);
991-
assert.equal(blockTwo, null);
992-
993-
await ethers.provider.send("hardhat_reset", []);
994-
995-
blockOne = await ethers.provider.getBlock(1);
996-
blockTwo = await ethers.provider.getBlock(2);
997-
assert.equal(blockOne, null);
998-
assert.equal(blockTwo, null);
999-
});
1000-
1001-
it("should return the correct nonce after a hardhat_reset", async () => {
1002-
const [sig] = await ethers.getSigners();
1003-
1004-
let nonce = await ethers.provider.getTransactionCount(sig.address);
1005-
1006-
assert.equal(nonce, 0);
1007-
1008-
const response = await sig.sendTransaction({
1009-
from: sig.address,
1010-
to: ethers.ZeroAddress,
1011-
value: "0x1",
1012-
});
1013-
await response.wait();
1014-
1015-
nonce = await ethers.provider.getTransactionCount(sig.address);
1016-
assert.equal(nonce, 1);
1017-
1018-
await ethers.provider.send("hardhat_reset", []);
1019-
nonce = await ethers.provider.getTransactionCount(sig.address);
1020-
assert.equal(nonce, 0);
1021-
});
1022-
1023-
it("should return the correct balance after a hardhat_reset", async () => {
1024-
const [sig] = await ethers.getSigners();
1025-
1026-
let balance = await ethers.provider.getBalance(sig.address);
1027-
1028-
assert.equal(balance.toString(), "10000000000000000000000");
1029-
1030-
const response = await sig.sendTransaction({
1031-
from: sig.address,
1032-
to: ethers.ZeroAddress,
1033-
gasPrice: 8e9,
1034-
});
1035-
await response.wait();
1036-
1037-
balance = await ethers.provider.getBalance(sig.address);
1038-
assert.equal(balance.toString(), "9999999832000000000000");
1039-
1040-
await ethers.provider.send("hardhat_reset", []);
1041-
balance = await ethers.provider.getBalance(sig.address);
1042-
assert.equal(balance.toString(), "10000000000000000000000");
1043-
});
1044-
1045-
it("should return the correct code after a hardhat_reset", async () => {
1046-
const [sig] = await ethers.getSigners();
1047-
1048-
const Greeter = await ethers.getContractFactory("Greeter");
1049-
const tx = await Greeter.getDeployTransaction();
1050-
1051-
const response = await sig.sendTransaction(tx);
1052-
1053-
const receipt = await response.wait();
1054-
if (receipt === null) {
1055-
assert.fail("receipt shoudn't be null");
1056-
}
1057-
if (receipt.contractAddress === null) {
1058-
assert.fail("receipt.contractAddress shoudn't be null");
1059-
}
1060-
1061-
let code = await ethers.provider.getCode(receipt.contractAddress);
1062-
assert.equal(code.length, 1880);
1063-
1064-
await ethers.provider.send("hardhat_reset", []);
1065-
1066-
code = await ethers.provider.getCode(receipt.contractAddress);
1067-
assert.equal(code.length, 2);
1068-
});
1069-
});
1070-
1071970
describe("evm_revert", () => {
1072971
it("should return the correct block number after a evm_revert", async () => {
1073972
const snapshotId = await ethers.provider.send("evm_snapshot", []);

v-next/hardhat-network-helpers/src/internal/network-helpers/helpers/reset.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

v-next/hardhat-network-helpers/src/internal/network-helpers/network-helpers.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { impersonateAccount } from "./helpers/impersonate-account.js";
1919
import { loadFixture } from "./helpers/load-fixture.js";
2020
import { mineUpTo } from "./helpers/mine-up-to.js";
2121
import { mine } from "./helpers/mine.js";
22-
import { reset } from "./helpers/reset.js";
2322
import { setBalance } from "./helpers/set-balance.js";
2423
import { setBlockGasLimit } from "./helpers/set-block-gas-limit.js";
2524
import { setCode } from "./helpers/set-code.js";
@@ -101,11 +100,6 @@ export class NetworkHelpers implements NetworkHelpersI {
101100
return mineUpTo(this.#provider, blockNumber, this.time);
102101
}
103102

104-
public async reset(url?: string, blockNumber?: NumberLike): Promise<void> {
105-
await this.throwIfNotDevelopmentNetwork();
106-
return reset(this, this.#provider, url, blockNumber);
107-
}
108-
109103
public async setBalance(address: string, balance: NumberLike): Promise<void> {
110104
await this.throwIfNotDevelopmentNetwork();
111105
return setBalance(this.#provider, address, balance);

v-next/hardhat-network-helpers/src/types.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ export interface NetworkHelpers {
107107
*/
108108
mineUpTo(blockNumber: NumberLike): Promise<void>;
109109

110-
/**
111-
* Resets the Hardhat Network to its initial state or forks from a given URL and block number.
112-
*
113-
* @param url Optional JSON-RPC URL to fork from.
114-
* @param blockNumber Optional block number to fork from.
115-
* @returns A promise that resolves once the reset operation is completed.
116-
*
117-
* @example
118-
* const { networkHelpers } = await hre.network.connect();
119-
* await networkHelpers.reset(); // Resets the network
120-
* await networkHelpers.reset("https://mainnet.infura.io", 123456); // Resets and forks from a specific block
121-
*/
122-
reset(url?: string, blockNumber?: NumberLike): Promise<void>;
123-
124110
/**
125111
* Sets the balance for the given address.
126112
*

0 commit comments

Comments
 (0)