hardhat 3.4.5 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/src/config.d.ts +0 -1
  3. package/dist/src/config.d.ts.map +1 -1
  4. package/dist/src/config.js.map +1 -1
  5. package/dist/src/hre.d.ts +0 -1
  6. package/dist/src/hre.d.ts.map +1 -1
  7. package/dist/src/hre.js.map +1 -1
  8. package/dist/src/index.d.ts +0 -1
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/internal/builtin-global-options.d.ts.map +1 -1
  12. package/dist/src/internal/builtin-global-options.js +1 -1
  13. package/dist/src/internal/builtin-global-options.js.map +1 -1
  14. package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts +21 -0
  15. package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts.map +1 -1
  16. package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js +49 -1
  17. package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js.map +1 -1
  18. package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.d.ts +2 -1
  19. package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.d.ts.map +1 -1
  20. package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.js +12 -2
  21. package/dist/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.js.map +1 -1
  22. package/dist/src/internal/builtin-plugins/network-manager/config-resolution.d.ts.map +1 -1
  23. package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js +9 -2
  24. package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js.map +1 -1
  25. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts +1 -0
  26. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts.map +1 -1
  27. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js +1 -0
  28. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js.map +1 -1
  29. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts.map +1 -1
  30. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js +25 -5
  31. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
  32. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts +16 -0
  33. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts.map +1 -1
  34. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js +28 -1
  35. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js.map +1 -1
  36. package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts.map +1 -1
  37. package/dist/src/internal/builtin-plugins/network-manager/network-manager.js +2 -6
  38. package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
  39. package/dist/src/internal/builtin-plugins/network-manager/type-extensions/config.d.ts +5 -3
  40. package/dist/src/internal/builtin-plugins/network-manager/type-extensions/config.d.ts.map +1 -1
  41. package/dist/src/internal/builtin-plugins/network-manager/type-validation.d.ts.map +1 -1
  42. package/dist/src/internal/builtin-plugins/network-manager/type-validation.js +3 -1
  43. package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
  44. package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.d.ts +18 -0
  45. package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.d.ts.map +1 -0
  46. package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.js +27 -0
  47. package/dist/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.js.map +1 -0
  48. package/dist/src/internal/builtin-plugins/node/json-rpc/handler.js +6 -5
  49. package/dist/src/internal/builtin-plugins/node/json-rpc/handler.js.map +1 -1
  50. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +1 -4
  51. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
  52. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +1 -11
  53. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
  54. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts.map +1 -1
  55. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js +1 -1
  56. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js.map +1 -1
  57. package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.d.ts +6 -10
  58. package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.d.ts.map +1 -1
  59. package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.js +54 -43
  60. package/dist/src/internal/builtin-plugins/solidity/build-system/warning-suppression.js.map +1 -1
  61. package/dist/src/internal/builtin-plugins/solidity/constants.d.ts +10 -0
  62. package/dist/src/internal/builtin-plugins/solidity/constants.d.ts.map +1 -1
  63. package/dist/src/internal/builtin-plugins/solidity/constants.js +10 -0
  64. package/dist/src/internal/builtin-plugins/solidity/constants.js.map +1 -1
  65. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.d.ts.map +1 -1
  66. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js +2 -1
  67. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
  68. package/dist/src/internal/builtin-plugins/solidity/index.d.ts.map +1 -1
  69. package/dist/src/internal/builtin-plugins/solidity/index.js +1 -0
  70. package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
  71. package/dist/src/internal/builtin-plugins/solidity/tasks/compile.d.ts +9 -0
  72. package/dist/src/internal/builtin-plugins/solidity/tasks/compile.d.ts.map +1 -0
  73. package/dist/src/internal/builtin-plugins/solidity/tasks/compile.js +10 -0
  74. package/dist/src/internal/builtin-plugins/solidity/tasks/compile.js.map +1 -0
  75. package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts +4 -3
  76. package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts.map +1 -1
  77. package/dist/src/internal/builtin-plugins/solidity-test/config.js +55 -8
  78. package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
  79. package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.d.ts +58 -0
  80. package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.d.ts.map +1 -0
  81. package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.js +226 -0
  82. package/dist/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.js.map +1 -0
  83. package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.d.ts +29 -0
  84. package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.d.ts.map +1 -0
  85. package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.js +244 -0
  86. package/dist/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.js.map +1 -0
  87. package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.d.ts +7 -0
  88. package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.d.ts.map +1 -0
  89. package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.js +204 -0
  90. package/dist/src/internal/builtin-plugins/solidity-test/eip712/glob.js.map +1 -0
  91. package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.d.ts +21 -0
  92. package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.d.ts.map +1 -0
  93. package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js +77 -0
  94. package/dist/src/internal/builtin-plugins/solidity-test/eip712/index.js.map +1 -0
  95. package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts +4 -3
  96. package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts.map +1 -1
  97. package/dist/src/internal/builtin-plugins/solidity-test/helpers.js +20 -3
  98. package/dist/src/internal/builtin-plugins/solidity-test/helpers.js.map +1 -1
  99. package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
  100. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +5 -1
  101. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
  102. package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.d.ts +2 -0
  103. package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.d.ts.map +1 -0
  104. package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.js +2 -0
  105. package/dist/src/internal/builtin-plugins/solidity-test/test-profiles.js.map +1 -0
  106. package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts +91 -32
  107. package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts.map +1 -1
  108. package/dist/src/internal/cli/error-handler.d.ts +11 -2
  109. package/dist/src/internal/cli/error-handler.d.ts.map +1 -1
  110. package/dist/src/internal/cli/error-handler.js +72 -46
  111. package/dist/src/internal/cli/error-handler.js.map +1 -1
  112. package/dist/src/internal/cli/init/init.d.ts +31 -6
  113. package/dist/src/internal/cli/init/init.d.ts.map +1 -1
  114. package/dist/src/internal/cli/init/init.js +126 -13
  115. package/dist/src/internal/cli/init/init.js.map +1 -1
  116. package/dist/src/internal/cli/init/package-manager.d.ts +7 -1
  117. package/dist/src/internal/cli/init/package-manager.d.ts.map +1 -1
  118. package/dist/src/internal/cli/init/package-manager.js +14 -2
  119. package/dist/src/internal/cli/init/package-manager.js.map +1 -1
  120. package/dist/src/internal/cli/main.d.ts.map +1 -1
  121. package/dist/src/internal/cli/main.js +42 -2
  122. package/dist/src/internal/cli/main.js.map +1 -1
  123. package/dist/src/internal/cli/telemetry/error-classification/classifier.d.ts +2 -1
  124. package/dist/src/internal/cli/telemetry/error-classification/classifier.d.ts.map +1 -1
  125. package/dist/src/internal/cli/telemetry/error-classification/classifier.js +2 -1
  126. package/dist/src/internal/cli/telemetry/error-classification/classifier.js.map +1 -1
  127. package/dist/src/internal/using-hardhat2-plugin-errors.d.ts.map +1 -1
  128. package/dist/src/internal/using-hardhat2-plugin-errors.js +8 -11
  129. package/dist/src/internal/using-hardhat2-plugin-errors.js.map +1 -1
  130. package/dist/src/types/arguments.d.ts +1 -0
  131. package/dist/src/types/arguments.d.ts.map +1 -1
  132. package/dist/src/types/arguments.js +1 -0
  133. package/dist/src/types/arguments.js.map +1 -1
  134. package/dist/src/types/artifacts.d.ts +1 -0
  135. package/dist/src/types/artifacts.d.ts.map +1 -1
  136. package/dist/src/types/artifacts.js +1 -1
  137. package/dist/src/types/artifacts.js.map +1 -1
  138. package/dist/src/types/builtin-plugin-type-extensions.d.ts +2 -0
  139. package/dist/src/types/builtin-plugin-type-extensions.d.ts.map +1 -0
  140. package/dist/src/types/builtin-plugin-type-extensions.js +2 -0
  141. package/dist/src/types/builtin-plugin-type-extensions.js.map +1 -0
  142. package/dist/src/types/config.d.ts +1 -0
  143. package/dist/src/types/config.d.ts.map +1 -1
  144. package/dist/src/types/config.js +1 -1
  145. package/dist/src/types/config.js.map +1 -1
  146. package/dist/src/types/global-options.d.ts +1 -0
  147. package/dist/src/types/global-options.d.ts.map +1 -1
  148. package/dist/src/types/global-options.js +1 -1
  149. package/dist/src/types/global-options.js.map +1 -1
  150. package/dist/src/types/hooks.d.ts +1 -0
  151. package/dist/src/types/hooks.d.ts.map +1 -1
  152. package/dist/src/types/hooks.js +1 -1
  153. package/dist/src/types/hooks.js.map +1 -1
  154. package/dist/src/types/hre.d.ts +1 -0
  155. package/dist/src/types/hre.d.ts.map +1 -1
  156. package/dist/src/types/hre.js +1 -1
  157. package/dist/src/types/hre.js.map +1 -1
  158. package/dist/src/types/index.d.ts +1 -0
  159. package/dist/src/types/index.d.ts.map +1 -1
  160. package/dist/src/types/index.js +1 -0
  161. package/dist/src/types/index.js.map +1 -1
  162. package/dist/src/types/network.d.ts +1 -0
  163. package/dist/src/types/network.d.ts.map +1 -1
  164. package/dist/src/types/network.js +1 -1
  165. package/dist/src/types/network.js.map +1 -1
  166. package/dist/src/types/plugins.d.ts +1 -1
  167. package/dist/src/types/plugins.d.ts.map +1 -1
  168. package/dist/src/types/plugins.js +1 -1
  169. package/dist/src/types/plugins.js.map +1 -1
  170. package/dist/src/types/providers.d.ts +1 -0
  171. package/dist/src/types/providers.d.ts.map +1 -1
  172. package/dist/src/types/providers.js +1 -1
  173. package/dist/src/types/providers.js.map +1 -1
  174. package/dist/src/types/solidity.d.ts +1 -0
  175. package/dist/src/types/solidity.d.ts.map +1 -1
  176. package/dist/src/types/solidity.js +1 -0
  177. package/dist/src/types/solidity.js.map +1 -1
  178. package/dist/src/types/tasks.d.ts +1 -0
  179. package/dist/src/types/tasks.d.ts.map +1 -1
  180. package/dist/src/types/tasks.js +1 -0
  181. package/dist/src/types/tasks.js.map +1 -1
  182. package/dist/src/types/test.d.ts +1 -0
  183. package/dist/src/types/test.d.ts.map +1 -1
  184. package/dist/src/types/test.js +1 -1
  185. package/dist/src/types/test.js.map +1 -1
  186. package/dist/src/types/user-interruptions.d.ts +1 -0
  187. package/dist/src/types/user-interruptions.d.ts.map +1 -1
  188. package/dist/src/types/user-interruptions.js +1 -1
  189. package/dist/src/types/user-interruptions.js.map +1 -1
  190. package/package.json +12 -11
  191. package/src/config.ts +0 -2
  192. package/src/hre.ts +0 -3
  193. package/src/index.ts +0 -3
  194. package/src/internal/builtin-global-options.ts +2 -1
  195. package/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts +90 -1
  196. package/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts +24 -2
  197. package/src/internal/builtin-plugins/network-manager/config-resolution.ts +11 -3
  198. package/src/internal/builtin-plugins/network-manager/edr/edr-constants.ts +2 -0
  199. package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +38 -8
  200. package/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts +43 -1
  201. package/src/internal/builtin-plugins/network-manager/network-manager.ts +5 -6
  202. package/src/internal/builtin-plugins/network-manager/type-extensions/config.ts +5 -3
  203. package/src/internal/builtin-plugins/network-manager/type-validation.ts +7 -1
  204. package/src/internal/builtin-plugins/network-manager/utils/apply-coverage-network-overrides.ts +32 -0
  205. package/src/internal/builtin-plugins/node/json-rpc/handler.ts +7 -5
  206. package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +2 -15
  207. package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +1 -2
  208. package/src/internal/builtin-plugins/solidity/build-system/warning-suppression.ts +81 -59
  209. package/src/internal/builtin-plugins/solidity/constants.ts +11 -0
  210. package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +2 -1
  211. package/src/internal/builtin-plugins/solidity/index.ts +1 -0
  212. package/src/internal/builtin-plugins/solidity/tasks/compile.ts +12 -0
  213. package/src/internal/builtin-plugins/solidity-test/config.ts +85 -12
  214. package/src/internal/builtin-plugins/solidity-test/eip712/ast-walker.ts +324 -0
  215. package/src/internal/builtin-plugins/solidity-test/eip712/canonicalize.ts +317 -0
  216. package/src/internal/builtin-plugins/solidity-test/eip712/glob.ts +225 -0
  217. package/src/internal/builtin-plugins/solidity-test/eip712/index.ts +120 -0
  218. package/src/internal/builtin-plugins/solidity-test/helpers.ts +28 -4
  219. package/src/internal/builtin-plugins/solidity-test/task-action.ts +12 -1
  220. package/src/internal/builtin-plugins/solidity-test/test-profiles.ts +1 -0
  221. package/src/internal/builtin-plugins/solidity-test/type-extensions.ts +100 -33
  222. package/src/internal/cli/error-handler.ts +103 -72
  223. package/src/internal/cli/init/init.ts +203 -16
  224. package/src/internal/cli/init/package-manager.ts +18 -1
  225. package/src/internal/cli/main.ts +65 -2
  226. package/src/internal/cli/telemetry/error-classification/classifier.ts +2 -1
  227. package/src/internal/using-hardhat2-plugin-errors.ts +8 -11
  228. package/src/types/arguments.ts +2 -0
  229. package/src/types/artifacts.ts +2 -0
  230. package/src/types/builtin-plugin-type-extensions.ts +15 -0
  231. package/src/types/config.ts +2 -0
  232. package/src/types/global-options.ts +2 -0
  233. package/src/types/hooks.ts +2 -0
  234. package/src/types/hre.ts +2 -0
  235. package/src/types/index.ts +2 -0
  236. package/src/types/network.ts +2 -0
  237. package/src/types/plugins.ts +1 -2
  238. package/src/types/providers.ts +2 -0
  239. package/src/types/solidity.ts +2 -0
  240. package/src/types/tasks.ts +2 -0
  241. package/src/types/test.ts +2 -0
  242. package/src/types/user-interruptions.ts +2 -0
  243. package/templates/hardhat-3/01-node-test-runner-viem/package.json +11 -11
  244. package/templates/hardhat-3/01-node-test-runner-viem/tsconfig.json +4 -7
  245. package/templates/hardhat-3/02-mocha-ethers/package.json +13 -13
  246. package/templates/hardhat-3/02-mocha-ethers/tsconfig.json +4 -7
  247. package/templates/hardhat-3/03-minimal/package.json +2 -2
  248. package/templates/hardhat-3/03-minimal/tsconfig.json +4 -7
@@ -95,21 +95,6 @@ export function isSolcSolidityCompilerConfig(
95
95
  return config.type === undefined || config.type === "solc";
96
96
  }
97
97
 
98
- // Compiler warnings to suppress from build output.
99
- // Each rule specifies a warning message and the source file it applies to.
100
- // This allows suppressing known warnings from internal files (e.g., console.sol)
101
- // while still showing the same warning type from user code.
102
- export const SUPPRESSED_WARNINGS: Array<{
103
- message: string;
104
- sourceFile: string;
105
- }> = [
106
- {
107
- message:
108
- "Natspec memory-safe-assembly special comment for inline assembly is deprecated and scheduled for removal. Use the memory-safe block annotation instead.",
109
- sourceFile: path.normalize("hardhat/console.sol"),
110
- },
111
- ];
112
-
113
98
  interface CompilationResult {
114
99
  compilationJob: CompilationJob;
115
100
  compilerOutput: CompilerOutput;
@@ -123,6 +108,7 @@ export interface SolidityBuildSystemOptions {
123
108
  readonly artifactsPath: string;
124
109
  readonly cachePath: string;
125
110
  readonly solidityTestsPath: string;
111
+ readonly coverage: boolean;
126
112
  }
127
113
 
128
114
  /**
@@ -1417,6 +1403,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
1417
1403
  msg,
1418
1404
  this.#options.solidityTestsPath,
1419
1405
  this.#options.projectRoot,
1406
+ this.#options.coverage,
1420
1407
  );
1421
1408
  }
1422
1409
 
@@ -29,14 +29,13 @@ import {
29
29
  } from "@nomicfoundation/hardhat-utils/package";
30
30
 
31
31
  import { UserRemappingErrorType } from "../../../../../types/solidity.js";
32
+ import { HARDHAT_PROJECT_INPUT_SOURCE_NAME_ROOT } from "../../constants.js";
32
33
 
33
34
  import { getNpmPackageName } from "./npm-module-parsing.js";
34
35
  import { parseRemappingString, selectBestRemapping } from "./remappings.js";
35
36
  import { sourceNamePathJoin } from "./source-name-utils.js";
36
37
  import { UserRemappingType } from "./types.js";
37
38
 
38
- const HARDHAT_PROJECT_INPUT_SOURCE_NAME_ROOT = "project";
39
-
40
39
  /**
41
40
  * Returns a normalized version of the path if it refers to a node_modules in
42
41
  * the root directory (i.e. node_modules/...), or a `node_modules` directory
@@ -1,97 +1,119 @@
1
1
  import path from "node:path";
2
2
 
3
- // Compiler warnings to suppress from build output.
4
- // Supports two types of suppression rules:
5
- //
6
- // 1. scope: 'specific-file' - Suppress warnings from specific file paths
7
- // - Use this to suppress known warnings from internal/library files (e.g., console.sol)
8
- // - The same warning type will still be shown for user code
9
- //
10
- // 2. scope: 'test-files' - Suppress warnings from all test files
11
- // - Test files are identified as:
12
- // * Files ending in .t.sol (e.g., Counter.t.sol)
13
- // * Files inside test/contracts/ directory
14
- // (e.g., test/contracts/Example.sol)
15
- // - Use this for warnings that are acceptable in test code but not in production code
16
- // (e.g., missing SPDX license identifiers or pragma statements)
17
- export const SUPPRESSED_WARNINGS: Array<
18
- | {
19
- message: string;
20
- scope: "specific-file";
21
- filePath: string;
22
- }
23
- | {
24
- message: string;
25
- scope: "test-files";
26
- }
27
- > = [
3
+ import { COVERAGE_LIBRARY_FILE_NAME } from "@nomicfoundation/edr";
4
+
5
+ export const NATSPEC_MEMORY_SAFE_ASSEMBLY_WARNING =
6
+ "Natspec memory-safe-assembly special comment for inline assembly is deprecated and scheduled for removal. Use the memory-safe block annotation instead.";
7
+ export const SPDX_WARNING = "SPDX license identifier not provided";
8
+ export const PRAGMA_WARNING =
9
+ "Source file does not specify required compiler version";
10
+ const CONTRACT_SIZE_WARNING = "Contract code size is";
11
+
12
+ // Suppression rules are grouped by scope. Each array has its own match logic
13
+ // in `shouldSuppressWarning` function; add new entries to the array that fits, or add
14
+ // a new array + block for a new scope.
15
+
16
+ // Warnings tied to a specific internal file (e.g. console.sol). Suppressed
17
+ // only when the warning points at that file.
18
+ const SPECIFIC_FILE_RULES: ReadonlyArray<{
19
+ message: string;
20
+ filePath: string;
21
+ }> = [
28
22
  {
29
- message:
30
- "Natspec memory-safe-assembly special comment for inline assembly is deprecated and scheduled for removal. Use the memory-safe block annotation instead.",
31
- scope: "specific-file",
23
+ message: NATSPEC_MEMORY_SAFE_ASSEMBLY_WARNING,
32
24
  // Normalize to handle different OS path separators
33
25
  filePath: path.normalize("hardhat/console.sol"),
34
26
  },
27
+ ];
28
+
29
+ // Warnings acceptable in test files. Suppressed when the warning points at a
30
+ // file ending in `.t.sol` or inside the configured Solidity test directory.
31
+ const TEST_FILE_WARNING_MESSAGES: readonly string[] = [
32
+ SPDX_WARNING,
33
+ PRAGMA_WARNING,
34
+ ];
35
+
36
+ // Warnings suppressed only when running with `--coverage`. An entry with no
37
+ // `filePath` matches the message anywhere (e.g. contract-size warnings that
38
+ // fire on user files as a side effect of instrumentation); an entry with a
39
+ // `filePath` only matches when the diagnostic also points at that file
40
+ // (e.g. the injected coverage library file, which users can't edit).
41
+ const COVERAGE_MODE_RULES: ReadonlyArray<{
42
+ message: string;
43
+ filePath?: string;
44
+ }> = [
45
+ { message: CONTRACT_SIZE_WARNING },
35
46
  {
36
- message: "SPDX license identifier not provided",
37
- scope: "test-files",
38
- },
39
- {
40
- message: "Source file does not specify required compiler version",
41
- scope: "test-files",
47
+ message: NATSPEC_MEMORY_SAFE_ASSEMBLY_WARNING,
48
+ filePath: COVERAGE_LIBRARY_FILE_NAME,
42
49
  },
43
50
  ];
44
51
 
45
52
  /**
46
- * Determines if a compiler warning should be suppressed based on the suppression rules.
53
+ * Determines if a compiler warning should be suppressed.
47
54
  *
48
55
  * @param errorMessage - The formatted error message from the compiler
49
56
  * @param absoluteSolidityTestsPath - Absolute path to the Solidity test directory
50
57
  * @param absoluteProjectRoot - Absolute path to the project root
58
+ * @param coverage - Whether the build is running with `--coverage` enabled
51
59
  * @returns true if the warning should be suppressed, false otherwise
52
60
  */
53
61
  export function shouldSuppressWarning(
54
62
  errorMessage: string,
55
63
  absoluteSolidityTestsPath: string,
56
64
  absoluteProjectRoot: string,
65
+ coverage: boolean,
57
66
  ): boolean {
58
- // Compute relative path from project root to test directory.
59
- // Example:
60
- // absoluteSolidityTestsPath: /workspaces/hardhat-4/packages/example-project/test/contracts
61
- // absoluteProjectRoot: /workspaces/hardhat-4/packages/example-project
62
- // relativeTestPath: test/contracts/ - note the addition of the `/`
63
- // to avoid partial matches, e.g.: test/contractsUtils/
64
- const relativeTestPath = path.join(
65
- path.relative(absoluteProjectRoot, absoluteSolidityTestsPath),
66
- "/",
67
- );
68
-
69
- return SUPPRESSED_WARNINGS.some((rule) => {
70
- if (!errorMessage.includes(rule.message)) {
71
- return false;
72
- }
67
+ // Warnings suppressed only when running with `--coverage`.
68
+ if (
69
+ coverage &&
70
+ COVERAGE_MODE_RULES.some(
71
+ (rule) =>
72
+ errorMessage.includes(rule.message) &&
73
+ (rule.filePath === undefined || errorMessage.includes(rule.filePath)),
74
+ )
75
+ ) {
76
+ return true;
77
+ }
73
78
 
74
- if (rule.scope === "specific-file") {
75
- return errorMessage.includes(rule.filePath);
76
- }
79
+ // Warnings tied to a specific internal file (e.g. console.sol).
80
+ if (
81
+ SPECIFIC_FILE_RULES.some(
82
+ (rule) =>
83
+ errorMessage.includes(rule.message) &&
84
+ errorMessage.includes(rule.filePath),
85
+ )
86
+ ) {
87
+ return true;
88
+ }
77
89
 
78
- // Check if the message contains a path to a test file
90
+ // Warnings allowed in test files.
91
+ if (TEST_FILE_WARNING_MESSAGES.some((m) => errorMessage.includes(m))) {
79
92
  // Test files are identified by:
80
93
  // - Ending in .t.sol (e.g., Counter.t.sol)
81
94
  // - Being inside the configured Solidity test directory
82
-
83
95
  if (/\.t\.sol(:|$|\s)/.test(errorMessage)) {
84
96
  return true;
85
97
  }
86
98
 
87
- // Extract file path from error message
99
+ // Compute relative path from project root to test directory.
100
+ // Example:
101
+ // absoluteSolidityTestsPath: /workspaces/hardhat-4/packages/example-project/test/contracts
102
+ // absoluteProjectRoot: /workspaces/hardhat-4/packages/example-project
103
+ // relativeTestPath: test/contracts/ - note the addition of the `/`
104
+ // to avoid partial matches, e.g.: test/contractsUtils/
105
+ const relativeTestPath = path.join(
106
+ path.relative(absoluteProjectRoot, absoluteSolidityTestsPath),
107
+ "/",
108
+ );
109
+
110
+ // Extract file path from error message.
88
111
  // Format: "Warning: message\n --> path/to/file.sol:line:column:"
89
112
  const pathMatches = errorMessage.match(/-->\s+([^\s:]+\.sol)/);
90
-
91
113
  if (pathMatches !== null) {
92
114
  return pathMatches[1].includes(relativeTestPath);
93
115
  }
116
+ }
94
117
 
95
- return false;
96
- });
118
+ return false;
97
119
  }
@@ -1,5 +1,16 @@
1
1
  import type { CompilerInput } from "../../../types/solidity.js";
2
2
 
3
+ /**
4
+ * The input source name prefix used for files belonging to the Hardhat
5
+ * project (as opposed to npm packages, which use `npm/<pkg>@<version>`).
6
+ *
7
+ * For example, a project file at `<root>/contracts/Foo.sol` has input
8
+ * source name `project/contracts/Foo.sol`. Part of the build-info format
9
+ * contract: changing this value would require a new build-info format
10
+ * version.
11
+ */
12
+ export const HARDHAT_PROJECT_INPUT_SOURCE_NAME_ROOT = "project";
13
+
3
14
  export const DEFAULT_OUTPUT_SELECTION: CompilerInput["settings"]["outputSelection"] =
4
15
  {
5
16
  "*": {
@@ -152,7 +152,7 @@ class LazySolidityBuildSystem implements SolidityBuildSystem {
152
152
 
153
153
  export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
154
154
  return {
155
- created: async (_context, hre) => {
155
+ created: async (context, hre) => {
156
156
  hre.solidity = new LazySolidityBuildSystem(hre.hooks, {
157
157
  solidityConfig: hre.config.solidity,
158
158
  projectRoot: hre.config.paths.root,
@@ -160,6 +160,7 @@ export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
160
160
  artifactsPath: hre.config.paths.artifacts,
161
161
  cachePath: hre.config.paths.cache,
162
162
  solidityTestsPath: hre.config.paths.tests.solidity,
163
+ coverage: context.globalOptions.coverage,
163
164
  });
164
165
  },
165
166
  };
@@ -53,6 +53,7 @@ const hardhatPlugin: HardhatPlugin = {
53
53
  ...buildTask,
54
54
  id: ["compile"],
55
55
  description: "Build project (alias for build)",
56
+ action: async () => await import("./tasks/compile.js"),
56
57
  },
57
58
  ],
58
59
  globalOptions: [
@@ -0,0 +1,12 @@
1
+ import type { NewTaskActionFunction } from "../../../../types/tasks.js";
2
+
3
+ /**
4
+ * Compile task action is an alias of the build task action, it invokes
5
+ * the build task to ensure any build overrides are properly executed when
6
+ * compile is run.
7
+ */
8
+ const compileAction: NewTaskActionFunction = async (args, hre) => {
9
+ return await hre.tasks.getTask("build").run(args);
10
+ };
11
+
12
+ export default compileAction;
@@ -6,17 +6,19 @@ import type {
6
6
  } from "../../../types/config.js";
7
7
  import type { HardhatUserConfigValidationError } from "../../../types/hooks.js";
8
8
  import type {
9
- SolidityTestConfig,
10
9
  SolidityTestForkingConfig,
11
- SolidityTestUserConfig,
10
+ SolidityTestProfileConfig,
11
+ SolidityTestProfileUserConfig,
12
12
  } from "../../../types/test.js";
13
13
 
14
14
  import path from "node:path";
15
15
 
16
+ import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
16
17
  import { isObject } from "@nomicfoundation/hardhat-utils/lang";
17
18
  import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
18
19
  import {
19
20
  conditionalUnionType,
21
+ incompatibleFieldType,
20
22
  sensitiveStringSchema,
21
23
  sensitiveUrlSchema,
22
24
  unionType,
@@ -24,11 +26,13 @@ import {
24
26
  } from "@nomicfoundation/hardhat-zod-utils";
25
27
  import { z } from "zod";
26
28
 
29
+ import { DEFAULT_TEST_PROFILE } from "./test-profiles.js";
30
+
27
31
  // the keccak256 of "built for ethereum"
28
32
  export const DEFAULT_FUZZ_SEED =
29
33
  "0x7727ea51af0441c20da14dcd68a15dac8c9ebd589c5be8fa8c87c1d3720450bc";
30
34
 
31
- const solidityTestUserConfigType = z.object({
35
+ const solidityTestProfileUserConfigType = z.object({
32
36
  fsPermissions: z
33
37
  .object({
34
38
  readWriteFile: z.array(z.string()).optional(),
@@ -50,7 +54,11 @@ const solidityTestUserConfigType = z.object({
50
54
  blockTimestamp: z.bigint().optional(),
51
55
  prevRandao: z.bigint().optional(),
52
56
  gasLimit: z.bigint().optional(),
53
- blockGasLimit: z.bigint().or(z.literal(false)).optional(),
57
+ blockGasLimit: z.number().or(z.bigint()).or(z.literal(false)).optional(),
58
+ // TODO: widen back to .number().or(z.bigint()).or(z.literal(false))
59
+ // once Solidity test runner no longer breaks setUp() when
60
+ // disableTransactionGasCap is false. See PR #8301.
61
+ transactionGasCap: z.literal(false).optional(),
54
62
  fuzz: z
55
63
  .object({
56
64
  failurePersistDir: z.string().optional(),
@@ -89,8 +97,49 @@ const solidityTestUserConfigType = z.object({
89
97
  shrinkRunLimit: z.number().optional(),
90
98
  })
91
99
  .optional(),
100
+ eip712Types: z
101
+ .object({
102
+ include: z.array(z.string()).optional(),
103
+ exclude: z.array(z.string()).optional(),
104
+ })
105
+ .optional(),
92
106
  });
93
107
 
108
+ const solidityTestFlatUserConfigType = solidityTestProfileUserConfigType.extend(
109
+ {
110
+ profiles: incompatibleFieldType(
111
+ "This field is incompatible with the flat solidity test config",
112
+ ),
113
+ },
114
+ );
115
+
116
+ const solidityTestProfilesUserConfigType = z.object({
117
+ profiles: z
118
+ .record(z.string(), solidityTestProfileUserConfigType)
119
+ .refine(
120
+ (profiles) => DEFAULT_TEST_PROFILE in profiles,
121
+ "A `default` profile is required when using `profiles`",
122
+ )
123
+ .refine(
124
+ (profiles) =>
125
+ !(DEFAULT_TEST_PROFILE in profiles) ||
126
+ Object.keys(profiles).every((name) => name === DEFAULT_TEST_PROFILE),
127
+ "Only the `default` profile is supported. Other profile names will be supported in a future release.",
128
+ ),
129
+ });
130
+
131
+ const solidityTestUserConfigType = conditionalUnionType(
132
+ [
133
+ [
134
+ (data) =>
135
+ isObject(data) && "profiles" in data && Object.keys(data).length === 1,
136
+ solidityTestProfilesUserConfigType,
137
+ ],
138
+ [isObject, solidityTestFlatUserConfigType],
139
+ ],
140
+ "Expected a Solidity test config or a `{ profiles: { ... } }` wrapper",
141
+ );
142
+
94
143
  const userConfigType = z.object({
95
144
  paths: z
96
145
  .object({
@@ -111,7 +160,7 @@ const userConfigType = z.object({
111
160
  });
112
161
 
113
162
  export function resolveSolidityTestForkingConfig(
114
- forkingUserConfig: SolidityTestUserConfig["forking"],
163
+ forkingUserConfig: SolidityTestProfileUserConfig["forking"],
115
164
  resolveConfigurationVariable: ConfigurationVariableResolver,
116
165
  ): SolidityTestForkingConfig | undefined {
117
166
  if (forkingUserConfig === undefined) {
@@ -159,16 +208,29 @@ export async function resolveSolidityTestUserConfig(
159
208
 
160
209
  const defaultRpcCachePath = path.join(resolvedConfig.paths.cache, "edr");
161
210
 
211
+ const solidityUserConfig = userConfig.test?.solidity;
212
+ let profileUserConfig: SolidityTestProfileUserConfig | undefined;
213
+ if (solidityUserConfig !== undefined && "profiles" in solidityUserConfig) {
214
+ profileUserConfig = solidityUserConfig.profiles[DEFAULT_TEST_PROFILE];
215
+ assertHardhatInvariant(
216
+ profileUserConfig !== undefined,
217
+ "default profile must be present when the profiles wrapper user config is supplied",
218
+ );
219
+ } else {
220
+ profileUserConfig = solidityUserConfig;
221
+ }
222
+
162
223
  const resolvedForking = resolveSolidityTestForkingConfig(
163
- userConfig.test?.solidity?.forking,
224
+ profileUserConfig?.forking,
164
225
  resolveConfigurationVariable,
165
226
  );
166
227
 
167
- const solidityTest = {
228
+ const resolvedDefaultProfile = {
168
229
  rpcCachePath: defaultRpcCachePath,
169
- ...userConfig.test?.solidity,
170
- fuzz: resolveFuzzConfig(userConfig.test?.solidity?.fuzz),
230
+ ...profileUserConfig,
231
+ fuzz: resolveFuzzConfig(profileUserConfig?.fuzz),
171
232
  forking: resolvedForking,
233
+ eip712Types: resolveEip712TypesConfig(profileUserConfig?.eip712Types),
172
234
  };
173
235
 
174
236
  return {
@@ -182,16 +244,27 @@ export async function resolveSolidityTestUserConfig(
182
244
  },
183
245
  test: {
184
246
  ...resolvedConfig.test,
185
- solidity: solidityTest,
247
+ solidity: {
248
+ profiles: { [DEFAULT_TEST_PROFILE]: resolvedDefaultProfile },
249
+ },
186
250
  },
187
251
  };
188
252
  }
189
253
 
190
254
  export function resolveFuzzConfig(
191
- fuzzUserConfig: SolidityTestUserConfig["fuzz"] = {},
192
- ): SolidityTestConfig["fuzz"] {
255
+ fuzzUserConfig: SolidityTestProfileUserConfig["fuzz"] = {},
256
+ ): SolidityTestProfileConfig["fuzz"] {
193
257
  return {
194
258
  ...fuzzUserConfig,
195
259
  seed: fuzzUserConfig.seed ?? DEFAULT_FUZZ_SEED,
196
260
  };
197
261
  }
262
+
263
+ export function resolveEip712TypesConfig(
264
+ eip712TypesUserConfig: SolidityTestProfileUserConfig["eip712Types"] = {},
265
+ ): SolidityTestProfileConfig["eip712Types"] {
266
+ return {
267
+ include: eip712TypesUserConfig.include ?? [],
268
+ exclude: eip712TypesUserConfig.exclude ?? [],
269
+ };
270
+ }