Skip to content

Commit fef3c25

Browse files
committed
fix: adapt gas-analytics and solidity-test to Result pattern after rebase onto main
1 parent 8345cce commit fef3c25

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const hardhatPlugin: HardhatPlugin = {
2121
default: async (args, _hre, runSuper) => {
2222
// We don't need to do anything here, as the test task will forward
2323
// the arguments to its subtasks.
24-
await runSuper(args);
24+
return runSuper(args);
2525
},
2626
}))
2727
.build(),

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { TaskOverrideActionFunction } from "../../../../../types/tasks.js";
2+
import type { Result } from "../../../../../types/utils.js";
3+
import type { SolidityTestRunResult } from "../../../solidity-test/task-action.js";
24
import type { FunctionGasSnapshotCheckResult } from "../../function-gas-snapshots.js";
35
import type { SnapshotCheatcodesCheckResult } from "../../snapshot-cheatcodes.js";
46
import type { SuiteResult } from "@nomicfoundation/edr";
57

68
import { HardhatError } from "@nomicfoundation/hardhat-errors";
79
import chalk from "chalk";
810

11+
import { errorResult } from "../../../../../utils/result.js";
912
import {
1013
checkFunctionGasSnapshots,
1114
extractFunctionGasSnapshots,
@@ -36,9 +39,13 @@ export interface SnapshotCheckResult {
3639
const runSolidityTests: TaskOverrideActionFunction<
3740
GasAnalyticsTestActionArguments
3841
> = async (args, hre, runSuper) => {
39-
const taskResult = await runSuper(args);
40-
const suiteResults: SuiteResult[] = taskResult.suiteResults;
41-
const testsPassed = process.exitCode !== 1;
42+
const superResult: Result<SolidityTestRunResult, SolidityTestRunResult> =
43+
await runSuper(args);
44+
const testsPassed = superResult.success;
45+
const solidityTestRunResult = testsPassed
46+
? superResult.value
47+
: superResult.error;
48+
const suiteResults = solidityTestRunResult.suiteResults;
4249
const rootPath = hre.config.paths.root;
4350

4451
if (args.snapshot && args.snapshotCheck) {
@@ -66,12 +73,11 @@ const runSolidityTests: TaskOverrideActionFunction<
6673
snapshotCheckResult.snapshotCheatcodesCheck.passed;
6774
}
6875

69-
process.exitCode = testsPassed && snapshotCheckPassed ? 0 : 1;
76+
if (!snapshotCheckPassed) {
77+
return errorResult(solidityTestRunResult);
78+
}
7079

71-
return {
72-
...taskResult,
73-
suiteResults,
74-
};
80+
return superResult;
7581
};
7682

7783
export async function handleSnapshot(

v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ interface TestActionArguments {
4747
testSummaryIndex: number;
4848
}
4949

50+
export interface SolidityTestRunResult extends TestRunResult {
51+
suiteResults: SuiteResult[];
52+
}
53+
5054
const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
5155
{ testFiles, chainType, grep, noCompile, verbosity, testSummaryIndex },
5256
hre,
53-
): Promise<Result<TestRunResult, TestRunResult>> => {
57+
): Promise<Result<SolidityTestRunResult, SolidityTestRunResult>> => {
5458
assertHardhatInvariant(
5559
hre instanceof HardhatRuntimeEnvironmentImplementation,
5660
"Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation",

v-next/hardhat/test/internal/builtin-plugins/solidity-test/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe("solidityTestConfigToSolidityTestRunnerConfigArgs", () => {
140140
const args = await solidityTestConfigToSolidityTestRunnerConfigArgs({
141141
chainType: GENERIC_CHAIN_TYPE,
142142
projectRoot: process.cwd(),
143-
config: { gasLimit: undefined },
143+
config: { fuzz: { seed: "0x1234" }, gasLimit: undefined },
144144
verbosity: 1,
145145
generateGasReport: false,
146146
});
@@ -152,7 +152,7 @@ describe("solidityTestConfigToSolidityTestRunnerConfigArgs", () => {
152152
const args = await solidityTestConfigToSolidityTestRunnerConfigArgs({
153153
chainType: GENERIC_CHAIN_TYPE,
154154
projectRoot: process.cwd(),
155-
config: { gasLimit: 12_000_000n },
155+
config: { fuzz: { seed: "0x1234" }, gasLimit: 12_000_000n },
156156
verbosity: 1,
157157
generateGasReport: false,
158158
});

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,18 @@ describe("solidity-test/task-action", function () {
185185
const result = await hre.tasks
186186
.getTask(["test", "solidity"])
187187
.run({ noCompile: true });
188-
assert.deepEqual(result, {
189-
success: false,
190-
error: {
191-
summary: {
192-
failed: 0,
193-
passed: 0,
194-
skipped: 0,
195-
todo: 0,
196-
failureOutput: "",
197-
},
198-
},
188+
assert.equal(result.success, false);
189+
assert.deepEqual(result.error.summary, {
190+
failed: 0,
191+
passed: 0,
192+
skipped: 0,
193+
todo: 0,
194+
failureOutput: "",
199195
});
196+
assert.ok(
197+
Array.isArray(result.error.suiteResults),
198+
"suiteResults should be an array",
199+
);
200200
});
201201

202202
it("should return a success result when all tests pass", async () => {
@@ -205,18 +205,18 @@ describe("solidity-test/task-action", function () {
205205
const result = await hre.tasks
206206
.getTask(["test", "solidity"])
207207
.run({ noCompile: true });
208-
assert.deepEqual(result, {
209-
success: true,
210-
value: {
211-
summary: {
212-
failed: 0,
213-
passed: 0,
214-
skipped: 0,
215-
todo: 0,
216-
failureOutput: "",
217-
},
218-
},
208+
assert.equal(result.success, true);
209+
assert.deepEqual(result.value.summary, {
210+
failed: 0,
211+
passed: 0,
212+
skipped: 0,
213+
todo: 0,
214+
failureOutput: "",
219215
});
216+
assert.ok(
217+
Array.isArray(result.value.suiteResults),
218+
"suiteResults should be an array",
219+
);
220220
});
221221

222222
describe("when the contracts are in the optimism chain type", () => {

0 commit comments

Comments
 (0)