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.
- package/builtin-tasks/compile.js +16 -6
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/flatten.js +1 -1
- package/builtin-tasks/flatten.js.map +1 -1
- package/builtin-tasks/help.js +2 -4
- package/builtin-tasks/help.js.map +1 -1
- package/builtin-tasks/task-names.d.ts +1 -0
- package/builtin-tasks/task-names.d.ts.map +1 -1
- package/builtin-tasks/task-names.js +3 -2
- package/builtin-tasks/task-names.js.map +1 -1
- package/builtin-tasks/test.js +22 -1
- package/builtin-tasks/test.js.map +1 -1
- package/internal/cli/bootstrap.d.ts +1 -0
- package/internal/cli/bootstrap.js +12 -20
- package/internal/cli/bootstrap.js.map +1 -1
- package/internal/cli/cli.d.ts +0 -1
- package/internal/cli/cli.d.ts.map +1 -1
- package/internal/cli/cli.js +20 -29
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/project-creation.d.ts +1 -2
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +105 -36
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/prompt.d.ts +2 -2
- package/internal/cli/prompt.d.ts.map +1 -1
- package/internal/cli/prompt.js +1 -2
- package/internal/cli/prompt.js.map +1 -1
- package/internal/cli/types.d.ts +1 -0
- package/internal/cli/types.d.ts.map +1 -1
- package/internal/core/config/config-env.d.ts +5 -11
- package/internal/core/config/config-env.d.ts.map +1 -1
- package/internal/core/config/config-env.js +2 -13
- package/internal/core/config/config-env.js.map +1 -1
- package/internal/core/config/config-loading.d.ts +2 -1
- package/internal/core/config/config-loading.d.ts.map +1 -1
- package/internal/core/config/config-loading.js +25 -7
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/config/config-validation.d.ts +2 -0
- package/internal/core/config/config-validation.d.ts.map +1 -1
- package/internal/core/config/config-validation.js +18 -1
- package/internal/core/config/config-validation.js.map +1 -1
- package/internal/core/config/extenders.d.ts +4 -7
- package/internal/core/config/extenders.d.ts.map +1 -1
- package/internal/core/config/extenders.js +5 -12
- package/internal/core/config/extenders.js.map +1 -1
- package/internal/core/errors-list.d.ts +28 -7
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +33 -10
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
- package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
- package/internal/core/project-structure.d.ts.map +1 -1
- package/internal/core/project-structure.js +6 -0
- package/internal/core/project-structure.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +25 -5
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/http.d.ts +2 -2
- package/internal/core/providers/http.d.ts.map +1 -1
- package/internal/core/providers/http.js +41 -19
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/runtime-environment.d.ts +4 -2
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js +39 -47
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/core/tasks/dsl.d.ts +6 -6
- package/internal/core/tasks/dsl.d.ts.map +1 -1
- package/internal/core/tasks/dsl.js.map +1 -1
- package/internal/core/tasks/task-definitions.d.ts +2 -2
- package/internal/core/tasks/task-definitions.d.ts.map +1 -1
- package/internal/core/tasks/task-definitions.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.d.ts +1 -0
- package/internal/hardhat-network/jsonrpc/handler.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +13 -18
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/RethnetState.d.ts +26 -0
- package/internal/hardhat-network/provider/RethnetState.d.ts.map +1 -0
- package/internal/hardhat-network/provider/RethnetState.js +84 -0
- package/internal/hardhat-network/provider/RethnetState.js.map +1 -0
- package/internal/hardhat-network/provider/modules/evm.d.ts +2 -1
- package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/evm.js +10 -4
- package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +1 -0
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +6 -4
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +25 -21
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +25 -42
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/return-data.js +2 -2
- package/internal/hardhat-network/provider/return-data.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +4 -2
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/utils/bloom.d.ts +32 -0
- package/internal/hardhat-network/provider/utils/bloom.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/bloom.js +79 -0
- package/internal/hardhat-network/provider/utils/bloom.js.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts +12 -0
- package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToRethnet.js +162 -0
- package/internal/hardhat-network/provider/utils/convertToRethnet.js.map +1 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +7 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +31 -0
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -0
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -2
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
- package/internal/hardhat-network/provider/vm/block-builder.d.ts +31 -0
- package/internal/hardhat-network/provider/vm/block-builder.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/block-builder.js +151 -0
- package/internal/hardhat-network/provider/vm/block-builder.js.map +1 -0
- package/internal/hardhat-network/provider/vm/creation.d.ts +10 -0
- package/internal/hardhat-network/provider/vm/creation.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/creation.js +29 -0
- package/internal/hardhat-network/provider/vm/creation.js.map +1 -0
- package/internal/hardhat-network/provider/vm/dual.d.ts +43 -0
- package/internal/hardhat-network/provider/vm/dual.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/dual.js +488 -0
- package/internal/hardhat-network/provider/vm/dual.js.map +1 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.d.ts +56 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.js +416 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.js.map +1 -0
- package/internal/hardhat-network/provider/vm/exit.d.ts +23 -0
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/exit.js +130 -0
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
- package/internal/hardhat-network/provider/vm/rethnet.d.ts +99 -0
- package/internal/hardhat-network/provider/vm/rethnet.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/rethnet.js +284 -0
- package/internal/hardhat-network/provider/vm/rethnet.js.map +1 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.d.ts +52 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.js +3 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.js.map +1 -0
- package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.js +37 -11
- package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/constants.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/constants.js +1 -1
- package/internal/hardhat-network/stack-traces/debug.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/debug.js +6 -2
- package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +1 -0
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +85 -55
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/model.d.ts +3 -1
- package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/model.js +9 -1
- package/internal/hardhat-network/stack-traces/model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +2 -2
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +1 -0
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
- package/internal/lib/hardhat-lib.d.ts.map +1 -1
- package/internal/lib/hardhat-lib.js +1 -4
- package/internal/lib/hardhat-lib.js.map +1 -1
- package/internal/solidity/compiler/downloader.js +2 -2
- package/internal/solidity/compiler/downloader.js.map +1 -1
- package/internal/solidity/compiler/index.js +1 -1
- package/internal/solidity/compiler/index.js.map +1 -1
- package/internal/solidity/resolver.d.ts +4 -3
- package/internal/solidity/resolver.d.ts.map +1 -1
- package/internal/solidity/resolver.js +18 -7
- package/internal/solidity/resolver.js.map +1 -1
- package/internal/util/abi-helpers.d.ts +1 -0
- package/internal/util/abi-helpers.d.ts.map +1 -1
- package/internal/util/abi-helpers.js +9 -0
- package/internal/util/abi-helpers.js.map +1 -1
- package/internal/util/download.d.ts.map +1 -1
- package/internal/util/download.js +12 -11
- package/internal/util/download.js.map +1 -1
- package/internal/util/packageInfo.d.ts +6 -1
- package/internal/util/packageInfo.d.ts.map +1 -1
- package/internal/util/packageInfo.js +14 -11
- package/internal/util/packageInfo.js.map +1 -1
- package/internal/util/proxy.d.ts +2 -0
- package/internal/util/proxy.d.ts.map +1 -0
- package/internal/util/proxy.js +19 -0
- package/internal/util/proxy.js.map +1 -0
- package/package.json +9 -10
- package/register.js +1 -4
- package/register.js.map +1 -1
- package/sample-projects/javascript/hardhat.config.js +1 -1
- package/sample-projects/javascript/scripts/deploy.js +2 -2
- package/sample-projects/javascript-esm/LICENSE.md +11 -0
- package/sample-projects/javascript-esm/README.md +13 -0
- package/sample-projects/javascript-esm/contracts/Lock.sol +34 -0
- package/sample-projects/javascript-esm/hardhat.config.cjs +6 -0
- package/sample-projects/javascript-esm/scripts/deploy.js +22 -0
- package/sample-projects/javascript-esm/test/Lock.js +123 -0
- package/sample-projects/typescript/hardhat.config.ts +1 -1
- package/sample-projects/typescript/scripts/deploy.ts +2 -2
- package/sample-projects/typescript/tsconfig.json +2 -1
- package/src/builtin-tasks/compile.ts +28 -7
- package/src/builtin-tasks/flatten.ts +4 -1
- package/src/builtin-tasks/help.ts +15 -16
- package/src/builtin-tasks/task-names.ts +2 -0
- package/src/builtin-tasks/test.ts +30 -2
- package/src/internal/artifacts.ts +947 -0
- package/src/internal/cli/bootstrap.ts +14 -36
- package/src/internal/cli/cli.ts +38 -43
- package/src/internal/cli/project-creation.ts +128 -47
- package/src/internal/cli/prompt.ts +2 -4
- package/src/internal/cli/types.ts +2 -0
- package/src/internal/core/config/config-env.ts +15 -27
- package/src/internal/core/config/config-loading.ts +35 -11
- package/src/internal/core/config/config-validation.ts +20 -0
- package/src/internal/core/config/extenders.ts +6 -15
- package/src/internal/core/errors-list.ts +36 -10
- package/src/internal/core/project-structure.ts +8 -0
- package/src/internal/core/providers/construction.ts +29 -24
- package/src/internal/core/providers/http.ts +38 -26
- package/src/internal/core/runtime-environment.ts +65 -60
- package/src/internal/core/tasks/dsl.ts +17 -17
- package/src/internal/core/tasks/task-definitions.ts +6 -2
- package/src/internal/hardhat-network/jsonrpc/handler.ts +31 -28
- package/src/internal/hardhat-network/provider/modules/evm.ts +15 -3
- package/src/internal/hardhat-network/provider/node-types.ts +1 -1
- package/src/internal/hardhat-network/provider/node.ts +5 -1
- package/src/internal/hardhat-network/provider/provider.ts +60 -49
- package/src/internal/hardhat-network/provider/return-data.ts +2 -2
- package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +5 -2
- package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +5 -2
- package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +5 -2
- package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +46 -0
- package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +2 -2
- package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +71 -9
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/constants.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/debug.ts +9 -2
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +177 -89
- package/src/internal/hardhat-network/stack-traces/model.ts +11 -1
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
- package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +2 -2
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +3 -0
- package/src/internal/lib/hardhat-lib.ts +1 -6
- package/src/internal/solidity/compiler/downloader.ts +2 -2
- package/src/internal/solidity/compiler/index.ts +1 -1
- package/src/internal/solidity/resolver.ts +28 -11
- package/src/internal/util/abi-helpers.ts +9 -0
- package/src/internal/util/download.ts +13 -15
- package/src/internal/util/packageInfo.ts +24 -10
- package/src/internal/util/proxy.ts +18 -0
- package/src/register.ts +1 -6
- package/src/types/artifacts.ts +14 -112
- package/src/types/config.ts +2 -0
- package/src/types/runtime.ts +16 -13
- package/types/artifacts.d.ts +10 -96
- package/types/artifacts.d.ts.map +1 -1
- package/types/config.d.ts +2 -0
- package/types/config.d.ts.map +1 -1
- package/types/runtime.d.ts +9 -10
- package/types/runtime.d.ts.map +1 -1
- package/internal/artifacts/caching.d.ts +0 -28
- package/internal/artifacts/caching.d.ts.map +0 -1
- package/internal/artifacts/caching.js +0 -178
- package/internal/artifacts/caching.js.map +0 -1
- package/internal/artifacts/index.d.ts +0 -45
- package/internal/artifacts/index.d.ts.map +0 -1
- package/internal/artifacts/index.js +0 -191
- package/internal/artifacts/index.js.map +0 -1
- package/internal/artifacts/mutable.d.ts +0 -29
- package/internal/artifacts/mutable.d.ts.map +0 -1
- package/internal/artifacts/mutable.js +0 -226
- package/internal/artifacts/mutable.js.map +0 -1
- package/internal/artifacts/readonly.d.ts +0 -94
- package/internal/artifacts/readonly.d.ts.map +0 -1
- package/internal/artifacts/readonly.js +0 -343
- package/internal/artifacts/readonly.js.map +0 -1
- package/src/internal/artifacts/caching.ts +0 -259
- package/src/internal/artifacts/index.ts +0 -302
- package/src/internal/artifacts/mutable.ts +0 -330
- 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
|
+
});
|
|
@@ -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("
|
|
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
|
|
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
|
|
@@ -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
|
|
96
|
-
|
|
97
|
-
|
|
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(
|
|
762
|
+
console.error(errorMessage.replace(/^\w+:/, (t) => chalk.red.bold(t)));
|
|
746
763
|
} else {
|
|
747
|
-
console.warn(
|
|
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(
|
|
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(
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
HARDHAT_PARAM_DEFINITIONS,
|
|
22
|
-
tasks
|
|
23
|
-
);
|
|
23
|
+
if (taskName !== undefined) {
|
|
24
|
+
helpPrinter.printTaskHelp(taskName);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
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(
|
|
39
|
-
|
|
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
|
});
|