Skip to content

Commit 67ad197

Browse files
committed
fix: only set snapshot cheatcodes written flag when cheatcodes exist
1 parent ff5b4e0 commit 67ad197

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

v-next/hardhat/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ export async function checkSnapshotCheatcodes(
268268
previousSnapshotCheatcodes = await readSnapshotCheatcodes(basePath);
269269
} catch (error) {
270270
if (error instanceof FileNotFoundError) {
271-
await writeSnapshotCheatcodes(basePath, snapshotCheatcodes);
271+
// Only write if there are cheatcodes to save
272+
const written = snapshotCheatcodes.size > 0;
273+
if (written) {
274+
await writeSnapshotCheatcodes(basePath, snapshotCheatcodes);
275+
}
272276

273277
return {
274278
passed: true,
@@ -277,7 +281,7 @@ export async function checkSnapshotCheatcodes(
277281
removed: [],
278282
changed: [],
279283
},
280-
written: true,
284+
written,
281285
};
282286
}
283287

v-next/hardhat/test/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,25 @@ describe("solidity-test/task-action (override in gas-analytics/index)", () => {
335335
assert.deepEqual(cheatcodeContent, { "test-entry": "42" });
336336
});
337337

338+
it("should not write when no existing file and no cheatcodes in current run", async () => {
339+
const suiteResults = [
340+
createSuiteResult("MyContract", [
341+
createTestResultWithSnapshots(undefined),
342+
]),
343+
];
344+
345+
const { snapshotCheatcodesCheck } = await handleSnapshotCheck(
346+
tmpDir,
347+
suiteResults,
348+
);
349+
350+
assert.equal(snapshotCheatcodesCheck.passed, true);
351+
assert.equal(snapshotCheatcodesCheck.written, false);
352+
assert.equal(snapshotCheatcodesCheck.comparison.added.length, 0);
353+
assert.equal(snapshotCheatcodesCheck.comparison.removed.length, 0);
354+
assert.equal(snapshotCheatcodesCheck.comparison.changed.length, 0);
355+
});
356+
338357
it("should pass when snapshot cheatcodes are unchanged", async () => {
339358
const suiteResults = [
340359
createSuiteResult("MyContract", [

0 commit comments

Comments
 (0)