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
@@ -0,0 +1,123 @@
1
+ import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
2
+ import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs.js";
3
+ import { expect } from "chai";
4
+
5
+ describe("Lock", function () {
6
+ // We define a fixture to reuse the same setup in every test.
7
+ // We use loadFixture to run this setup once, snapshot that state,
8
+ // and reset Hardhat Network to that snapshot in every test.
9
+ async function deployOneYearLockFixture() {
10
+ const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
11
+ const ONE_GWEI = 1_000_000_000;
12
+
13
+ const lockedAmount = ONE_GWEI;
14
+ const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
15
+
16
+ // Contracts are deployed using the first signer/account by default
17
+ const [owner, otherAccount] = await ethers.getSigners();
18
+
19
+ const Lock = await ethers.getContractFactory("Lock");
20
+ const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
21
+
22
+ return { lock, unlockTime, lockedAmount, owner, otherAccount };
23
+ }
24
+
25
+ describe("Deployment", function () {
26
+ it("Should set the right unlockTime", async function () {
27
+ const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
28
+
29
+ expect(await lock.unlockTime()).to.equal(unlockTime);
30
+ });
31
+
32
+ it("Should set the right owner", async function () {
33
+ const { lock, owner } = await loadFixture(deployOneYearLockFixture);
34
+
35
+ expect(await lock.owner()).to.equal(owner.address);
36
+ });
37
+
38
+ it("Should receive and store the funds to lock", async function () {
39
+ const { lock, lockedAmount } = await loadFixture(
40
+ deployOneYearLockFixture
41
+ );
42
+
43
+ expect(await ethers.provider.getBalance(lock.address)).to.equal(
44
+ lockedAmount
45
+ );
46
+ });
47
+
48
+ it("Should fail if the unlockTime is not in the future", async function () {
49
+ // We don't use the fixture here because we want a different deployment
50
+ const latestTime = await time.latest();
51
+ const Lock = await ethers.getContractFactory("Lock");
52
+ await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
53
+ "Unlock time should be in the future"
54
+ );
55
+ });
56
+ });
57
+
58
+ describe("Withdrawals", function () {
59
+ describe("Validations", function () {
60
+ it("Should revert with the right error if called too soon", async function () {
61
+ const { lock } = await loadFixture(deployOneYearLockFixture);
62
+
63
+ await expect(lock.withdraw()).to.be.revertedWith(
64
+ "You can't withdraw yet"
65
+ );
66
+ });
67
+
68
+ it("Should revert with the right error if called from another account", async function () {
69
+ const { lock, unlockTime, otherAccount } = await loadFixture(
70
+ deployOneYearLockFixture
71
+ );
72
+
73
+ // We can increase the time in Hardhat Network
74
+ await time.increaseTo(unlockTime);
75
+
76
+ // We use lock.connect() to send a transaction from another account
77
+ await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
78
+ "You aren't the owner"
79
+ );
80
+ });
81
+
82
+ it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
83
+ const { lock, unlockTime } = await loadFixture(
84
+ deployOneYearLockFixture
85
+ );
86
+
87
+ // Transactions are sent using the first signer by default
88
+ await time.increaseTo(unlockTime);
89
+
90
+ await expect(lock.withdraw()).not.to.be.reverted;
91
+ });
92
+ });
93
+
94
+ describe("Events", function () {
95
+ it("Should emit an event on withdrawals", async function () {
96
+ const { lock, unlockTime, lockedAmount } = await loadFixture(
97
+ deployOneYearLockFixture
98
+ );
99
+
100
+ await time.increaseTo(unlockTime);
101
+
102
+ await expect(lock.withdraw())
103
+ .to.emit(lock, "Withdrawal")
104
+ .withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
105
+ });
106
+ });
107
+
108
+ describe("Transfers", function () {
109
+ it("Should transfer the funds to the owner", async function () {
110
+ const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
111
+ deployOneYearLockFixture
112
+ );
113
+
114
+ await time.increaseTo(unlockTime);
115
+
116
+ await expect(lock.withdraw()).to.changeEtherBalances(
117
+ [owner, lock],
118
+ [lockedAmount, -lockedAmount]
119
+ );
120
+ });
121
+ });
122
+ });
123
+ });
@@ -2,7 +2,7 @@ import { HardhatUserConfig } from "hardhat/config";
2
2
  import "@nomicfoundation/hardhat-toolbox";
3
3
 
4
4
  const config: HardhatUserConfig = {
5
- solidity: "0.8.17",
5
+ solidity: "0.8.18",
6
6
  };
7
7
 
8
8
  export default config;
@@ -5,14 +5,14 @@ async function main() {
5
5
  const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
6
6
  const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
7
7
 
8
- const lockedAmount = ethers.utils.parseEther("1");
8
+ const lockedAmount = ethers.utils.parseEther("0.01");
9
9
 
10
10
  const Lock = await ethers.getContractFactory("Lock");
11
11
  const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
12
12
 
13
13
  await lock.deployed();
14
14
 
15
- console.log(`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`);
15
+ console.log(`Lock with 0.01 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`);
16
16
  }
17
17
 
18
18
  // We recommend this pattern to be able to use async/await everywhere
@@ -5,6 +5,7 @@
5
5
  "esModuleInterop": true,
6
6
  "forceConsistentCasingInFileNames": true,
7
7
  "strict": true,
8
- "skipLibCheck": true
8
+ "skipLibCheck": true,
9
+ "resolveJsonModule": true
9
10
  }
10
11
  }
@@ -73,6 +73,7 @@ import {
73
73
  TASK_COMPILE_SOLIDITY_RUN_SOLC,
74
74
  TASK_COMPILE_SOLIDITY_RUN_SOLCJS,
75
75
  TASK_COMPILE_REMOVE_OBSOLETE_ARTIFACTS,
76
+ TASK_COMPILE_TRANSFORM_IMPORT_NAME,
76
77
  } from "./task-names";
77
78
  import {
78
79
  getSolidityFilesCachePath,
@@ -90,11 +91,13 @@ type ArtifactsEmittedPerJob = Array<{
90
91
  }>;
91
92
 
92
93
  function isConsoleLogError(error: any): boolean {
94
+ const message = error.message;
95
+
93
96
  return (
94
97
  error.type === "TypeError" &&
95
- typeof error.message === "string" &&
96
- error.message.includes("log") &&
97
- error.message.includes("type(library console)")
98
+ typeof message === "string" &&
99
+ message.includes("log") &&
100
+ message.includes("type(library console)")
98
101
  );
99
102
  }
100
103
 
@@ -157,6 +160,18 @@ subtask(TASK_COMPILE_SOLIDITY_READ_FILE)
157
160
  }
158
161
  );
159
162
 
163
+ /**
164
+ * This task transform the string literal in an import directive.
165
+ * By default it does nothing, but it can be overriden by plugins.
166
+ */
167
+ subtask(TASK_COMPILE_TRANSFORM_IMPORT_NAME)
168
+ .addParam("importName", undefined, undefined, types.string)
169
+ .setAction(
170
+ async ({ importName }: { importName: string }): Promise<string> => {
171
+ return importName;
172
+ }
173
+ );
174
+
160
175
  /**
161
176
  * Receives a list of source names and returns a dependency graph. This task
162
177
  * is responsible for both resolving dependencies (like getting files from
@@ -178,7 +193,9 @@ subtask(TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH)
178
193
  config.paths.root,
179
194
  parser,
180
195
  (absolutePath: string) =>
181
- run(TASK_COMPILE_SOLIDITY_READ_FILE, { absolutePath })
196
+ run(TASK_COMPILE_SOLIDITY_READ_FILE, { absolutePath }),
197
+ (importName: string) =>
198
+ run(TASK_COMPILE_TRANSFORM_IMPORT_NAME, { importName })
182
199
  );
183
200
 
184
201
  const resolvedFiles = await Promise.all(
@@ -738,13 +755,17 @@ subtask(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS)
738
755
 
739
756
  for (const error of output.errors) {
740
757
  if (error.severity === "error") {
741
- const errorMessage =
758
+ const errorMessage: string =
742
759
  getFormattedInternalCompilerErrorMessage(error) ??
743
760
  error.formattedMessage;
744
761
 
745
- console.error(chalk.red(errorMessage));
762
+ console.error(errorMessage.replace(/^\w+:/, (t) => chalk.red.bold(t)));
746
763
  } else {
747
- console.warn(chalk.yellow(error.formattedMessage));
764
+ console.warn(
765
+ (error.formattedMessage as string).replace(/^\w+:/, (t) =>
766
+ chalk.yellow.bold(t)
767
+ )
768
+ );
748
769
  }
749
770
  }
750
771
 
@@ -124,7 +124,10 @@ subtask(TASK_FLATTEN_GET_DEPENDENCY_GRAPH)
124
124
  return dependencyGraph;
125
125
  });
126
126
 
127
- task(TASK_FLATTEN, "Flattens and prints contracts and their dependencies")
127
+ task(
128
+ TASK_FLATTEN,
129
+ "Flattens and prints contracts and their dependencies. If no file is passed, all the contracts in the project will be flattened."
130
+ )
128
131
  .addOptionalVariadicPositionalParam(
129
132
  "files",
130
133
  "The files to flatten",
@@ -2,7 +2,6 @@ import { HelpPrinter } from "../internal/cli/HelpPrinter";
2
2
  import { HARDHAT_EXECUTABLE_NAME, HARDHAT_NAME } from "../internal/constants";
3
3
  import { task } from "../internal/core/config/config-env";
4
4
  import { HARDHAT_PARAM_DEFINITIONS } from "../internal/core/params/hardhat-params";
5
- import { getPackageJson } from "../internal/util/packageInfo";
6
5
 
7
6
  import { TASK_HELP } from "./task-names";
8
7
 
@@ -11,21 +10,21 @@ task(TASK_HELP, "Prints this message")
11
10
  "task",
12
11
  "An optional task to print more info about"
13
12
  )
14
- .setAction(async ({ task: taskName }: { task?: string }, { tasks }) => {
15
- const packageJson = await getPackageJson();
13
+ .setAction(
14
+ async ({ task: taskName }: { task?: string }, { tasks, version }) => {
15
+ const helpPrinter = new HelpPrinter(
16
+ HARDHAT_NAME,
17
+ HARDHAT_EXECUTABLE_NAME,
18
+ version,
19
+ HARDHAT_PARAM_DEFINITIONS,
20
+ tasks
21
+ );
16
22
 
17
- const helpPrinter = new HelpPrinter(
18
- HARDHAT_NAME,
19
- HARDHAT_EXECUTABLE_NAME,
20
- packageJson.version,
21
- HARDHAT_PARAM_DEFINITIONS,
22
- tasks
23
- );
23
+ if (taskName !== undefined) {
24
+ helpPrinter.printTaskHelp(taskName);
25
+ return;
26
+ }
24
27
 
25
- if (taskName !== undefined) {
26
- helpPrinter.printTaskHelp(taskName);
27
- return;
28
+ helpPrinter.printGlobalHelp();
28
29
  }
29
-
30
- helpPrinter.printGlobalHelp();
31
- });
30
+ );
@@ -12,6 +12,8 @@ export const TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS =
12
12
  export const TASK_COMPILE_SOLIDITY_GET_SOURCE_NAMES =
13
13
  "compile:solidity:get-source-names";
14
14
  export const TASK_COMPILE_SOLIDITY_READ_FILE = "compile:solidity:read-file";
15
+ export const TASK_COMPILE_TRANSFORM_IMPORT_NAME =
16
+ "compile:solidity:transform-import-name";
15
17
  export const TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH =
16
18
  "compile:solidity:get-dependency-graph";
17
19
  export const TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS =
@@ -5,11 +5,14 @@ import path from "path";
5
5
 
6
6
  import { HARDHAT_NETWORK_NAME } from "../internal/constants";
7
7
  import { subtask, task } from "../internal/core/config/config-env";
8
+ import { HardhatError } from "../internal/core/errors";
9
+ import { ERRORS } from "../internal/core/errors-list";
8
10
  import { isRunningWithTypescript } from "../internal/core/typescript-support";
9
11
  import { getForkCacheDirPath } from "../internal/hardhat-network/provider/utils/disk-cache";
10
12
  import { showForkRecommendationsBannerIfNecessary } from "../internal/hardhat-network/provider/utils/fork-recomendations-banner";
11
13
  import { pluralize } from "../internal/util/strings";
12
14
  import { getAllFilesMatching } from "../internal/util/fs-utils";
15
+ import { getProjectPackageJson } from "../internal/util/packageInfo";
13
16
 
14
17
  import {
15
18
  TASK_COMPILE,
@@ -35,8 +38,9 @@ subtask(TASK_TEST_GET_TEST_FILES)
35
38
  return testFilesAbsolutePaths;
36
39
  }
37
40
 
38
- const jsFiles = await getAllFilesMatching(config.paths.tests, (f) =>
39
- f.endsWith(".js")
41
+ const jsFiles = await getAllFilesMatching(
42
+ config.paths.tests,
43
+ (f) => f.endsWith(".js") || f.endsWith(".cjs") || f.endsWith(".mjs")
40
44
  );
41
45
 
42
46
  if (!isRunningWithTypescript(config)) {
@@ -52,6 +56,7 @@ subtask(TASK_TEST_GET_TEST_FILES)
52
56
 
53
57
  subtask(TASK_TEST_SETUP_TEST_ENVIRONMENT, async () => {});
54
58
 
59
+ let testsAlreadyRun = false;
55
60
  subtask(TASK_TEST_RUN_MOCHA_TESTS)
56
61
  .addFlag("parallel", "Run tests in parallel")
57
62
  .addFlag("bail", "Stop running tests after the first test failure")
@@ -99,6 +104,29 @@ subtask(TASK_TEST_RUN_MOCHA_TESTS)
99
104
  const mocha = new Mocha(mochaConfig);
100
105
  taskArgs.testFiles.forEach((file) => mocha.addFile(file));
101
106
 
107
+ // if the project is of type "module" or if there's some ESM test file,
108
+ // we call loadFilesAsync to enable Mocha's ESM support
109
+ const projectPackageJson = await getProjectPackageJson();
110
+ const isTypeModule = projectPackageJson.type === "module";
111
+ const hasEsmTest = taskArgs.testFiles.some((file) =>
112
+ file.endsWith(".mjs")
113
+ );
114
+ if (isTypeModule || hasEsmTest) {
115
+ // Because of the way the ESM cache works, loadFilesAsync doesn't work
116
+ // correctly if used twice within the same process, so we throw an error
117
+ // in that case
118
+ if (testsAlreadyRun) {
119
+ throw new HardhatError(
120
+ ERRORS.BUILTIN_TASKS.TEST_TASK_ESM_TESTS_RUN_TWICE
121
+ );
122
+ }
123
+ testsAlreadyRun = true;
124
+
125
+ // This instructs Mocha to use the more verbose file loading infrastructure
126
+ // which supports both ESM and CJS
127
+ await mocha.loadFilesAsync();
128
+ }
129
+
102
130
  const testFailures = await new Promise<number>((resolve) => {
103
131
  mocha.run(resolve);
104
132
  });