hardhat 3.1.10 → 3.1.11

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 (186) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.d.ts +2 -2
  3. package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.d.ts.map +1 -1
  4. package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.js.map +1 -1
  5. package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.d.ts.map +1 -1
  6. package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.js.map +1 -1
  7. package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts +3 -5
  8. package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts.map +1 -1
  9. package/dist/src/internal/builtin-plugins/coverage/helpers.js +7 -19
  10. package/dist/src/internal/builtin-plugins/coverage/helpers.js.map +1 -1
  11. package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.d.ts +7 -0
  12. package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.d.ts.map +1 -0
  13. package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js +42 -0
  14. package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js.map +1 -0
  15. package/dist/src/internal/builtin-plugins/coverage/index.d.ts.map +1 -1
  16. package/dist/src/internal/builtin-plugins/coverage/index.js +1 -0
  17. package/dist/src/internal/builtin-plugins/coverage/index.js.map +1 -1
  18. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts +3 -5
  19. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts.map +1 -1
  20. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js +7 -19
  21. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js.map +1 -1
  22. package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.d.ts +7 -0
  23. package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.d.ts.map +1 -0
  24. package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.js +42 -0
  25. package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.js.map +1 -0
  26. package/dist/src/internal/builtin-plugins/gas-analytics/index.d.ts.map +1 -1
  27. package/dist/src/internal/builtin-plugins/gas-analytics/index.js +1 -0
  28. package/dist/src/internal/builtin-plugins/gas-analytics/index.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 +17 -20
  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/stack-traces/stack-trace-generation-errors.d.ts +1 -1
  33. package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.d.ts.map +1 -1
  34. package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.js +2 -2
  35. package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.js.map +1 -1
  36. package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.d.ts +0 -2
  37. package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.d.ts.map +1 -1
  38. package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.js +0 -6
  39. package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.js.map +1 -1
  40. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts +1 -3
  41. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts.map +1 -1
  42. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js +0 -49
  43. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js.map +1 -1
  44. package/dist/src/internal/builtin-plugins/solidity/build-results.d.ts +2 -2
  45. package/dist/src/internal/builtin-plugins/solidity/build-results.d.ts.map +1 -1
  46. package/dist/src/internal/builtin-plugins/solidity/build-results.js +2 -2
  47. package/dist/src/internal/builtin-plugins/solidity/build-results.js.map +1 -1
  48. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +1 -0
  49. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
  50. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +13 -5
  51. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
  52. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js +1 -1
  53. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js.map +1 -1
  54. package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph.d.ts +1 -1
  55. package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph.js +1 -1
  56. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts +2 -1
  57. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts.map +1 -1
  58. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts +13 -1
  59. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts.map +1 -1
  60. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js +30 -5
  61. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js.map +1 -1
  62. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/types.d.ts +3 -12
  63. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/types.d.ts.map +1 -1
  64. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/types.js.map +1 -1
  65. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/utils.d.ts +1 -1
  66. package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/utils.d.ts.map +1 -1
  67. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts +8 -6
  68. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts.map +1 -1
  69. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js +103 -27
  70. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js.map +1 -1
  71. package/dist/src/internal/builtin-plugins/solidity/config.js +2 -2
  72. package/dist/src/internal/builtin-plugins/solidity/config.js.map +1 -1
  73. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.d.ts.map +1 -1
  74. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js +5 -0
  75. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
  76. package/dist/src/internal/builtin-plugins/solidity/tasks/build.js +1 -1
  77. package/dist/src/internal/builtin-plugins/solidity/tasks/build.js.map +1 -1
  78. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts +1 -1
  79. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts.map +1 -1
  80. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js +1 -1
  81. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js.map +1 -1
  82. package/dist/src/internal/builtin-plugins/solidity-test/runner.d.ts +1 -1
  83. package/dist/src/internal/builtin-plugins/solidity-test/runner.js +1 -1
  84. package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
  85. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +16 -27
  86. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
  87. package/dist/src/internal/builtin-plugins/telemetry/task-action.d.ts.map +1 -1
  88. package/dist/src/internal/builtin-plugins/telemetry/task-action.js +3 -2
  89. package/dist/src/internal/builtin-plugins/telemetry/task-action.js.map +1 -1
  90. package/dist/src/internal/builtin-plugins/test/task-action.d.ts.map +1 -1
  91. package/dist/src/internal/builtin-plugins/test/task-action.js +40 -13
  92. package/dist/src/internal/builtin-plugins/test/task-action.js.map +1 -1
  93. package/dist/src/internal/builtin-plugins/test/type-extensions.d.ts +27 -0
  94. package/dist/src/internal/builtin-plugins/test/type-extensions.d.ts.map +1 -1
  95. package/dist/src/internal/cli/banner-manager.d.ts +26 -0
  96. package/dist/src/internal/cli/banner-manager.d.ts.map +1 -0
  97. package/dist/src/internal/cli/banner-manager.js +146 -0
  98. package/dist/src/internal/cli/banner-manager.js.map +1 -0
  99. package/dist/src/internal/cli/init/init.d.ts.map +1 -1
  100. package/dist/src/internal/cli/init/init.js +8 -0
  101. package/dist/src/internal/cli/init/init.js.map +1 -1
  102. package/dist/src/internal/cli/main.d.ts.map +1 -1
  103. package/dist/src/internal/cli/main.js +18 -1
  104. package/dist/src/internal/cli/main.js.map +1 -1
  105. package/dist/src/internal/cli/telemetry/analytics/subprocess.js +2 -0
  106. package/dist/src/internal/cli/telemetry/analytics/subprocess.js.map +1 -1
  107. package/dist/src/internal/cli/telemetry/sentry/anonymize-paths.js +1 -1
  108. package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.d.ts +1 -1
  109. package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.d.ts.map +1 -1
  110. package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.js +47 -38
  111. package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.js.map +1 -1
  112. package/dist/src/internal/core/user-interruptions.js +1 -1
  113. package/dist/src/types/artifacts.d.ts +32 -3
  114. package/dist/src/types/artifacts.d.ts.map +1 -1
  115. package/dist/src/types/network.d.ts +1 -1
  116. package/dist/src/types/solidity/build-system.d.ts +56 -10
  117. package/dist/src/types/solidity/build-system.d.ts.map +1 -1
  118. package/dist/src/types/solidity/build-system.js +26 -2
  119. package/dist/src/types/solidity/build-system.js.map +1 -1
  120. package/dist/src/types/solidity/resolved-file.d.ts +2 -2
  121. package/dist/src/types/tasks.d.ts +8 -0
  122. package/dist/src/types/tasks.d.ts.map +1 -1
  123. package/dist/src/types/tasks.js.map +1 -1
  124. package/dist/src/types/test.d.ts +11 -0
  125. package/dist/src/types/test.d.ts.map +1 -1
  126. package/dist/src/types/utils.d.ts +16 -0
  127. package/dist/src/types/utils.d.ts.map +1 -1
  128. package/dist/src/utils/result.d.ts +33 -0
  129. package/dist/src/utils/result.d.ts.map +1 -0
  130. package/dist/src/utils/result.js +43 -0
  131. package/dist/src/utils/result.js.map +1 -0
  132. package/package.json +4 -3
  133. package/src/internal/builtin-plugins/artifacts/artifact-manager.ts +4 -1
  134. package/src/internal/builtin-plugins/artifacts/hook-handlers/hre.ts +4 -1
  135. package/src/internal/builtin-plugins/coverage/helpers.ts +11 -29
  136. package/src/internal/builtin-plugins/coverage/hook-handlers/test.ts +68 -0
  137. package/src/internal/builtin-plugins/coverage/index.ts +1 -0
  138. package/src/internal/builtin-plugins/gas-analytics/helpers.ts +11 -29
  139. package/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.ts +68 -0
  140. package/src/internal/builtin-plugins/gas-analytics/index.ts +1 -0
  141. package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +21 -28
  142. package/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.ts +5 -2
  143. package/src/internal/builtin-plugins/network-manager/edr/type-validation.ts +0 -13
  144. package/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts +0 -64
  145. package/src/internal/builtin-plugins/solidity/build-results.ts +3 -1
  146. package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +15 -5
  147. package/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts +1 -1
  148. package/src/internal/builtin-plugins/solidity/build-system/dependency-graph.ts +1 -1
  149. package/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts +1 -1
  150. package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +36 -6
  151. package/src/internal/builtin-plugins/solidity/build-system/resolver/types.ts +3 -9
  152. package/src/internal/builtin-plugins/solidity/build-system/resolver/utils.ts +1 -1
  153. package/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts +125 -28
  154. package/src/internal/builtin-plugins/solidity/config.ts +2 -2
  155. package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +8 -0
  156. package/src/internal/builtin-plugins/solidity/tasks/build.ts +1 -1
  157. package/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts +2 -2
  158. package/src/internal/builtin-plugins/solidity-test/runner.ts +1 -1
  159. package/src/internal/builtin-plugins/solidity-test/task-action.ts +36 -38
  160. package/src/internal/builtin-plugins/telemetry/task-action.ts +4 -2
  161. package/src/internal/builtin-plugins/test/task-action.ts +71 -25
  162. package/src/internal/builtin-plugins/test/type-extensions.ts +42 -0
  163. package/src/internal/cli/banner-manager.ts +234 -0
  164. package/src/internal/cli/init/init.ts +8 -0
  165. package/src/internal/cli/main.ts +19 -1
  166. package/src/internal/cli/telemetry/analytics/subprocess.ts +2 -0
  167. package/src/internal/cli/telemetry/sentry/anonymize-paths.ts +1 -1
  168. package/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.ts +98 -50
  169. package/src/internal/core/user-interruptions.ts +1 -1
  170. package/src/types/artifacts.ts +40 -3
  171. package/src/types/hre.ts +1 -1
  172. package/src/types/network.ts +1 -1
  173. package/src/types/solidity/build-system.ts +75 -14
  174. package/src/types/solidity/resolved-file.ts +2 -2
  175. package/src/types/tasks.ts +10 -0
  176. package/src/types/test.ts +12 -0
  177. package/src/types/utils.ts +14 -0
  178. package/src/utils/result.ts +57 -0
  179. package/templates/hardhat-3/01-node-test-runner-viem/package.json +9 -9
  180. package/templates/hardhat-3/02-mocha-ethers/package.json +10 -10
  181. package/templates/hardhat-3/03-minimal/package.json +1 -1
  182. package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.d.ts +0 -19
  183. package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.d.ts.map +0 -1
  184. package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.js +0 -2
  185. package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.js.map +0 -1
  186. package/src/internal/builtin-plugins/network-manager/edr/types/output.ts +0 -19
@@ -1,44 +1,26 @@
1
- import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
2
-
3
- import { HardhatRuntimeEnvironmentImplementation } from "../../core/hre.js";
1
+ import {
2
+ testRunDone,
3
+ testRunStart,
4
+ testWorkerDone,
5
+ } from "./hook-handlers/test.js";
4
6
 
5
7
  /**
6
- * NOTE: The following helpers interact with the global HRE instance only;
7
- * This is OK because:
8
- * - They are intended for the internal use only. They are exposed via the
9
- * internal public API only.
10
- * - We know the HRE has been initialized by the time they are used.
8
+ * The following helpers are kept for backward compatibility with older versions
9
+ * of test runner plugins (hardhat-mocha, hardhat-node-test-runner) that import
10
+ * from "hardhat/internal/gas-analytics".
11
11
  */
12
12
 
13
13
  export async function markTestRunStart(id: string): Promise<void> {
14
14
  const { default: hre } = await import("../../../index.js");
15
- if (hre.globalOptions.gasStats === true) {
16
- assertHardhatInvariant(
17
- hre instanceof HardhatRuntimeEnvironmentImplementation,
18
- "Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation",
19
- );
20
- await hre._gasAnalytics.clearGasMeasurements(id);
21
- }
15
+ await testRunStart(hre, id);
22
16
  }
23
17
 
24
18
  export async function markTestWorkerDone(id: string): Promise<void> {
25
19
  const { default: hre } = await import("../../../index.js");
26
- if (hre.globalOptions.gasStats === true) {
27
- assertHardhatInvariant(
28
- hre instanceof HardhatRuntimeEnvironmentImplementation,
29
- "Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation",
30
- );
31
- await hre._gasAnalytics.saveGasMeasurements(id);
32
- }
20
+ await testWorkerDone(hre, id);
33
21
  }
34
22
 
35
23
  export async function markTestRunDone(id: string): Promise<void> {
36
24
  const { default: hre } = await import("../../../index.js");
37
- if (hre.globalOptions.gasStats === true) {
38
- assertHardhatInvariant(
39
- hre instanceof HardhatRuntimeEnvironmentImplementation,
40
- "Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation",
41
- );
42
- await hre._gasAnalytics.reportGasStats(id);
43
- }
25
+ await testRunDone(hre, id);
44
26
  }
@@ -0,0 +1,68 @@
1
+ import type { HookContext, TestHooks } from "../../../../types/hooks.js";
2
+
3
+ import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
4
+ import { isObject } from "@nomicfoundation/hardhat-utils/lang";
5
+
6
+ import { GasAnalyticsManagerImplementation } from "../gas-analytics-manager.js";
7
+
8
+ export default async (): Promise<Partial<TestHooks>> => ({
9
+ onTestRunStart: async (context, id, next) => {
10
+ await next(context, id);
11
+ await testRunStart(context, id);
12
+ },
13
+
14
+ onTestWorkerDone: async (context, id, next) => {
15
+ await next(context, id);
16
+ await testWorkerDone(context, id);
17
+ },
18
+
19
+ onTestRunDone: async (context, id, next) => {
20
+ await next(context, id);
21
+ await testRunDone(context, id);
22
+ },
23
+ });
24
+
25
+ export async function testRunStart(
26
+ context: HookContext,
27
+ id: string,
28
+ ): Promise<void> {
29
+ if (context.globalOptions.gasStats === true) {
30
+ assertHardhatInvariant(
31
+ "_gasAnalytics" in context &&
32
+ isObject(context._gasAnalytics) &&
33
+ context._gasAnalytics instanceof GasAnalyticsManagerImplementation,
34
+ "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation",
35
+ );
36
+ await context._gasAnalytics.clearGasMeasurements(id);
37
+ }
38
+ }
39
+
40
+ export async function testWorkerDone(
41
+ context: HookContext,
42
+ id: string,
43
+ ): Promise<void> {
44
+ if (context.globalOptions.gasStats === true) {
45
+ assertHardhatInvariant(
46
+ "_gasAnalytics" in context &&
47
+ isObject(context._gasAnalytics) &&
48
+ context._gasAnalytics instanceof GasAnalyticsManagerImplementation,
49
+ "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation",
50
+ );
51
+ await context._gasAnalytics.saveGasMeasurements(id);
52
+ }
53
+ }
54
+
55
+ export async function testRunDone(
56
+ context: HookContext,
57
+ id: string,
58
+ ): Promise<void> {
59
+ if (context.globalOptions.gasStats === true) {
60
+ assertHardhatInvariant(
61
+ "_gasAnalytics" in context &&
62
+ isObject(context._gasAnalytics) &&
63
+ context._gasAnalytics instanceof GasAnalyticsManagerImplementation,
64
+ "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation",
65
+ );
66
+ await context._gasAnalytics.reportGasStats(id);
67
+ }
68
+ }
@@ -16,6 +16,7 @@ const hardhatPlugin: HardhatPlugin = {
16
16
  ],
17
17
  hookHandlers: {
18
18
  hre: () => import("./hook-handlers/hre.js"),
19
+ test: () => import("./hook-handlers/test.js"),
19
20
  },
20
21
  npmPackage: "hardhat",
21
22
  };
@@ -1,4 +1,3 @@
1
- import type { SolidityStackTrace } from "./stack-traces/solidity-stack-trace.js";
2
1
  import type { CoverageConfig } from "./types/coverage.js";
3
2
  import type { LoggerConfig } from "./types/logger.js";
4
3
  import type {
@@ -63,14 +62,10 @@ import {
63
62
 
64
63
  import { EdrProviderStackTraceGenerationError } from "./stack-traces/stack-trace-generation-errors.js";
65
64
  import { createSolidityErrorWithStackTrace } from "./stack-traces/stack-trace-solidity-errors.js";
66
- import {
67
- isDebugTraceResult,
68
- isEdrProviderErrorData,
69
- } from "./type-validation.js";
65
+ import { isEdrProviderErrorData } from "./type-validation.js";
70
66
  import { clientVersion } from "./utils/client-version.js";
71
67
  import { ConsoleLogger } from "./utils/console-logger.js";
72
68
  import {
73
- edrRpcDebugTraceToHardhat,
74
69
  hardhatMiningIntervalToEdrMiningInterval,
75
70
  hardhatMempoolOrderToEdrMineOrdering,
76
71
  hardhatHardforkToEdrSpecId,
@@ -289,15 +284,6 @@ export class EdrProvider extends BaseProvider {
289
284
  "Invalid client version response",
290
285
  );
291
286
  return clientVersion(jsonRpcResponse.result);
292
- } else if (
293
- jsonRpcRequest.method === "debug_traceTransaction" ||
294
- jsonRpcRequest.method === "debug_traceCall"
295
- ) {
296
- assertHardhatInvariant(
297
- isDebugTraceResult(jsonRpcResponse.result),
298
- "Invalid debug trace response",
299
- );
300
- return edrRpcDebugTraceToHardhat(jsonRpcResponse.result);
301
287
  } else {
302
288
  return jsonRpcResponse.result;
303
289
  }
@@ -339,18 +325,9 @@ export class EdrProvider extends BaseProvider {
339
325
  const responseError = jsonRpcResponse.error;
340
326
  let error;
341
327
 
342
- let stackTrace: SolidityStackTrace | null = null;
343
- try {
344
- stackTrace = edrResponse.stackTrace();
345
- } catch (e) {
346
- if (e instanceof Error) {
347
- await sendErrorTelemetry(new EdrProviderStackTraceGenerationError(e));
348
- }
349
-
350
- log("Failed to get stack trace: %O", e);
351
- }
328
+ const stackTrace = edrResponse.stackTrace();
352
329
 
353
- if (stackTrace !== null) {
330
+ if (stackTrace?.kind === "StackTrace") {
354
331
  // If we have a stack trace, we know that the json rpc response data
355
332
  // is an object with the data and transactionHash fields
356
333
  assertHardhatInvariant(
@@ -360,11 +337,27 @@ export class EdrProvider extends BaseProvider {
360
337
 
361
338
  error = createSolidityErrorWithStackTrace(
362
339
  responseError.message,
363
- stackTrace,
340
+ stackTrace.entries,
364
341
  responseError.data.data,
365
342
  responseError.data.transactionHash,
366
343
  );
367
344
  } else {
345
+ if (stackTrace !== null) {
346
+ if (stackTrace.kind === "UnexpectedError") {
347
+ await sendErrorTelemetry(
348
+ new EdrProviderStackTraceGenerationError(stackTrace.errorMessage),
349
+ );
350
+ log(`Failed to get stack trace: ${stackTrace.errorMessage}`);
351
+ } else {
352
+ const errHeuristicFailed =
353
+ "Heuristic failed to generate stack trace";
354
+ await sendErrorTelemetry(
355
+ new EdrProviderStackTraceGenerationError(errHeuristicFailed),
356
+ );
357
+ log(`Failed to get stack trace: ${errHeuristicFailed}`);
358
+ }
359
+ }
360
+
368
361
  error =
369
362
  responseError.code === InvalidArgumentsError.CODE
370
363
  ? new InvalidArgumentsError(responseError.message)
@@ -373,7 +366,7 @@ export class EdrProvider extends BaseProvider {
373
366
  }
374
367
 
375
368
  /* eslint-disable-next-line no-restricted-syntax -- we may throw
376
- non-Hardaht errors inside of an EthereumProvider */
369
+ non-Hardhat errors inside of an EthereumProvider */
377
370
  throw error;
378
371
  }
379
372
 
@@ -3,8 +3,11 @@ import { CustomError } from "@nomicfoundation/hardhat-utils/error";
3
3
  abstract class StackTraceGenerationError extends CustomError {}
4
4
 
5
5
  export class EdrProviderStackTraceGenerationError extends StackTraceGenerationError {
6
- constructor(error: Error) {
7
- super("Failed to generate stack trace for the EDR provider", error);
6
+ constructor(message: string) {
7
+ super(
8
+ "Failed to generate stack trace for the EDR provider",
9
+ new Error(message),
10
+ );
8
11
  }
9
12
  }
10
13
 
@@ -1,18 +1,5 @@
1
- import type { DebugTraceResult } from "@nomicfoundation/edr";
2
-
3
1
  import { isObject } from "@nomicfoundation/hardhat-utils/lang";
4
2
 
5
- export function isDebugTraceResult(
6
- result: unknown,
7
- ): result is DebugTraceResult {
8
- return (
9
- isObject(result) &&
10
- "pass" in result &&
11
- "gasUsed" in result &&
12
- "structLogs" in result
13
- );
14
- }
15
-
16
3
  interface EdrProviderErrorData {
17
4
  data: string;
18
5
  transactionHash?: string;
@@ -9,10 +9,8 @@ import type {
9
9
  } from "../../../../../types/config.js";
10
10
  import type { ChainType } from "../../../../../types/network.js";
11
11
  import type { GasMeasurement } from "../../../gas-analytics/types.js";
12
- import type { RpcDebugTraceOutput, RpcStructLog } from "../types/output.js";
13
12
  import type {
14
13
  IntervalRange,
15
- DebugTraceResult,
16
14
  ChainOverride,
17
15
  ForkConfig,
18
16
  GasReport,
@@ -51,7 +49,6 @@ import {
51
49
  HOLOCENE,
52
50
  ISTHMUS,
53
51
  } from "@nomicfoundation/edr";
54
- import { getUnprefixedHexString } from "@nomicfoundation/hardhat-utils/hex";
55
52
 
56
53
  import {
57
54
  GENERIC_CHAIN_TYPE,
@@ -274,67 +271,6 @@ export function hardhatMempoolOrderToEdrMineOrdering(
274
271
  }
275
272
  }
276
273
 
277
- // TODO: EDR should handle this conversion. This is a temporary solution.
278
- export function edrRpcDebugTraceToHardhat(
279
- debugTraceResult: DebugTraceResult,
280
- ): RpcDebugTraceOutput {
281
- const structLogs = debugTraceResult.structLogs.map((log) => {
282
- const result: RpcStructLog = {
283
- depth: Number(log.depth),
284
- gas: Number(log.gas),
285
- gasCost: Number(log.gasCost),
286
- op: log.opName,
287
- pc: Number(log.pc),
288
- };
289
-
290
- if (log.memory !== undefined) {
291
- result.memory = log.memory;
292
- }
293
-
294
- if (log.stack !== undefined) {
295
- // Remove 0x prefix which is required by EIP-3155, but not expected by Hardhat.
296
- result.stack = log.stack.map(getUnprefixedHexString);
297
- }
298
-
299
- if (log.storage !== undefined) {
300
- result.storage = Object.fromEntries(
301
- Object.entries(log.storage).map(([key, value]) => [
302
- getUnprefixedHexString(key),
303
- getUnprefixedHexString(value),
304
- ]),
305
- );
306
- }
307
-
308
- if (log.error !== undefined) {
309
- result.error = {
310
- message: log.error,
311
- };
312
- }
313
-
314
- return result;
315
- });
316
-
317
- // REVM trace adds initial STOP that Hardhat doesn't expect
318
- // TODO: double check with EDR team that this is still the case
319
- if (structLogs.length > 0 && structLogs[0].op === "STOP") {
320
- structLogs.shift();
321
- }
322
-
323
- /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
324
- debugTraceResult.output is a string, but it's typed as Buffer in Edr */
325
- let returnValue = (debugTraceResult.output as unknown as string) ?? "0x";
326
- if (returnValue === "0x") {
327
- returnValue = "";
328
- }
329
-
330
- return {
331
- failed: !debugTraceResult.pass,
332
- gas: Number(debugTraceResult.gasUsed),
333
- returnValue,
334
- structLogs,
335
- };
336
- }
337
-
338
274
  export async function hardhatAccountsToEdrOwnedAccounts(
339
275
  accounts: EdrNetworkAccountsConfig,
340
276
  ): Promise<Array<{ secretKey: string; balance: bigint }>> {
@@ -2,6 +2,7 @@ import type {
2
2
  CompilationJobCreationError,
3
3
  FailedFileBuildResult,
4
4
  FileBuildResult,
5
+ SolidityBuildSystem,
5
6
  } from "../../../types/solidity.js";
6
7
 
7
8
  import { HardhatError } from "@nomicfoundation/hardhat-errors";
@@ -22,9 +23,10 @@ type SuccessfulSolidityBuildResults = Map<
22
23
  * job failed.
23
24
  */
24
25
  export function throwIfSolidityBuildFailed(
26
+ solidity: SolidityBuildSystem,
25
27
  results: SolidityBuildResults,
26
28
  ): asserts results is SuccessfulSolidityBuildResults {
27
- if ("reason" in results) {
29
+ if (!solidity.isSuccessfulBuildResult(results)) {
28
30
  throw new HardhatError(
29
31
  HardhatError.ERRORS.CORE.SOLIDITY.COMPILATION_JOB_CREATION_ERROR,
30
32
  {
@@ -208,6 +208,12 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
208
208
  }
209
209
  }
210
210
 
211
+ public isSuccessfulBuildResult(
212
+ buildResult: CompilationJobCreationError | Map<string, FileBuildResult>,
213
+ ): buildResult is Map<string, FileBuildResult> {
214
+ return buildResult instanceof Map;
215
+ }
216
+
211
217
  public async build(
212
218
  rootFilePaths: string[],
213
219
  _options?: BuildOptions,
@@ -244,7 +250,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
244
250
  options,
245
251
  );
246
252
 
247
- if ("reason" in compilationJobsResult) {
253
+ if (!compilationJobsResult.success) {
248
254
  return compilationJobsResult;
249
255
  }
250
256
 
@@ -430,7 +436,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
430
436
  const solcConfigSelector = new SolcConfigSelector(
431
437
  buildProfileName,
432
438
  buildProfile,
433
- dependencyGraph,
434
439
  );
435
440
 
436
441
  let subgraphsWithConfig: Array<
@@ -446,11 +451,11 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
446
451
  const configOrError =
447
452
  solcConfigSelector.selectBestSolcConfigForSingleRootGraph(subgraph);
448
453
 
449
- if ("reason" in configOrError) {
454
+ if (!configOrError.success) {
450
455
  return configOrError;
451
456
  }
452
457
 
453
- subgraphsWithConfig.push([configOrError, subgraph]);
458
+ subgraphsWithConfig.push([configOrError.config, subgraph]);
454
459
  }
455
460
 
456
461
  // get longVersion and isWasm from the compiler for each version
@@ -632,7 +637,12 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
632
637
  }
633
638
  }
634
639
 
635
- return { compilationJobsPerFile, indexedIndividualJobs, cacheHits };
640
+ return {
641
+ success: true,
642
+ compilationJobsPerFile,
643
+ indexedIndividualJobs,
644
+ cacheHits,
645
+ };
636
646
  }
637
647
 
638
648
  #getBuildProfile(buildProfileName: string = DEFAULT_BUILD_PROFILE) {
@@ -66,7 +66,7 @@ async function spawnCompile(
66
66
  );
67
67
 
68
68
  const stdoutPipeline = subprocess.stdout.pipe(stdoutWriteStream);
69
- // NOTE: Compiler warnings are NOT written to stder, they are returned via
69
+ // NOTE: Compiler warnings are NOT written to stderr, they are returned via
70
70
  // the `errors` field of the CompilerOutput instead
71
71
  const stderrPipeline = subprocess.stderr.pipe(
72
72
  createNonClosingWriter(process.stderr),
@@ -25,7 +25,7 @@ export class DependencyGraphImplementation implements DependencyGraph {
25
25
 
26
26
  /**
27
27
  * Adds a root file to the graph. All the roots of the dependency graph must
28
- * be added before any dependencry.
28
+ * be added before any dependency.
29
29
  *
30
30
  * @param userSourceName The source name used to identify the file, as it
31
31
  * would appear in the artifacts and used by the user. This is not always the
@@ -4,7 +4,6 @@ import type {
4
4
  Remapping,
5
5
  ResolvedNpmUserRemapping,
6
6
  ResolvedUserRemapping,
7
- Result,
8
7
  } from "./types.js";
9
8
  import type {
10
9
  ImportResolutionError,
@@ -20,6 +19,7 @@ import type {
20
19
  ProjectResolvedFile,
21
20
  NpmPackageResolvedFile,
22
21
  } from "../../../../../types/solidity/resolved-file.js";
22
+ import type { Result } from "../../../../../types/utils.js";
23
23
 
24
24
  import path from "node:path";
25
25
 
@@ -7,13 +7,13 @@ import type {
7
7
  ResolvedUserRemapping,
8
8
  UnresolvedNpmUserRemapping,
9
9
  RemappedNpmPackagesGraphJson,
10
- Result,
11
10
  } from "./types.js";
12
11
  import type {
13
12
  ResolvedFile,
14
13
  ResolvedNpmPackage,
15
14
  UserRemappingError,
16
15
  } from "../../../../../types/solidity.js";
16
+ import type { Result } from "../../../../../types/utils.js";
17
17
 
18
18
  import path from "node:path";
19
19
 
@@ -37,6 +37,32 @@ import { UserRemappingType } from "./types.js";
37
37
 
38
38
  const HARDHAT_PROJECT_INPUT_SOURCE_NAME_ROOT = "project";
39
39
 
40
+ /**
41
+ * Returns a normalized version of the path if it refers to a node_modules in
42
+ * the root directory (i.e. node_modules/...), or a `node_modules` directory
43
+ * in a parent directory (i.e. ../../node_modules/...).
44
+ *
45
+ * Otherwise returns `undefined`.
46
+ *
47
+ * @param pathToNormalize The path to normalize.
48
+ * @returns The normalized path (node_modules/...), or `undefined`.
49
+ */
50
+ export function getNormalizeNodeModulesPath(
51
+ pathToNormalize: string,
52
+ ): string | undefined {
53
+ if (pathToNormalize.startsWith("node_modules/")) {
54
+ return pathToNormalize;
55
+ }
56
+
57
+ const normalized = path.posix.normalize(pathToNormalize);
58
+
59
+ if (!/^(?:\.\.\/)*node_modules\//.test(normalized)) {
60
+ return undefined;
61
+ }
62
+
63
+ return normalized.substring(normalized.indexOf("node_modules/"));
64
+ }
65
+
40
66
  export type RemappingsReaderFunction = (
41
67
  packageName: string,
42
68
  packageVersion: string,
@@ -559,7 +585,7 @@ export class RemappedNpmPackagesGraphImplementation
559
585
  const prefix = remapping.prefix.endsWith("/")
560
586
  ? remapping.prefix
561
587
  : remapping.prefix + "/";
562
- const target = remapping.target.endsWith("/")
588
+ let target = remapping.target.endsWith("/")
563
589
  ? remapping.target
564
590
  : remapping.target + "/";
565
591
 
@@ -568,12 +594,13 @@ export class RemappedNpmPackagesGraphImplementation
568
594
  path.dirname(sourceOfTheRemapping),
569
595
  );
570
596
 
571
- // If the remapping's target starts with `node_modules/`, we treat
572
- // it as trying to load an npm dependency, otherwise we treat it as a local
597
+ // If the remapping's target starts with `node_modules/`, we treat it as
598
+ // trying to load an npm dependency, otherwise we treat it as a local
573
599
  // remapping.
600
+ const normalizedNodeModulesTarget = getNormalizeNodeModulesPath(target);
574
601
 
575
602
  // Local remapping case
576
- if (!target.startsWith("node_modules/")) {
603
+ if (normalizedNodeModulesTarget === undefined) {
577
604
  return {
578
605
  success: true,
579
606
  value: {
@@ -593,6 +620,9 @@ export class RemappedNpmPackagesGraphImplementation
593
620
  source: sourceOfTheRemapping,
594
621
  },
595
622
  };
623
+ } else {
624
+ // We update the target to the normalized version
625
+ target = normalizedNodeModulesTarget;
596
626
  }
597
627
 
598
628
  // If we are here the remapping is a npm remapping.
@@ -600,7 +630,7 @@ export class RemappedNpmPackagesGraphImplementation
600
630
  const targetWithoutNodeModules = target.substring("node_modules/".length);
601
631
 
602
632
  // If after doing that the prefix and target are the same, we skip it
603
- // so that it doesn't even go unnecesarly go through a user remapping.
633
+ // so that it doesn't even go unnecessarily go through a user remapping.
604
634
  if (prefix === targetWithoutNodeModules) {
605
635
  return { success: true, value: undefined };
606
636
  }
@@ -10,13 +10,7 @@ import type {
10
10
  ResolvedFile,
11
11
  ResolvedNpmPackage,
12
12
  } from "../../../../../types/solidity/resolved-file.js";
13
-
14
- /**
15
- * A result that can either have a value or an error.
16
- */
17
- export type Result<ValueT, ErrorT> =
18
- | { readonly success: true; readonly value: ValueT }
19
- | { readonly success: false; readonly error: ErrorT };
13
+ import type { Result } from "../../../../../types/utils.js";
20
14
 
21
15
  /**
22
16
  * A solc remapping.
@@ -96,7 +90,7 @@ export type InstallationName = string;
96
90
 
97
91
  /**
98
92
  * This interface represents a graph of all the npm packages that the Hardhat
99
- * project uses, including the Hardhat projecct itself, and their remappings.
93
+ * project uses, including the Hardhat project itself, and their remappings.
100
94
  *
101
95
  * This class guarantees that there's a single instance of any npm package per
102
96
  * each version. That means that, even if you have multiple installations of
@@ -109,7 +103,7 @@ export type InstallationName = string;
109
103
  * than expected, because:
110
104
  * - Processing a remapping may require loading a new npm package, and this
111
105
  * interface ensures its uniqueness.
112
- * - Loading an npm package requires processing its remappigns.
106
+ * - Loading an npm package requires processing its remappings.
113
107
  * - Selecting the best user remapping for an import can require processing it
114
108
  * and loading its npm package.
115
109
  *
@@ -1,5 +1,5 @@
1
- import type { Result } from "./types.js";
2
1
  import type { ResolvedNpmPackage } from "../../../../../types/solidity.js";
2
+ import type { Result } from "../../../../../types/utils.js";
3
3
 
4
4
  import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
5
5
  import { ensureError } from "@nomicfoundation/hardhat-utils/error";