hardhat 2.13.0-dev.2 → 2.13.0-dev.3

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 (292) hide show
  1. package/builtin-tasks/compile.js +16 -6
  2. package/builtin-tasks/compile.js.map +1 -1
  3. package/builtin-tasks/flatten.js +1 -1
  4. package/builtin-tasks/flatten.js.map +1 -1
  5. package/builtin-tasks/help.js +2 -4
  6. package/builtin-tasks/help.js.map +1 -1
  7. package/builtin-tasks/task-names.d.ts +1 -0
  8. package/builtin-tasks/task-names.d.ts.map +1 -1
  9. package/builtin-tasks/task-names.js +3 -2
  10. package/builtin-tasks/task-names.js.map +1 -1
  11. package/builtin-tasks/test.js +22 -1
  12. package/builtin-tasks/test.js.map +1 -1
  13. package/internal/cli/bootstrap.d.ts +1 -0
  14. package/internal/cli/bootstrap.js +12 -20
  15. package/internal/cli/bootstrap.js.map +1 -1
  16. package/internal/cli/cli.d.ts +0 -1
  17. package/internal/cli/cli.d.ts.map +1 -1
  18. package/internal/cli/cli.js +20 -29
  19. package/internal/cli/cli.js.map +1 -1
  20. package/internal/cli/project-creation.d.ts +1 -2
  21. package/internal/cli/project-creation.d.ts.map +1 -1
  22. package/internal/cli/project-creation.js +105 -36
  23. package/internal/cli/project-creation.js.map +1 -1
  24. package/internal/cli/prompt.d.ts +2 -2
  25. package/internal/cli/prompt.d.ts.map +1 -1
  26. package/internal/cli/prompt.js +1 -2
  27. package/internal/cli/prompt.js.map +1 -1
  28. package/internal/cli/types.d.ts +1 -0
  29. package/internal/cli/types.d.ts.map +1 -1
  30. package/internal/core/config/config-env.d.ts +5 -11
  31. package/internal/core/config/config-env.d.ts.map +1 -1
  32. package/internal/core/config/config-env.js +2 -13
  33. package/internal/core/config/config-env.js.map +1 -1
  34. package/internal/core/config/config-loading.d.ts +2 -1
  35. package/internal/core/config/config-loading.d.ts.map +1 -1
  36. package/internal/core/config/config-loading.js +25 -7
  37. package/internal/core/config/config-loading.js.map +1 -1
  38. package/internal/core/config/config-validation.d.ts +2 -0
  39. package/internal/core/config/config-validation.d.ts.map +1 -1
  40. package/internal/core/config/config-validation.js +18 -1
  41. package/internal/core/config/config-validation.js.map +1 -1
  42. package/internal/core/config/extenders.d.ts +4 -7
  43. package/internal/core/config/extenders.d.ts.map +1 -1
  44. package/internal/core/config/extenders.js +5 -12
  45. package/internal/core/config/extenders.js.map +1 -1
  46. package/internal/core/errors-list.d.ts +28 -7
  47. package/internal/core/errors-list.d.ts.map +1 -1
  48. package/internal/core/errors-list.js +33 -10
  49. package/internal/core/errors-list.js.map +1 -1
  50. package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
  51. package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
  52. package/internal/core/project-structure.d.ts.map +1 -1
  53. package/internal/core/project-structure.js +6 -0
  54. package/internal/core/project-structure.js.map +1 -1
  55. package/internal/core/providers/construction.d.ts.map +1 -1
  56. package/internal/core/providers/construction.js +25 -5
  57. package/internal/core/providers/construction.js.map +1 -1
  58. package/internal/core/providers/http.d.ts +2 -2
  59. package/internal/core/providers/http.d.ts.map +1 -1
  60. package/internal/core/providers/http.js +41 -19
  61. package/internal/core/providers/http.js.map +1 -1
  62. package/internal/core/runtime-environment.d.ts +4 -2
  63. package/internal/core/runtime-environment.d.ts.map +1 -1
  64. package/internal/core/runtime-environment.js +39 -47
  65. package/internal/core/runtime-environment.js.map +1 -1
  66. package/internal/core/tasks/dsl.d.ts +6 -6
  67. package/internal/core/tasks/dsl.d.ts.map +1 -1
  68. package/internal/core/tasks/dsl.js.map +1 -1
  69. package/internal/core/tasks/task-definitions.d.ts +2 -2
  70. package/internal/core/tasks/task-definitions.d.ts.map +1 -1
  71. package/internal/core/tasks/task-definitions.js.map +1 -1
  72. package/internal/hardhat-network/jsonrpc/handler.d.ts +1 -0
  73. package/internal/hardhat-network/jsonrpc/handler.d.ts.map +1 -1
  74. package/internal/hardhat-network/jsonrpc/handler.js +13 -18
  75. package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
  76. package/internal/hardhat-network/provider/RethnetState.d.ts +26 -0
  77. package/internal/hardhat-network/provider/RethnetState.d.ts.map +1 -0
  78. package/internal/hardhat-network/provider/RethnetState.js +84 -0
  79. package/internal/hardhat-network/provider/RethnetState.js.map +1 -0
  80. package/internal/hardhat-network/provider/modules/evm.d.ts +2 -1
  81. package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
  82. package/internal/hardhat-network/provider/modules/evm.js +10 -4
  83. package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
  84. package/internal/hardhat-network/provider/node-types.d.ts +1 -1
  85. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  86. package/internal/hardhat-network/provider/node.d.ts +1 -0
  87. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  88. package/internal/hardhat-network/provider/node.js +6 -4
  89. package/internal/hardhat-network/provider/node.js.map +1 -1
  90. package/internal/hardhat-network/provider/provider.d.ts +25 -21
  91. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  92. package/internal/hardhat-network/provider/provider.js +25 -42
  93. package/internal/hardhat-network/provider/provider.js.map +1 -1
  94. package/internal/hardhat-network/provider/return-data.js +2 -2
  95. package/internal/hardhat-network/provider/return-data.js.map +1 -1
  96. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  97. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +4 -2
  98. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  99. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  100. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +4 -2
  101. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  102. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  103. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +4 -2
  104. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  105. package/internal/hardhat-network/provider/utils/bloom.d.ts +32 -0
  106. package/internal/hardhat-network/provider/utils/bloom.d.ts.map +1 -0
  107. package/internal/hardhat-network/provider/utils/bloom.js +79 -0
  108. package/internal/hardhat-network/provider/utils/bloom.js.map +1 -0
  109. package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts +12 -0
  110. package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts.map +1 -0
  111. package/internal/hardhat-network/provider/utils/convertToRethnet.js +162 -0
  112. package/internal/hardhat-network/provider/utils/convertToRethnet.js.map +1 -0
  113. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +7 -0
  114. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -0
  115. package/internal/hardhat-network/provider/utils/makeFakeSignature.js +31 -0
  116. package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -0
  117. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +1 -1
  118. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  119. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -2
  120. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  121. package/internal/hardhat-network/provider/vm/block-builder.d.ts +31 -0
  122. package/internal/hardhat-network/provider/vm/block-builder.d.ts.map +1 -0
  123. package/internal/hardhat-network/provider/vm/block-builder.js +151 -0
  124. package/internal/hardhat-network/provider/vm/block-builder.js.map +1 -0
  125. package/internal/hardhat-network/provider/vm/creation.d.ts +10 -0
  126. package/internal/hardhat-network/provider/vm/creation.d.ts.map +1 -0
  127. package/internal/hardhat-network/provider/vm/creation.js +29 -0
  128. package/internal/hardhat-network/provider/vm/creation.js.map +1 -0
  129. package/internal/hardhat-network/provider/vm/dual.d.ts +43 -0
  130. package/internal/hardhat-network/provider/vm/dual.d.ts.map +1 -0
  131. package/internal/hardhat-network/provider/vm/dual.js +488 -0
  132. package/internal/hardhat-network/provider/vm/dual.js.map +1 -0
  133. package/internal/hardhat-network/provider/vm/ethereumjs.d.ts +56 -0
  134. package/internal/hardhat-network/provider/vm/ethereumjs.d.ts.map +1 -0
  135. package/internal/hardhat-network/provider/vm/ethereumjs.js +416 -0
  136. package/internal/hardhat-network/provider/vm/ethereumjs.js.map +1 -0
  137. package/internal/hardhat-network/provider/vm/exit.d.ts +23 -0
  138. package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
  139. package/internal/hardhat-network/provider/vm/exit.js +130 -0
  140. package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
  141. package/internal/hardhat-network/provider/vm/rethnet.d.ts +99 -0
  142. package/internal/hardhat-network/provider/vm/rethnet.d.ts.map +1 -0
  143. package/internal/hardhat-network/provider/vm/rethnet.js +284 -0
  144. package/internal/hardhat-network/provider/vm/rethnet.js.map +1 -0
  145. package/internal/hardhat-network/provider/vm/vm-adapter.d.ts +52 -0
  146. package/internal/hardhat-network/provider/vm/vm-adapter.d.ts.map +1 -0
  147. package/internal/hardhat-network/provider/vm/vm-adapter.js +3 -0
  148. package/internal/hardhat-network/provider/vm/vm-adapter.js.map +1 -0
  149. package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts.map +1 -1
  150. package/internal/hardhat-network/stack-traces/compiler-to-model.js +37 -11
  151. package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
  152. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  153. package/internal/hardhat-network/stack-traces/constants.d.ts +1 -1
  154. package/internal/hardhat-network/stack-traces/constants.js +1 -1
  155. package/internal/hardhat-network/stack-traces/debug.d.ts.map +1 -1
  156. package/internal/hardhat-network/stack-traces/debug.js +6 -2
  157. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  158. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +1 -0
  159. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  160. package/internal/hardhat-network/stack-traces/error-inferrer.js +85 -55
  161. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  162. package/internal/hardhat-network/stack-traces/model.d.ts +3 -1
  163. package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
  164. package/internal/hardhat-network/stack-traces/model.js +9 -1
  165. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  166. package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
  167. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  168. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +2 -2
  169. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
  170. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  171. package/internal/hardhat-network/stack-traces/solidityTracer.js +1 -0
  172. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  173. package/internal/lib/hardhat-lib.d.ts.map +1 -1
  174. package/internal/lib/hardhat-lib.js +1 -4
  175. package/internal/lib/hardhat-lib.js.map +1 -1
  176. package/internal/solidity/compiler/downloader.js +2 -2
  177. package/internal/solidity/compiler/downloader.js.map +1 -1
  178. package/internal/solidity/compiler/index.js +1 -1
  179. package/internal/solidity/compiler/index.js.map +1 -1
  180. package/internal/solidity/resolver.d.ts +4 -3
  181. package/internal/solidity/resolver.d.ts.map +1 -1
  182. package/internal/solidity/resolver.js +18 -7
  183. package/internal/solidity/resolver.js.map +1 -1
  184. package/internal/util/abi-helpers.d.ts +1 -0
  185. package/internal/util/abi-helpers.d.ts.map +1 -1
  186. package/internal/util/abi-helpers.js +9 -0
  187. package/internal/util/abi-helpers.js.map +1 -1
  188. package/internal/util/download.d.ts.map +1 -1
  189. package/internal/util/download.js +12 -11
  190. package/internal/util/download.js.map +1 -1
  191. package/internal/util/packageInfo.d.ts +6 -1
  192. package/internal/util/packageInfo.d.ts.map +1 -1
  193. package/internal/util/packageInfo.js +14 -11
  194. package/internal/util/packageInfo.js.map +1 -1
  195. package/internal/util/proxy.d.ts +2 -0
  196. package/internal/util/proxy.d.ts.map +1 -0
  197. package/internal/util/proxy.js +19 -0
  198. package/internal/util/proxy.js.map +1 -0
  199. package/package.json +9 -10
  200. package/register.js +1 -4
  201. package/register.js.map +1 -1
  202. package/sample-projects/javascript/hardhat.config.js +1 -1
  203. package/sample-projects/javascript/scripts/deploy.js +2 -2
  204. package/sample-projects/javascript-esm/LICENSE.md +11 -0
  205. package/sample-projects/javascript-esm/README.md +13 -0
  206. package/sample-projects/javascript-esm/contracts/Lock.sol +34 -0
  207. package/sample-projects/javascript-esm/hardhat.config.cjs +6 -0
  208. package/sample-projects/javascript-esm/scripts/deploy.js +22 -0
  209. package/sample-projects/javascript-esm/test/Lock.js +123 -0
  210. package/sample-projects/typescript/hardhat.config.ts +1 -1
  211. package/sample-projects/typescript/scripts/deploy.ts +2 -2
  212. package/sample-projects/typescript/tsconfig.json +2 -1
  213. package/src/builtin-tasks/compile.ts +28 -7
  214. package/src/builtin-tasks/flatten.ts +4 -1
  215. package/src/builtin-tasks/help.ts +15 -16
  216. package/src/builtin-tasks/task-names.ts +2 -0
  217. package/src/builtin-tasks/test.ts +30 -2
  218. package/src/internal/artifacts.ts +947 -0
  219. package/src/internal/cli/bootstrap.ts +14 -36
  220. package/src/internal/cli/cli.ts +38 -43
  221. package/src/internal/cli/project-creation.ts +128 -47
  222. package/src/internal/cli/prompt.ts +2 -4
  223. package/src/internal/cli/types.ts +2 -0
  224. package/src/internal/core/config/config-env.ts +15 -27
  225. package/src/internal/core/config/config-loading.ts +35 -11
  226. package/src/internal/core/config/config-validation.ts +20 -0
  227. package/src/internal/core/config/extenders.ts +6 -15
  228. package/src/internal/core/errors-list.ts +36 -10
  229. package/src/internal/core/project-structure.ts +8 -0
  230. package/src/internal/core/providers/construction.ts +29 -24
  231. package/src/internal/core/providers/http.ts +38 -26
  232. package/src/internal/core/runtime-environment.ts +65 -60
  233. package/src/internal/core/tasks/dsl.ts +17 -17
  234. package/src/internal/core/tasks/task-definitions.ts +6 -2
  235. package/src/internal/hardhat-network/jsonrpc/handler.ts +31 -28
  236. package/src/internal/hardhat-network/provider/modules/evm.ts +15 -3
  237. package/src/internal/hardhat-network/provider/node-types.ts +1 -1
  238. package/src/internal/hardhat-network/provider/node.ts +5 -1
  239. package/src/internal/hardhat-network/provider/provider.ts +60 -49
  240. package/src/internal/hardhat-network/provider/return-data.ts +2 -2
  241. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +5 -2
  242. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +5 -2
  243. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +5 -2
  244. package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +46 -0
  245. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +2 -2
  246. package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +71 -9
  247. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +1 -1
  248. package/src/internal/hardhat-network/stack-traces/constants.ts +1 -1
  249. package/src/internal/hardhat-network/stack-traces/debug.ts +9 -2
  250. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +177 -89
  251. package/src/internal/hardhat-network/stack-traces/model.ts +11 -1
  252. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
  253. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +2 -2
  254. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +3 -0
  255. package/src/internal/lib/hardhat-lib.ts +1 -6
  256. package/src/internal/solidity/compiler/downloader.ts +2 -2
  257. package/src/internal/solidity/compiler/index.ts +1 -1
  258. package/src/internal/solidity/resolver.ts +28 -11
  259. package/src/internal/util/abi-helpers.ts +9 -0
  260. package/src/internal/util/download.ts +13 -15
  261. package/src/internal/util/packageInfo.ts +24 -10
  262. package/src/internal/util/proxy.ts +18 -0
  263. package/src/register.ts +1 -6
  264. package/src/types/artifacts.ts +14 -112
  265. package/src/types/config.ts +2 -0
  266. package/src/types/runtime.ts +16 -13
  267. package/types/artifacts.d.ts +10 -96
  268. package/types/artifacts.d.ts.map +1 -1
  269. package/types/config.d.ts +2 -0
  270. package/types/config.d.ts.map +1 -1
  271. package/types/runtime.d.ts +9 -10
  272. package/types/runtime.d.ts.map +1 -1
  273. package/internal/artifacts/caching.d.ts +0 -28
  274. package/internal/artifacts/caching.d.ts.map +0 -1
  275. package/internal/artifacts/caching.js +0 -178
  276. package/internal/artifacts/caching.js.map +0 -1
  277. package/internal/artifacts/index.d.ts +0 -45
  278. package/internal/artifacts/index.d.ts.map +0 -1
  279. package/internal/artifacts/index.js +0 -191
  280. package/internal/artifacts/index.js.map +0 -1
  281. package/internal/artifacts/mutable.d.ts +0 -29
  282. package/internal/artifacts/mutable.d.ts.map +0 -1
  283. package/internal/artifacts/mutable.js +0 -226
  284. package/internal/artifacts/mutable.js.map +0 -1
  285. package/internal/artifacts/readonly.d.ts +0 -94
  286. package/internal/artifacts/readonly.d.ts.map +0 -1
  287. package/internal/artifacts/readonly.js +0 -343
  288. package/internal/artifacts/readonly.js.map +0 -1
  289. package/src/internal/artifacts/caching.ts +0 -259
  290. package/src/internal/artifacts/index.ts +0 -302
  291. package/src/internal/artifacts/mutable.ts +0 -330
  292. package/src/internal/artifacts/readonly.ts +0 -470
@@ -1,7 +1,9 @@
1
+ /* eslint "@typescript-eslint/no-non-null-assertion": "error" */
1
2
  import { ERROR } from "@nomicfoundation/ethereumjs-evm/dist/exceptions";
2
3
  import { defaultAbiCoder as abi } from "@ethersproject/abi";
3
4
  import semver from "semver";
4
5
 
6
+ import { assertHardhatInvariant } from "../../core/errors";
5
7
  import { AbiHelpers } from "../../util/abi-helpers";
6
8
  import { ReturnData } from "../provider/return-data";
7
9
 
@@ -69,13 +71,16 @@ export class ErrorInferrer {
69
71
  trace.calldata.slice(0, 4)
70
72
  );
71
73
 
72
- if (this._isFunctionNotPayableError(trace, calledFunction)) {
74
+ if (
75
+ calledFunction !== undefined &&
76
+ this._isFunctionNotPayableError(trace, calledFunction)
77
+ ) {
73
78
  return [
74
79
  {
75
80
  type: StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR,
76
81
  sourceReference: this._getFunctionStartSourceReference(
77
82
  trace,
78
- calledFunction!
83
+ calledFunction
79
84
  ),
80
85
  value: trace.value,
81
86
  },
@@ -197,8 +202,9 @@ export class ErrorInferrer {
197
202
  stacktrace[i + 2].type === StackTraceEntryType.RETURNDATA_SIZE_ERROR
198
203
  ) {
199
204
  // ! below for tsc. we confirmed existence in the enclosing conditional.
200
- const thatSrcRef = stacktrace[i + 2].sourceReference!;
205
+ const thatSrcRef = stacktrace[i + 2].sourceReference;
201
206
  if (
207
+ thatSrcRef !== undefined &&
202
208
  frame.sourceReference.range[0] === thatSrcRef.range[0] &&
203
209
  frame.sourceReference.range[1] === thatSrcRef.range[1] &&
204
210
  frame.sourceReference.line === thatSrcRef.line
@@ -286,7 +292,11 @@ export class ErrorInferrer {
286
292
  lastSubmessageData.stepIndex
287
293
  )
288
294
  ) {
289
- const lastFrame = inferredStacktrace.pop()!;
295
+ const lastFrame = inferredStacktrace.pop();
296
+ assertHardhatInvariant(
297
+ lastFrame !== undefined,
298
+ "Expected inferred stack trace to have at least one frame"
299
+ );
290
300
  inferredStacktrace.push({
291
301
  type: StackTraceEntryType.CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR,
292
302
  sourceReference: lastFrame.sourceReference,
@@ -421,13 +431,23 @@ export class ErrorInferrer {
421
431
  );
422
432
  } else if (isDecodedCallTrace(trace)) {
423
433
  // This is here because of the optimizations
434
+ const functionSelector =
435
+ trace.bytecode.contract.getFunctionFromSelector(
436
+ trace.calldata.slice(0, 4)
437
+ );
438
+
439
+ // in general this shouldn't happen, but it does when viaIR is enabled,
440
+ // "optimizerSteps": "u" is used, and the called function is fallback or
441
+ // receive
442
+ if (functionSelector === undefined) {
443
+ return;
444
+ }
445
+
424
446
  inferredStacktrace.push({
425
447
  type: StackTraceEntryType.REVERT_ERROR,
426
448
  sourceReference: this._getFunctionStartSourceReference(
427
449
  trace,
428
- trace.bytecode.contract.getFunctionFromSelector(
429
- trace.calldata.slice(0, 4)
430
- )!
450
+ functionSelector
431
451
  ),
432
452
  message: new ReturnData(trace.returnData),
433
453
  isInvalidOpcodeError: lastInstruction.opcode === Opcode.INVALID,
@@ -617,15 +637,21 @@ export class ErrorInferrer {
617
637
  );
618
638
 
619
639
  if (calledFunction !== undefined) {
620
- return [
621
- {
622
- type: StackTraceEntryType.INVALID_PARAMS_ERROR,
623
- sourceReference: this._getFunctionStartSourceReference(
624
- trace,
625
- calledFunction
626
- ),
627
- },
628
- ];
640
+ const isValidCalldata = calledFunction.isValidCalldata(
641
+ trace.calldata.slice(4)
642
+ );
643
+
644
+ if (!isValidCalldata) {
645
+ return [
646
+ {
647
+ type: StackTraceEntryType.INVALID_PARAMS_ERROR,
648
+ sourceReference: this._getFunctionStartSourceReference(
649
+ trace,
650
+ calledFunction
651
+ ),
652
+ },
653
+ ];
654
+ }
629
655
  }
630
656
 
631
657
  if (this._solidity063MaybeUnmappedRevert(trace)) {
@@ -646,10 +672,17 @@ export class ErrorInferrer {
646
672
  stacktrace: SolidityStackTrace
647
673
  ): SolidityStackTrace | undefined {
648
674
  if (this._isCalledNonContractAccountError(trace)) {
675
+ const sourceReference = this._getLastSourceReference(trace);
676
+
677
+ // We are sure this is not undefined because there was at least a call instruction
678
+ assertHardhatInvariant(
679
+ sourceReference !== undefined,
680
+ "Expected source reference to be defined"
681
+ );
682
+
649
683
  const nonContractCalledFrame: SolidityStackTraceEntry = {
650
684
  type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR,
651
- // We are sure this is not undefined because there was at least a call instruction
652
- sourceReference: this._getLastSourceReference(trace)!,
685
+ sourceReference,
653
686
  };
654
687
 
655
688
  return [...stacktrace, nonContractCalledFrame];
@@ -749,12 +782,8 @@ export class ErrorInferrer {
749
782
 
750
783
  private _isFunctionNotPayableError(
751
784
  trace: DecodedCallMessageTrace,
752
- calledFunction: ContractFunction | undefined
785
+ calledFunction: ContractFunction
753
786
  ): boolean {
754
- if (calledFunction === undefined) {
755
- return false;
756
- }
757
-
758
787
  // This error doesn't return data
759
788
  if (trace.returnData.length > 0) {
760
789
  return false;
@@ -1057,7 +1086,14 @@ export class ErrorInferrer {
1057
1086
  continue;
1058
1087
  }
1059
1088
 
1060
- return sourceLocationToSourceReference(trace.bytecode, inst.location);
1089
+ const sourceReference = sourceLocationToSourceReference(
1090
+ trace.bytecode,
1091
+ inst.location
1092
+ );
1093
+
1094
+ if (sourceReference !== undefined) {
1095
+ return sourceReference;
1096
+ }
1061
1097
  }
1062
1098
 
1063
1099
  return undefined;
@@ -1105,27 +1141,49 @@ export class ErrorInferrer {
1105
1141
  trace: DecodedEvmMessageTrace,
1106
1142
  inst: Instruction
1107
1143
  ): RevertErrorStackTraceEntry {
1144
+ const sourceReference = sourceLocationToSourceReference(
1145
+ trace.bytecode,
1146
+ inst.location
1147
+ );
1148
+ assertHardhatInvariant(
1149
+ sourceReference !== undefined,
1150
+ "Expected source reference to be defined"
1151
+ );
1152
+
1108
1153
  return {
1109
1154
  type: StackTraceEntryType.REVERT_ERROR,
1110
- sourceReference: sourceLocationToSourceReference(
1111
- trace.bytecode,
1112
- inst.location
1113
- )!,
1155
+ sourceReference,
1114
1156
  message: new ReturnData(trace.returnData),
1115
1157
  isInvalidOpcodeError: inst.opcode === Opcode.INVALID,
1116
1158
  };
1117
1159
  }
1118
1160
 
1161
+ private _instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1162
+ trace: DecodedEvmMessageTrace,
1163
+ inst: Instruction
1164
+ ): UnmappedSolc063RevertErrorStackTraceEntry {
1165
+ const sourceReference = sourceLocationToSourceReference(
1166
+ trace.bytecode,
1167
+ inst.location
1168
+ );
1169
+
1170
+ return {
1171
+ type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1172
+ sourceReference,
1173
+ };
1174
+ }
1175
+
1119
1176
  private _instructionWithinFunctionToPanicStackTraceEntry(
1120
1177
  trace: DecodedEvmMessageTrace,
1121
1178
  inst: Instruction,
1122
1179
  errorCode: bigint
1123
1180
  ): PanicErrorStackTraceEntry {
1181
+ const lastSourceReference = this._getLastSourceReference(trace);
1124
1182
  return {
1125
1183
  type: StackTraceEntryType.PANIC_ERROR,
1126
1184
  sourceReference:
1127
1185
  sourceLocationToSourceReference(trace.bytecode, inst.location) ??
1128
- this._getLastSourceReference(trace)!,
1186
+ lastSourceReference,
1129
1187
  errorCode,
1130
1188
  };
1131
1189
  }
@@ -1135,11 +1193,18 @@ export class ErrorInferrer {
1135
1193
  inst: Instruction,
1136
1194
  message: string
1137
1195
  ): CustomErrorStackTraceEntry {
1196
+ const lastSourceReference = this._getLastSourceReference(trace);
1197
+
1198
+ assertHardhatInvariant(
1199
+ lastSourceReference !== undefined,
1200
+ "Expected last source reference to be defined"
1201
+ );
1202
+
1138
1203
  return {
1139
1204
  type: StackTraceEntryType.CUSTOM_ERROR,
1140
1205
  sourceReference:
1141
1206
  sourceLocationToSourceReference(trace.bytecode, inst.location) ??
1142
- this._getLastSourceReference(trace)!,
1207
+ lastSourceReference,
1143
1208
  message,
1144
1209
  };
1145
1210
  }
@@ -1251,16 +1316,16 @@ export class ErrorInferrer {
1251
1316
  ): UnmappedSolc063RevertErrorStackTraceEntry | undefined {
1252
1317
  // If we are within a function there's a last valid location. It may
1253
1318
  // be the entire contract.
1254
- const prevInst = this._getLastInstructionWithValidLocation(trace)!;
1319
+ const prevInst = this._getLastInstructionWithValidLocation(trace);
1255
1320
  const lastStep = trace.steps[trace.steps.length - 1] as EvmStep;
1256
1321
  const nextInstPc = lastStep.pc + 1;
1257
1322
  const hasNextInst = trace.bytecode.hasInstruction(nextInstPc);
1258
1323
 
1259
1324
  if (hasNextInst) {
1260
1325
  const nextInst = trace.bytecode.getInstruction(nextInstPc);
1261
- const prevLoc = prevInst.location!;
1326
+ const prevLoc = prevInst?.location;
1262
1327
  const nextLoc = nextInst.location;
1263
- const prevFunc = prevLoc.getContainingFunction();
1328
+ const prevFunc = prevLoc?.getContainingFunction();
1264
1329
  const nextFunc = nextLoc?.getContainingFunction();
1265
1330
 
1266
1331
  // This is probably a require. This means that we have the exact
@@ -1270,37 +1335,31 @@ export class ErrorInferrer {
1270
1335
  if (
1271
1336
  prevFunc !== undefined &&
1272
1337
  nextLoc !== undefined &&
1338
+ prevLoc !== undefined &&
1273
1339
  prevLoc.equals(nextLoc)
1274
1340
  ) {
1275
- return {
1276
- ...this._instructionWithinFunctionToRevertStackTraceEntry(
1277
- trace,
1278
- nextInst
1279
- ),
1280
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1281
- };
1341
+ return this._instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1342
+ trace,
1343
+ nextInst
1344
+ );
1282
1345
  }
1283
1346
 
1284
1347
  let revertFrame: UnmappedSolc063RevertErrorStackTraceEntry | undefined;
1285
1348
 
1286
1349
  // If the previous and next location don't match, we try to use the
1287
1350
  // previous one if it's inside a function, otherwise we use the next one
1288
- if (prevFunc !== undefined) {
1289
- revertFrame = {
1290
- ...this._instructionWithinFunctionToRevertStackTraceEntry(
1351
+ if (prevFunc !== undefined && prevInst !== undefined) {
1352
+ revertFrame =
1353
+ this._instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1291
1354
  trace,
1292
1355
  prevInst
1293
- ),
1294
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1295
- };
1356
+ );
1296
1357
  } else if (nextFunc !== undefined) {
1297
- revertFrame = {
1298
- ...this._instructionWithinFunctionToRevertStackTraceEntry(
1358
+ revertFrame =
1359
+ this._instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1299
1360
  trace,
1300
1361
  nextInst
1301
- ),
1302
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1303
- };
1362
+ );
1304
1363
  }
1305
1364
 
1306
1365
  if (revertFrame !== undefined) {
@@ -1310,18 +1369,15 @@ export class ErrorInferrer {
1310
1369
  return revertFrame;
1311
1370
  }
1312
1371
 
1313
- if (isCreateTrace(trace)) {
1372
+ if (isCreateTrace(trace) && prevInst !== undefined) {
1314
1373
  // Solidity is smart enough to stop emitting extra instructions after
1315
1374
  // an unconditional revert happens in a constructor. If this is the case
1316
1375
  // we just return a special error.
1317
1376
  const constructorRevertFrame: UnmappedSolc063RevertErrorStackTraceEntry =
1318
- {
1319
- ...this._instructionWithinFunctionToRevertStackTraceEntry(
1320
- trace,
1321
- prevInst
1322
- ),
1323
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1324
- };
1377
+ this._instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1378
+ trace,
1379
+ prevInst
1380
+ );
1325
1381
 
1326
1382
  // When the latest instruction is not within a function we need
1327
1383
  // some default sourceReference to show to the user
@@ -1349,24 +1405,22 @@ export class ErrorInferrer {
1349
1405
  return constructorRevertFrame;
1350
1406
  }
1351
1407
 
1352
- // We may as well just be in a function or modifier and just happen
1353
- // to be at the last instruction of the runtime bytecode.
1354
- // In this case we just return whatever the last mapped intruction
1355
- // points to.
1356
- const latestInstructionRevertFrame: UnmappedSolc063RevertErrorStackTraceEntry =
1357
- {
1358
- ...this._instructionWithinFunctionToRevertStackTraceEntry(
1408
+ if (prevInst !== undefined) {
1409
+ // We may as well just be in a function or modifier and just happen
1410
+ // to be at the last instruction of the runtime bytecode.
1411
+ // In this case we just return whatever the last mapped intruction
1412
+ // points to.
1413
+ const latestInstructionRevertFrame: UnmappedSolc063RevertErrorStackTraceEntry =
1414
+ this._instructionWithinFunctionToUnmappedSolc063RevertErrorStackTraceEntry(
1359
1415
  trace,
1360
1416
  prevInst
1361
- ),
1362
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
1363
- };
1417
+ );
1364
1418
 
1365
- if (latestInstructionRevertFrame.sourceReference !== undefined) {
1366
- this._solidity063CorrectLineNumber(latestInstructionRevertFrame);
1419
+ if (latestInstructionRevertFrame.sourceReference !== undefined) {
1420
+ this._solidity063CorrectLineNumber(latestInstructionRevertFrame);
1421
+ }
1422
+ return latestInstructionRevertFrame;
1367
1423
  }
1368
-
1369
- return latestInstructionRevertFrame;
1370
1424
  }
1371
1425
 
1372
1426
  private _isContractTooLargeError(trace: DecodedCreateMessageTrace) {
@@ -1376,6 +1430,10 @@ export class ErrorInferrer {
1376
1430
  private _solidity063CorrectLineNumber(
1377
1431
  revertFrame: UnmappedSolc063RevertErrorStackTraceEntry
1378
1432
  ) {
1433
+ if (revertFrame.sourceReference === undefined) {
1434
+ return;
1435
+ }
1436
+
1379
1437
  const lines = revertFrame.sourceReference.sourceContent.split("\n");
1380
1438
 
1381
1439
  const currentLine = lines[revertFrame.sourceReference.line - 1];
@@ -1443,13 +1501,19 @@ export class ErrorInferrer {
1443
1501
  bytecode: Bytecode,
1444
1502
  callInst: Instruction
1445
1503
  ): CallFailedErrorStackTraceEntry {
1504
+ const sourceReference = sourceLocationToSourceReference(
1505
+ bytecode,
1506
+ callInst.location
1507
+ );
1508
+ assertHardhatInvariant(
1509
+ sourceReference !== undefined,
1510
+ "Expected source reference to be defined"
1511
+ );
1512
+
1446
1513
  // Calls only happen within functions
1447
1514
  return {
1448
1515
  type: StackTraceEntryType.CALL_FAILED_ERROR,
1449
- sourceReference: sourceLocationToSourceReference(
1450
- bytecode,
1451
- callInst.location
1452
- )!,
1516
+ sourceReference,
1453
1517
  };
1454
1518
  }
1455
1519
 
@@ -1498,10 +1562,16 @@ export class ErrorInferrer {
1498
1562
  const callOpcodeStep = trace.steps[callSubtraceStepIndex - 1] as EvmStep;
1499
1563
  const callInst = trace.bytecode.getInstruction(callOpcodeStep.pc);
1500
1564
 
1565
+ // Calls are always made from within functions
1566
+ assertHardhatInvariant(
1567
+ callInst.location !== undefined,
1568
+ "Expected call instruction location to be defined"
1569
+ );
1570
+
1501
1571
  return this._isLastLocation(
1502
1572
  trace,
1503
1573
  callSubtraceStepIndex + 1,
1504
- callInst.location! // Calls are always made from within functions
1574
+ callInst.location
1505
1575
  );
1506
1576
  }
1507
1577
 
@@ -1510,7 +1580,14 @@ export class ErrorInferrer {
1510
1580
  instIndex: number,
1511
1581
  callInstruction: Instruction
1512
1582
  ): boolean {
1513
- const callLocation = callInstruction.location!; // Calls are always made from within functions
1583
+ const callLocation = callInstruction.location;
1584
+
1585
+ // Calls are always made from within functions
1586
+ assertHardhatInvariant(
1587
+ callLocation !== undefined,
1588
+ "Expected call location to be defined"
1589
+ );
1590
+
1514
1591
  return this._isLastLocation(trace, instIndex, callLocation);
1515
1592
  }
1516
1593
 
@@ -1681,30 +1758,41 @@ export function instructionToCallstackStackTraceEntry(
1681
1758
  };
1682
1759
  }
1683
1760
 
1684
- const func = inst.location!.getContainingFunction();
1761
+ const func = inst.location?.getContainingFunction();
1685
1762
 
1686
1763
  if (func !== undefined) {
1764
+ const sourceReference = sourceLocationToSourceReference(
1765
+ bytecode,
1766
+ inst.location
1767
+ );
1768
+ assertHardhatInvariant(
1769
+ sourceReference !== undefined,
1770
+ "Expected source reference to be defined"
1771
+ );
1772
+
1687
1773
  return {
1688
1774
  type: StackTraceEntryType.CALLSTACK_ENTRY,
1689
- sourceReference: sourceLocationToSourceReference(
1690
- bytecode,
1691
- inst.location
1692
- )!,
1775
+ sourceReference,
1693
1776
  functionType: func.type,
1694
1777
  };
1695
1778
  }
1696
1779
 
1780
+ assertHardhatInvariant(
1781
+ inst.location !== undefined,
1782
+ "Expected instruction location to be defined"
1783
+ );
1784
+
1697
1785
  return {
1698
1786
  type: StackTraceEntryType.CALLSTACK_ENTRY,
1699
1787
  sourceReference: {
1700
1788
  function: undefined,
1701
1789
  contract: bytecode.contract.name,
1702
- sourceName: inst.location!.file.sourceName,
1703
- sourceContent: inst.location!.file.content,
1704
- line: inst.location!.getStartingLineNumber(),
1790
+ sourceName: inst.location.file.sourceName,
1791
+ sourceContent: inst.location.file.content,
1792
+ line: inst.location.getStartingLineNumber(),
1705
1793
  range: [
1706
- inst.location!.offset,
1707
- inst.location!.offset + inst.location!.length,
1794
+ inst.location.offset,
1795
+ inst.location.offset + inst.location.length,
1708
1796
  ],
1709
1797
  },
1710
1798
  functionType: ContractFunctionType.FUNCTION,
@@ -261,12 +261,22 @@ export class ContractFunction {
261
261
  public readonly contract?: Contract,
262
262
  public readonly visibility?: ContractFunctionVisibility,
263
263
  public readonly isPayable?: boolean,
264
- public selector?: Buffer
264
+ public selector?: Buffer,
265
+ public readonly paramTypes?: any[]
265
266
  ) {
266
267
  if (contract !== undefined && !contract.location.contains(location)) {
267
268
  throw new Error("Incompatible contract and function location");
268
269
  }
269
270
  }
271
+
272
+ public isValidCalldata(calldata: Buffer): boolean {
273
+ if (this.paramTypes === undefined) {
274
+ // if we don't know the param types, we just assume that the call is valid
275
+ return true;
276
+ }
277
+
278
+ return AbiHelpers.isValidCalldata(this.paramTypes, calldata);
279
+ }
270
280
  }
271
281
 
272
282
  export class CustomError {
@@ -112,7 +112,6 @@ function encodeStackTraceEntry(
112
112
 
113
113
  case StackTraceEntryType.CALLSTACK_ENTRY:
114
114
  case StackTraceEntryType.REVERT_ERROR:
115
- case StackTraceEntryType.PANIC_ERROR:
116
115
  case StackTraceEntryType.CUSTOM_ERROR:
117
116
  case StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR:
118
117
  case StackTraceEntryType.INVALID_PARAMS_ERROR:
@@ -122,7 +121,6 @@ function encodeStackTraceEntry(
122
121
  case StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR:
123
122
  case StackTraceEntryType.CALL_FAILED_ERROR:
124
123
  case StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR:
125
- case StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR:
126
124
  return sourceReferenceToSolidityCallsite(stackTraceEntry.sourceReference);
127
125
 
128
126
  case StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY:
@@ -188,6 +186,8 @@ function encodeStackTraceEntry(
188
186
 
189
187
  case StackTraceEntryType.OTHER_EXECUTION_ERROR:
190
188
  case StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR:
189
+ case StackTraceEntryType.PANIC_ERROR:
190
+ case StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR:
191
191
  if (stackTraceEntry.sourceReference === undefined) {
192
192
  return new SolidityCallSite(
193
193
  undefined,
@@ -81,7 +81,7 @@ export interface RevertErrorStackTraceEntry {
81
81
  export interface PanicErrorStackTraceEntry {
82
82
  type: StackTraceEntryType.PANIC_ERROR;
83
83
  errorCode: bigint;
84
- sourceReference: SourceReference;
84
+ sourceReference?: SourceReference;
85
85
  }
86
86
 
87
87
  export interface CustomErrorStackTraceEntry {
@@ -93,7 +93,7 @@ export interface CustomErrorStackTraceEntry {
93
93
 
94
94
  export interface UnmappedSolc063RevertErrorStackTraceEntry {
95
95
  type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR;
96
- sourceReference: SourceReference;
96
+ sourceReference?: SourceReference;
97
97
  }
98
98
 
99
99
  export interface FunctionNotPayableErrorStackTraceEntry {
@@ -171,7 +171,10 @@ export class SolidityTracer {
171
171
  const stacktrace: SolidityStackTrace = [];
172
172
 
173
173
  let subtracesSeen = 0;
174
+
175
+ // There was a jump into a function according to the sourcemaps
174
176
  let jumpedIntoFunction = false;
177
+
175
178
  const functionJumpdests: Instruction[] = [];
176
179
 
177
180
  let lastSubmessageData: SubmessageData | undefined;
@@ -36,16 +36,11 @@ if (HardhatContext.isCreated()) {
36
36
 
37
37
  const { resolvedConfig, userConfig } = loadConfigAndTasks(hardhatArguments);
38
38
 
39
- const artifactsExtensions = ctx.extendersManager
40
- .getArtifactsExtenders()
41
- .map((artifactsExtender) => artifactsExtender(resolvedConfig));
42
-
43
39
  env = new Environment(
44
40
  resolvedConfig,
45
41
  hardhatArguments,
46
42
  ctx.tasksDSL.getTaskDefinitions(),
47
- ctx.extendersManager.getEnvironmentExtenders(),
48
- artifactsExtensions,
43
+ ctx.extendersManager.getExtenders(),
49
44
  ctx.experimentalHardhatNetworkMessageTraceHooks,
50
45
  userConfig
51
46
  );
@@ -294,7 +294,7 @@ export class CompilerDownloader implements ICompilerDownloader {
294
294
  build: CompilerBuild,
295
295
  downloadPath: string
296
296
  ): Promise<boolean> {
297
- const ethereumjsUtil = await import("@nomicfoundation/ethereumjs-util");
297
+ const ethereumjsUtil = require("@nomicfoundation/ethereumjs-util");
298
298
  const { keccak256 } = await import("../../util/keccak");
299
299
 
300
300
  const expectedKeccak256 = build.keccak256;
@@ -328,7 +328,7 @@ export class CompilerDownloader implements ICompilerDownloader {
328
328
  downloadPath.endsWith(".zip")
329
329
  ) {
330
330
  // some window builds are zipped, some are not
331
- const { default: AdmZip } = await import("adm-zip");
331
+ const AdmZip = require("adm-zip");
332
332
 
333
333
  const solcFolder = path.join(this._compilersDir, build.version);
334
334
  await fsExtra.ensureDir(solcFolder);
@@ -25,7 +25,7 @@ export class Compiler implements ICompiler {
25
25
  return this._loadedSolc;
26
26
  }
27
27
 
28
- const { default: solcWrapper } = await import("solc/wrapper");
28
+ const solcWrapper = require("solc/wrapper");
29
29
  this._loadedSolc = solcWrapper(
30
30
  this._loadCompilerSources(this._pathToSolcJs)
31
31
  );
@@ -69,7 +69,10 @@ export class Resolver {
69
69
  constructor(
70
70
  private readonly _projectRoot: string,
71
71
  private readonly _parser: Parser,
72
- private readonly _readFile: (absolutePath: string) => Promise<string>
72
+ private readonly _readFile: (absolutePath: string) => Promise<string>,
73
+ private readonly _transformImportName: (
74
+ importName: string
75
+ ) => Promise<string>
73
76
  ) {}
74
77
 
75
78
  /**
@@ -100,12 +103,14 @@ export class Resolver {
100
103
  /**
101
104
  * Resolves an import from an already resolved file.
102
105
  * @param from The file were the import statement is present.
103
- * @param imported The path in the import statement.
106
+ * @param importName The path in the import statement.
104
107
  */
105
108
  public async resolveImport(
106
109
  from: ResolvedFile,
107
- imported: string
110
+ importName: string
108
111
  ): Promise<ResolvedFile> {
112
+ const imported = await this._transformImportName(importName);
113
+
109
114
  const scheme = this._getUriScheme(imported);
110
115
  if (scheme !== undefined) {
111
116
  throw new HardhatError(ERRORS.RESOLVER.INVALID_IMPORT_PROTOCOL, {
@@ -182,14 +187,26 @@ export class Resolver {
182
187
  ERRORS.RESOLVER.LIBRARY_FILE_NOT_FOUND
183
188
  )
184
189
  ) {
185
- throw new HardhatError(
186
- ERRORS.RESOLVER.IMPORTED_FILE_NOT_FOUND,
187
- {
188
- imported,
189
- from: from.sourceName,
190
- },
191
- error
192
- );
190
+ if (imported !== importName) {
191
+ throw new HardhatError(
192
+ ERRORS.RESOLVER.IMPORTED_MAPPED_FILE_NOT_FOUND,
193
+ {
194
+ imported,
195
+ importName,
196
+ from: from.sourceName,
197
+ },
198
+ error
199
+ );
200
+ } else {
201
+ throw new HardhatError(
202
+ ERRORS.RESOLVER.IMPORTED_FILE_NOT_FOUND,
203
+ {
204
+ imported,
205
+ from: from.sourceName,
206
+ },
207
+ error
208
+ );
209
+ }
193
210
  }
194
211
 
195
212
  if (