Skip to content

Commit d7b1481

Browse files
Saty248alcuadrado
authored andcommitted
adding test case for clearsnapshot on hardhat reset and formating the code
1 parent f068c99 commit d7b1481

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/hardhat-network-helpers/src/helpers/reset.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { deleteOnReset } from "../loadFixture";
21
import type { NumberLike } from "../types";
2+
import { clearSnapshots } from "../loadFixture";
3+
34
import { getHardhatProvider, toNumber } from "../utils";
45

56
export async function reset(
67
url?: string,
78
blockNumber?: NumberLike
89
): Promise<void> {
910
const provider = await getHardhatProvider();
10-
deleteOnReset();
11+
clearSnapshots();
1112
if (url === undefined) {
1213
await provider.request({
1314
method: "hardhat_reset",

packages/hardhat-network-helpers/src/loadFixture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ export async function loadFixture<T>(fixture: Fixture<T>): Promise<T> {
7070
}
7171

7272
// function to clear the snapshots array when hardhat_reset is called..
73-
export async function deleteOnReset(){
74-
snapshots=[];
73+
export async function clearSnapshots() {
74+
snapshots = [];
7575
}

packages/hardhat-network-helpers/test/helpers/reset.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { assert } from "chai";
2-
32
import * as hh from "../../src";
43
import { INFURA_URL } from "../setup";
54
import { useEnvironment } from "../test-utils";
6-
75
describe("resetWithoutFork", function () {
86
useEnvironment("simple");
97

@@ -56,3 +54,13 @@ describe("resetWithoutFork", function () {
5654
assert.equal(olderMainnetBlockNumber, mainnetBlockNumber - 1000);
5755
});
5856
});
57+
58+
describe("should clear snapshot upon reset", async function () {
59+
useEnvironment("simple");
60+
it("checks if the snapshot is cleared upon hardhat_reset", async function () {
61+
const snapshotBeforeReset = await hh.takeSnapshot();
62+
await hh.reset();
63+
const snapshotAfterReset = await hh.takeSnapshot();
64+
assert.equal(snapshotBeforeReset.snapshotId, snapshotAfterReset.snapshotId);
65+
});
66+
});

0 commit comments

Comments
 (0)