hardhat 2.9.9 → 2.10.2-dev.0
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/README.md +1 -1
- package/console.sol +444 -444
- package/internal/cli/cli.js +37 -7
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/hardhat-vscode-installation.d.ts +8 -0
- package/internal/cli/hardhat-vscode-installation.d.ts.map +1 -0
- package/internal/cli/hardhat-vscode-installation.js +41 -0
- package/internal/cli/hardhat-vscode-installation.js.map +1 -0
- package/internal/cli/project-creation.d.ts +0 -1
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +87 -179
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/prompt.d.ts +14 -0
- package/internal/cli/prompt.d.ts.map +1 -0
- package/internal/cli/prompt.js +120 -0
- package/internal/cli/prompt.js.map +1 -0
- package/internal/cli/types.d.ts +4 -0
- package/internal/cli/types.d.ts.map +1 -0
- package/internal/cli/types.js +3 -0
- package/internal/cli/types.js.map +1 -0
- package/internal/core/config/config-loading.js +1 -1
- package/internal/core/errors-list.js +4 -4
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +0 -4
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts +0 -15
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +1 -33
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +1 -1
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/node.js +1 -1
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +6 -2
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +5 -0
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.d.ts +223 -2
- package/internal/hardhat-network/stack-traces/logger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.js +445 -224
- package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/util/global-dir.d.ts +5 -0
- package/internal/util/global-dir.d.ts.map +1 -1
- package/internal/util/global-dir.js +17 -1
- package/internal/util/global-dir.js.map +1 -1
- package/internal/util/keys-derivation.d.ts.map +1 -1
- package/internal/util/keys-derivation.js +3 -1
- package/internal/util/keys-derivation.js.map +1 -1
- package/package.json +7 -6
- package/recommended-gitignore.txt +2 -0
- package/sample-projects/{basic → javascript}/LICENSE.md +1 -1
- package/sample-projects/javascript/README.md +13 -0
- package/sample-projects/javascript/contracts/Lock.sol +34 -0
- package/sample-projects/javascript/hardhat.config.js +6 -0
- package/sample-projects/javascript/scripts/deploy.js +29 -0
- package/sample-projects/javascript/test/Lock.js +126 -0
- package/sample-projects/typescript/LICENSE.md +11 -0
- package/sample-projects/typescript/README.md +13 -0
- package/sample-projects/typescript/contracts/Lock.sol +34 -0
- package/sample-projects/typescript/hardhat.config.ts +8 -0
- package/sample-projects/typescript/scripts/deploy.ts +23 -0
- package/sample-projects/typescript/test/Lock.ts +124 -0
- package/sample-projects/typescript/tsconfig.json +10 -0
- package/src/internal/cli/cli.ts +55 -7
- package/src/internal/cli/hardhat-vscode-installation.ts +43 -0
- package/src/internal/cli/project-creation.ts +124 -290
- package/src/internal/cli/prompt.ts +143 -0
- package/src/internal/cli/types.ts +3 -0
- package/src/internal/core/config/config-loading.ts +1 -1
- package/src/internal/core/errors-list.ts +4 -4
- package/src/internal/core/providers/construction.ts +0 -9
- package/src/internal/core/providers/gas-providers.ts +0 -39
- package/src/internal/hardhat-network/provider/modules/logger.ts +1 -1
- package/src/internal/hardhat-network/provider/node.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +9 -4
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +6 -0
- package/src/internal/hardhat-network/stack-traces/logger.ts +444 -223
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +1 -1
- package/src/internal/util/global-dir.ts +19 -0
- package/src/internal/util/keys-derivation.ts +3 -1
- package/sample-projects/advanced/.env.example +0 -3
- package/sample-projects/advanced/.eslintignore +0 -4
- package/sample-projects/advanced/.eslintrc.js +0 -22
- package/sample-projects/advanced/.prettierignore +0 -5
- package/sample-projects/advanced/.prettierrc +0 -1
- package/sample-projects/advanced/.solhint.json +0 -7
- package/sample-projects/advanced/.solhintignore +0 -1
- package/sample-projects/advanced/README.md +0 -42
- package/sample-projects/advanced/hardhat.config.js +0 -40
- package/sample-projects/advanced/npmignore +0 -3
- package/sample-projects/advanced/scripts/deploy.js +0 -30
- package/sample-projects/advanced-ts/.eslintrc.js +0 -24
- package/sample-projects/advanced-ts/README.md +0 -46
- package/sample-projects/advanced-ts/hardhat.config.ts +0 -43
- package/sample-projects/advanced-ts/npmignore +0 -3
- package/sample-projects/advanced-ts/scripts/deploy.ts +0 -30
- package/sample-projects/advanced-ts/test/index.ts +0 -19
- package/sample-projects/advanced-ts/tsconfig.json +0 -12
- package/sample-projects/basic/README.md +0 -15
- package/sample-projects/basic/contracts/Greeter.sol +0 -22
- package/sample-projects/basic/hardhat.config.js +0 -21
- package/sample-projects/basic/scripts/sample-script.js +0 -32
- package/sample-projects/basic/test/sample-test.js +0 -19
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ethers } from "hardhat";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
|
|
5
|
+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
|
6
|
+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
|
|
7
|
+
|
|
8
|
+
const lockedAmount = ethers.utils.parseEther("1");
|
|
9
|
+
|
|
10
|
+
const Lock = await ethers.getContractFactory("Lock");
|
|
11
|
+
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
|
12
|
+
|
|
13
|
+
await lock.deployed();
|
|
14
|
+
|
|
15
|
+
console.log("Lock with 1 ETH deployed to:", lock.address);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// We recommend this pattern to be able to use async/await everywhere
|
|
19
|
+
// and properly handle errors.
|
|
20
|
+
main().catch((error) => {
|
|
21
|
+
console.error(error);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
|
|
2
|
+
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
|
|
3
|
+
import { expect } from "chai";
|
|
4
|
+
import { ethers } from "hardhat";
|
|
5
|
+
|
|
6
|
+
describe("Lock", function () {
|
|
7
|
+
// We define a fixture to reuse the same setup in every test.
|
|
8
|
+
// We use loadFixture to run this setup once, snapshot that state,
|
|
9
|
+
// and reset Hardhat Network to that snapshopt in every test.
|
|
10
|
+
async function deployOneYearLockFixture() {
|
|
11
|
+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
|
12
|
+
const ONE_GWEI = 1_000_000_000;
|
|
13
|
+
|
|
14
|
+
const lockedAmount = ONE_GWEI;
|
|
15
|
+
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
|
16
|
+
|
|
17
|
+
// Contracts are deployed using the first signer/account by default
|
|
18
|
+
const [owner, otherAccount] = await ethers.getSigners();
|
|
19
|
+
|
|
20
|
+
const Lock = await ethers.getContractFactory("Lock");
|
|
21
|
+
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
|
22
|
+
|
|
23
|
+
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("Deployment", function () {
|
|
27
|
+
it("Should set the right unlockTime", async function () {
|
|
28
|
+
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
|
29
|
+
|
|
30
|
+
expect(await lock.unlockTime()).to.equal(unlockTime);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("Should set the right owner", async function () {
|
|
34
|
+
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
|
35
|
+
|
|
36
|
+
expect(await lock.owner()).to.equal(owner.address);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("Should receive and store the funds to lock", async function () {
|
|
40
|
+
const { lock, lockedAmount } = await loadFixture(
|
|
41
|
+
deployOneYearLockFixture
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(await ethers.provider.getBalance(lock.address)).to.equal(
|
|
45
|
+
lockedAmount
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("Should fail if the unlockTime is not in the future", async function () {
|
|
50
|
+
// We don't use the fixture here because we want a different deployment
|
|
51
|
+
const latestTime = await time.latest();
|
|
52
|
+
const Lock = await ethers.getContractFactory("Lock");
|
|
53
|
+
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
|
54
|
+
"Unlock time should be in the future"
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("Withdrawals", function () {
|
|
60
|
+
describe("Validations", function () {
|
|
61
|
+
it("Should revert with the right error if called too soon", async function () {
|
|
62
|
+
const { lock } = await loadFixture(deployOneYearLockFixture);
|
|
63
|
+
|
|
64
|
+
await expect(lock.withdraw()).to.be.revertedWith(
|
|
65
|
+
"You can't withdraw yet"
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("Should revert with the right error if called from another account", async function () {
|
|
70
|
+
const { lock, unlockTime, otherAccount } = await loadFixture(
|
|
71
|
+
deployOneYearLockFixture
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// We can increase the time in Hardhat Network
|
|
75
|
+
await time.increaseTo(unlockTime);
|
|
76
|
+
|
|
77
|
+
// We use lock.connect() to send a transaction from another account
|
|
78
|
+
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
|
79
|
+
"You aren't the owner"
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
|
84
|
+
const { lock, unlockTime } = await loadFixture(
|
|
85
|
+
deployOneYearLockFixture
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// Transactions are sent using the first signer by default
|
|
89
|
+
await time.increaseTo(unlockTime);
|
|
90
|
+
|
|
91
|
+
await expect(lock.withdraw()).not.to.be.reverted;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("Events", function () {
|
|
96
|
+
it("Should emit an event on withdrawals", async function () {
|
|
97
|
+
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
|
98
|
+
deployOneYearLockFixture
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await time.increaseTo(unlockTime);
|
|
102
|
+
|
|
103
|
+
await expect(lock.withdraw())
|
|
104
|
+
.to.emit(lock, "Withdrawal")
|
|
105
|
+
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("Transfers", function () {
|
|
110
|
+
it("Should transfer the funds to the owner", async function () {
|
|
111
|
+
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
|
112
|
+
deployOneYearLockFixture
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
await time.increaseTo(unlockTime);
|
|
116
|
+
|
|
117
|
+
await expect(lock.withdraw()).to.changeEtherBalances(
|
|
118
|
+
[owner, lock],
|
|
119
|
+
[lockedAmount, -lockedAmount]
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
package/src/internal/cli/cli.ts
CHANGED
|
@@ -21,6 +21,8 @@ import { Reporter } from "../sentry/reporter";
|
|
|
21
21
|
import { isRunningOnCiServer } from "../util/ci-detection";
|
|
22
22
|
import {
|
|
23
23
|
hasConsentedTelemetry,
|
|
24
|
+
hasPromptedForHHVSCode,
|
|
25
|
+
writePromptedForHHVSCode,
|
|
24
26
|
writeTelemetryConsent,
|
|
25
27
|
} from "../util/global-dir";
|
|
26
28
|
import { getPackageJson, PackageJson } from "../util/packageInfo";
|
|
@@ -29,7 +31,13 @@ import { applyWorkaround } from "../util/antlr-prototype-pollution-workaround";
|
|
|
29
31
|
import { Analytics } from "./analytics";
|
|
30
32
|
import { ArgumentsParser } from "./ArgumentsParser";
|
|
31
33
|
import { enableEmoji } from "./emoji";
|
|
32
|
-
import {
|
|
34
|
+
import { createProject } from "./project-creation";
|
|
35
|
+
import { confirmHHVSCodeInstallation, confirmTelemetryConsent } from "./prompt";
|
|
36
|
+
import {
|
|
37
|
+
InstallationState,
|
|
38
|
+
installHardhatVSCode,
|
|
39
|
+
isHardhatVSCodeInstalled,
|
|
40
|
+
} from "./hardhat-vscode-installation";
|
|
33
41
|
|
|
34
42
|
const log = debug("hardhat:core:cli");
|
|
35
43
|
|
|
@@ -56,6 +64,39 @@ To learn more about which versions of Node.js are supported go to https://hardha
|
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
|
|
67
|
+
async function suggestInstallingHardhatVscode() {
|
|
68
|
+
const alreadyPrompted = hasPromptedForHHVSCode();
|
|
69
|
+
if (alreadyPrompted) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const isInstalled = isHardhatVSCodeInstalled();
|
|
74
|
+
writePromptedForHHVSCode();
|
|
75
|
+
|
|
76
|
+
if (isInstalled !== InstallationState.EXTENSION_NOT_INSTALLED) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const installationConsent = await confirmHHVSCodeInstallation();
|
|
81
|
+
|
|
82
|
+
if (installationConsent === true) {
|
|
83
|
+
console.log("Installing Hardhat for Visual Studio Code...");
|
|
84
|
+
const installed = installHardhatVSCode();
|
|
85
|
+
|
|
86
|
+
if (installed) {
|
|
87
|
+
console.log("Hardhat for Visual Studio Code was successfully installed");
|
|
88
|
+
} else {
|
|
89
|
+
console.log(
|
|
90
|
+
"Hardhat for Visual Studio Code couldn't be installed. To learn more about it, go to https://hardhat.org/hardhat-vscode"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
console.log(
|
|
95
|
+
"To learn more about Hardhat for Visual Studio Code, go to https://hardhat.org/hardhat-vscode"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
59
100
|
async function main() {
|
|
60
101
|
// We first accept this argument anywhere, so we know if the user wants
|
|
61
102
|
// stack traces before really parsing the arguments.
|
|
@@ -103,12 +144,9 @@ async function main() {
|
|
|
103
144
|
if (hardhatArguments.config === undefined && !isCwdInsideProject()) {
|
|
104
145
|
if (
|
|
105
146
|
process.stdout.isTTY === true ||
|
|
106
|
-
process.env.
|
|
147
|
+
process.env.HARDHAT_CREATE_JAVASCRIPT_PROJECT_WITH_DEFAULTS !==
|
|
107
148
|
undefined ||
|
|
108
|
-
process.env.
|
|
109
|
-
undefined ||
|
|
110
|
-
process.env
|
|
111
|
-
.HARDHAT_CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
149
|
+
process.env.HARDHAT_CREATE_TYPESCRIPT_PROJECT_WITH_DEFAULTS !==
|
|
112
150
|
undefined
|
|
113
151
|
) {
|
|
114
152
|
await createProject();
|
|
@@ -226,6 +264,16 @@ async function main() {
|
|
|
226
264
|
} else {
|
|
227
265
|
abortAnalytics();
|
|
228
266
|
}
|
|
267
|
+
|
|
268
|
+
// VSCode extension prompt for installation
|
|
269
|
+
if (
|
|
270
|
+
taskName === "test" &&
|
|
271
|
+
!isRunningOnCiServer() &&
|
|
272
|
+
process.stdout.isTTY === true
|
|
273
|
+
) {
|
|
274
|
+
await suggestInstallingHardhatVscode();
|
|
275
|
+
}
|
|
276
|
+
|
|
229
277
|
log(`Killing Hardhat after successfully running task ${taskName}`);
|
|
230
278
|
} catch (error) {
|
|
231
279
|
let isHardhatError = false;
|
|
@@ -259,7 +307,7 @@ async function main() {
|
|
|
259
307
|
} else {
|
|
260
308
|
if (!isHardhatError) {
|
|
261
309
|
console.error(
|
|
262
|
-
`If you think this is a bug in Hardhat, please report it here: https://hardhat.org/
|
|
310
|
+
`If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bug`
|
|
263
311
|
);
|
|
264
312
|
}
|
|
265
313
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { spawnSync } from "child_process";
|
|
2
|
+
|
|
3
|
+
export enum InstallationState {
|
|
4
|
+
VSCODE_FAILED_OR_NOT_INSTALLED,
|
|
5
|
+
EXTENSION_INSTALLED,
|
|
6
|
+
EXTENSION_NOT_INSTALLED,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const HARDHAT_VSCODE_ID = "NomicFoundation.hardhat-solidity";
|
|
10
|
+
|
|
11
|
+
export function isHardhatVSCodeInstalled(): InstallationState {
|
|
12
|
+
try {
|
|
13
|
+
const { stdout, status } = spawnSync("code", ["--list-extensions"], {
|
|
14
|
+
encoding: "utf8",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (status !== 0) {
|
|
18
|
+
return InstallationState.VSCODE_FAILED_OR_NOT_INSTALLED;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return stdout.includes(HARDHAT_VSCODE_ID)
|
|
22
|
+
? InstallationState.EXTENSION_INSTALLED
|
|
23
|
+
: InstallationState.EXTENSION_NOT_INSTALLED;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
return InstallationState.VSCODE_FAILED_OR_NOT_INSTALLED;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function installHardhatVSCode(): boolean {
|
|
30
|
+
try {
|
|
31
|
+
const { status } = spawnSync(
|
|
32
|
+
"code",
|
|
33
|
+
["--install-extension", HARDHAT_VSCODE_ID],
|
|
34
|
+
{
|
|
35
|
+
encoding: "utf8",
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return status === 0;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|