Skip to content

Commit 3bcad59

Browse files
authored
Merge pull request #7686 from NomicFoundation/fix-solidity-tests-task-compilation
Fix `test solidity` and `build` issues
2 parents a5d24aa + 2b65ce5 commit 3bcad59

File tree

17 files changed

+482
-147
lines changed

17 files changed

+482
-147
lines changed

.changeset/rude-badgers-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Remove the compilation spinner when the compilation fails

.changeset/serious-knives-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Fix the `test solidity` task's compilation process

.changeset/twenty-dolls-stand.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-errors": patch
3+
"hardhat": patch
4+
---
5+
6+
Fail when a file isn't built neither as contract nor test

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/hardhat-errors/src/descriptors.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,18 @@ Please check Hardhat's output for more details.`,
11671167
websiteTitle: "Could not parse a compiler version",
11681168
websiteDescription: `Hardhat failed to parse the full compiler version from the output of the compiler's 'version' command.`,
11691169
},
1170+
UNRECOGNIZED_FILES_NOT_COMPILED: {
1171+
number: 915,
1172+
messageTemplate: `The build process failed because these files you provided haven't been recognized neither as contracts nor tests:
1173+
1174+
{files}
1175+
1176+
Solidity test files must be placed in your test directory, or in your contracts directory and end in .t.sol.`,
1177+
websiteTitle: "Build failed due to unrecognized files",
1178+
websiteDescription: `Hardhat failed to build your contracts and/or tests because you passed a file as parameter, but it wasn't recognized neither as a valid contract nor test.
1179+
1180+
Solidity test files must be placed in your test directory, or in your contracts directory and end in .t.sol.`,
1181+
},
11701182
},
11711183
ARTIFACTS: {
11721184
NOT_FOUND: {

v-next/hardhat-keystore/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"c8": "^9.1.0",
4949
"eslint": "9.25.1",
5050
"expect-type": "^1.2.1",
51+
"hardhat": "workspace:^3.0.0",
5152
"prettier": "3.2.5",
5253
"rimraf": "^5.0.5",
5354
"tsx": "^4.19.3",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import {
1616
l1HardforkLatest,
1717
IncludeTraces,
1818
FsAccessPermission,
19+
CollectStackTraces,
1920
} from "@nomicfoundation/edr";
2021
import { hexStringToBytes } from "@nomicfoundation/hardhat-utils/hex";
2122
import chalk from "chalk";
2223

23-
import { OPTIMISM_CHAIN_TYPE } from "../../constants.js";
24+
import { DEFAULT_VERBOSITY, OPTIMISM_CHAIN_TYPE } from "../../constants.js";
2425

2526
import { type Colorizer, formatArtifactId } from "./formatters.js";
2627

@@ -126,6 +127,8 @@ export async function solidityTestConfigToSolidityTestRunnerConfigArgs({
126127
}
127128
}
128129

130+
const shouldAlwaysCollectStackTraces = verbosity > DEFAULT_VERBOSITY;
131+
129132
return {
130133
projectRoot,
131134
...config,
@@ -144,6 +147,9 @@ export async function solidityTestConfigToSolidityTestRunnerConfigArgs({
144147
forkBlockNumber,
145148
rpcEndpoints,
146149
generateGasReport,
150+
collectStackTraces: shouldAlwaysCollectStackTraces
151+
? CollectStackTraces.Always
152+
: CollectStackTraces.OnFailure,
147153
};
148154
}
149155

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { HardhatPlugin } from "../../../types/plugins.js";
22

33
import { ArgumentType } from "hardhat/types/arguments";
44

5+
import { DEFAULT_VERBOSITY } from "../../constants.js";
56
import { task } from "../../core/config.js";
67

78
import "./type-extensions.js";
@@ -38,7 +39,7 @@ const hardhatPlugin: HardhatPlugin = {
3839
name: "verbosity",
3940
shortName: "v",
4041
description: "Verbosity level of the test output",
41-
defaultValue: 2,
42+
defaultValue: DEFAULT_VERBOSITY,
4243
})
4344
.setAction(async () => import("./task-action.js"))
4445
.build(),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,11 @@ export async function* testReporter(
302302
case "UnsafeToReplay":
303303
if (stackTrace.globalForkLatest === true) {
304304
yield indenter.t`Stack Trace Warning: ${colorizer.grey("The test is not safe to replay because a fork url without a fork block number was provided.")}\n`;
305+
yield indenter.t`Try rerunning your tests with -vvv or above.\n`;
305306
}
306307
if (stackTrace.impureCheatcodes.length > 0) {
307308
yield indenter.t`Stack Trace Warning: ${colorizer.grey(`The test is not safe to replay because it uses impure cheatcodes: ${stackTrace.impureCheatcodes.join(", ")}`)}\n`;
309+
yield indenter.t`Try rerunning your tests with -vvv or above.\n`;
308310
}
309311
break;
310312
case "HeuristicFailed":

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
7979
);
8080
}
8181

82+
// Run the build task for contract files if needed
83+
if (noCompile !== true) {
84+
await hre.tasks.getTask("build").run({
85+
noTests: true,
86+
});
87+
}
88+
8289
// Run the build task for test files
8390
const { testRootPaths }: { testRootPaths: string[] } = await hre.tasks
8491
.getTask("build")
8592
.run({
8693
files: testFiles,
87-
noContracts: noCompile,
94+
noContracts: true,
8895
});
8996
console.log();
9097

0 commit comments

Comments
 (0)