hardhat 3.5.1 → 3.6.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/CHANGELOG.md +28 -0
- package/dist/src/internal/builtin-plugins/flatten/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.js +23 -7
- package/dist/src/internal/builtin-plugins/flatten/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +78 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js +1 -5
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts +53 -1
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/cli/help/utils.d.ts.map +1 -1
- package/dist/src/internal/cli/help/utils.js +3 -2
- package/dist/src/internal/cli/help/utils.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +110 -1
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/main.d.ts.map +1 -1
- package/dist/src/internal/cli/main.js +3 -1
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.js +3 -2
- package/dist/src/internal/core/tasks/resolved-task.js.map +1 -1
- package/dist/src/internal/core/tasks/utils.d.ts +3 -0
- package/dist/src/internal/core/tasks/utils.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/utils.js +6 -0
- package/dist/src/internal/core/tasks/utils.js.map +1 -1
- package/dist/src/internal/core/tasks/validations.js +3 -3
- package/dist/src/internal/core/tasks/validations.js.map +1 -1
- package/dist/src/types/solidity/build-system.d.ts +22 -2
- package/dist/src/types/solidity/build-system.d.ts.map +1 -1
- package/dist/src/types/solidity/build-system.js.map +1 -1
- package/package.json +4 -3
- package/skills/hardhat/SKILL.md +152 -0
- package/skills/hardhat-toolbox-mocha-ethers/SKILL.md +119 -0
- package/skills/hardhat-toolbox-viem/SKILL.md +126 -0
- package/src/internal/builtin-plugins/flatten/task-action.ts +37 -7
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +124 -6
- package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +1 -1
- package/src/internal/builtin-plugins/solidity/tasks/build.ts +1 -6
- package/src/internal/builtin-plugins/solidity/type-extensions.ts +69 -0
- package/src/internal/cli/help/utils.ts +9 -2
- package/src/internal/cli/init/init.ts +136 -0
- package/src/internal/cli/main.ts +4 -2
- package/src/internal/core/tasks/resolved-task.ts +5 -2
- package/src/internal/core/tasks/utils.ts +13 -0
- package/src/internal/core/tasks/validations.ts +3 -3
- package/src/types/solidity/build-system.ts +24 -5
- package/templates/hardhat-3/01-node-test-runner-viem/AGENTS.md +20 -0
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +3 -3
- package/templates/hardhat-3/02-mocha-ethers/AGENTS.md +20 -0
- package/templates/hardhat-3/02-mocha-ethers/package.json +3 -3
- package/templates/hardhat-3/03-minimal/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-system.d.ts","sourceRoot":"","sources":["../../../../src/types/solidity/build-system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,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-system.js","sourceRoot":"","sources":["../../../../src/types/solidity/build-system.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-system.js","sourceRoot":"","sources":["../../../../src/types/solidity/build-system.ts"],"names":[],"mappings":"AA6GA,MAAM,CAAN,IAAY,iCAmCX;AAnCD,WAAY,iCAAiC;IAC3C;;OAEG;IACH,kHAA6E,CAAA;IAE7E;;OAEG;IACH,8HAAyF,CAAA;IAEzF;;OAEG;IACH,gGAA2D,CAAA;IAE3D;;OAEG;IACH,oJAA+G,CAAA;IAE/G;;OAEG;IACH,kHAA6E,CAAA;IAE7E;;OAEG;IACH,kJAA6G,CAAA;IAE7G;;OAEG;IACH,0GAAqE,CAAA;AACvE,CAAC,EAnCW,iCAAiC,KAAjC,iCAAiC,QAmC5C;AAyDD;;GAEG;AACH,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,8CAAuB,CAAA;IACvB,sDAA+B,CAAA;IAC/B,sDAA+B,CAAA;AACjC,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hardhat",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.",
|
|
5
5
|
"homepage": "https://hardhat.org",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"src/",
|
|
58
58
|
"templates/",
|
|
59
59
|
"console.sol",
|
|
60
|
+
"skills/",
|
|
60
61
|
"CHANGELOG.md",
|
|
61
62
|
"LICENSE",
|
|
62
63
|
"README.md"
|
|
@@ -77,8 +78,8 @@
|
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
80
|
"@nomicfoundation/edr": "0.12.0-next.33",
|
|
80
|
-
"@nomicfoundation/hardhat-errors": "^3.0.
|
|
81
|
-
"@nomicfoundation/hardhat-utils": "^4.1.
|
|
81
|
+
"@nomicfoundation/hardhat-errors": "^3.0.14",
|
|
82
|
+
"@nomicfoundation/hardhat-utils": "^4.1.3",
|
|
82
83
|
"@nomicfoundation/hardhat-vendored": "^3.0.4",
|
|
83
84
|
"@nomicfoundation/hardhat-zod-utils": "^3.0.5",
|
|
84
85
|
"@nomicfoundation/solidity-analyzer": "^0.1.1",
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hardhat
|
|
3
|
+
description: Use when working with Hardhat 3 projects — writing or modifying Solidity tests, TypeScript tests, or any code touching hardhat.config.ts, the `hardhat` import, or `network.create()`. Covers test-layer choice, forge-std cheatcodes, the network connection API, `networkHelpers`, and the compile-then-typecheck workflow. For toolbox-specific guidance (clients, contract calls, assertions), also load the matching `hardhat-toolbox-*` skill.
|
|
4
|
+
metadata:
|
|
5
|
+
package: "hardhat"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Hardhat 3
|
|
9
|
+
|
|
10
|
+
This skill covers Hardhat 3 itself. The toolbox layer (clients, contract interaction, ecosystem-specific assertions) lives in companion skills — load whichever matches the project:
|
|
11
|
+
|
|
12
|
+
- `@nomicfoundation/hardhat-toolbox-viem` → also load the **`hardhat-toolbox-viem`** skill.
|
|
13
|
+
- `@nomicfoundation/hardhat-toolbox-mocha-ethers` → also load the **`hardhat-toolbox-mocha-ethers`** skill.
|
|
14
|
+
|
|
15
|
+
## Test organization
|
|
16
|
+
|
|
17
|
+
Hardhat 3 supports two distinct test layers:
|
|
18
|
+
|
|
19
|
+
**Solidity tests** (`.t.sol` files in `contracts/`, or any `.sol` file in `test/`) are the default choice for unit tests on individual contracts. They run directly in the EVM, compile-check against the real ABI, and have access to cheatcodes for EVM state manipulation. Any public function whose name starts with `test` is executed as a test case.
|
|
20
|
+
|
|
21
|
+
**TypeScript tests** (`.ts` files in `test/`) are the right choice when a test requires off-chain orchestration: multi-contract interactions, fixture reuse across a large suite, assertions about gas or ETH balances from the outside, or integration scenarios driven by external state.
|
|
22
|
+
|
|
23
|
+
Reach for TypeScript only when Solidity isn't enough. Solidity tests cover all contract logic; TypeScript tests cover the end-to-end flow as a user or script would experience it.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
hardhat test # run all tests (Solidity + TypeScript)
|
|
27
|
+
hardhat test solidity # Solidity tests only
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
TypeScript tests are run either with `hardhat test nodejs` or with `hardhat test mocha`, depending on the toolbox or plugins being used: the viem-based toolbox uses `nodejs` while the ethers+mocha toolbox uses `mocha`.
|
|
31
|
+
|
|
32
|
+
Pass `--coverage` to collect Solidity coverage while running tests. It works on the main `hardhat test` task as well as the `solidity` and TypeScript subtasks (`nodejs` / `mocha`), so you can scope coverage to a single test layer when needed.
|
|
33
|
+
|
|
34
|
+
## Solidity tests
|
|
35
|
+
|
|
36
|
+
Any contract that contains at least one `test*` function is treated as a test contract. Use `forge-std` (if present in `package.json`) for assertions and cheatcodes:
|
|
37
|
+
|
|
38
|
+
```solidity
|
|
39
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
40
|
+
pragma solidity ^0.8.28;
|
|
41
|
+
|
|
42
|
+
import { Test } from "forge-std/Test.sol";
|
|
43
|
+
import { Counter } from "./Counter.sol";
|
|
44
|
+
|
|
45
|
+
contract CounterTest is Test {
|
|
46
|
+
Counter counter;
|
|
47
|
+
|
|
48
|
+
function setUp() public {
|
|
49
|
+
counter = new Counter();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function test_InitialValueIsZero() public view {
|
|
53
|
+
assertEq(counter.x(), 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function test_IncByIncreasesByAmount() public {
|
|
57
|
+
counter.incBy(3);
|
|
58
|
+
assertEq(counter.x(), 3);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Fuzz test: Hardhat runs this with many random inputs automatically
|
|
62
|
+
function testFuzz_Inc(uint8 x) public {
|
|
63
|
+
for (uint8 i = 0; i < x; i++) {
|
|
64
|
+
counter.inc();
|
|
65
|
+
}
|
|
66
|
+
require(counter.x() == x, "Value after calling inc x times should be x");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The `vm` object (from `forge-std/Test.sol`) exposes cheatcodes for EVM state manipulation. Commonly used ones:
|
|
72
|
+
|
|
73
|
+
| Cheatcode | Effect |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `vm.prank(addr)` | Sets `msg.sender` for the next call only |
|
|
76
|
+
| `vm.startPrank(addr)` / `vm.stopPrank()` | Sets `msg.sender` for a range of calls |
|
|
77
|
+
| `vm.deal(addr, amount)` | Sets an account's ETH balance |
|
|
78
|
+
| `vm.warp(timestamp)` | Sets `block.timestamp` |
|
|
79
|
+
| `vm.roll(blockNum)` | Sets `block.number` |
|
|
80
|
+
| `vm.expectRevert(...)` | Asserts the next call reverts |
|
|
81
|
+
| `vm.expectEmit(...)` | Asserts the next call emits a specific event |
|
|
82
|
+
|
|
83
|
+
## TypeScript tests and the network connection
|
|
84
|
+
|
|
85
|
+
The central object in a TypeScript test is the **network connection**, created by `network.create()`. Toolbox plugins extend it with helper objects (e.g. `viem` or `ethers`, plus `networkHelpers`):
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { network } from "hardhat";
|
|
89
|
+
|
|
90
|
+
const { networkHelpers } = await network.create();
|
|
91
|
+
// Toolbox plugins also expose viem / ethers on this object;
|
|
92
|
+
// see the matching hardhat-toolbox-* skill.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Hardhat 3 only works with ESM, so top-level `await` is available. Each call to `network.create()` produces an **isolated blockchain state**. A top-level network connection can be used when the same connection and its associated state can be shared across all tests in the file. For more isolation, you can create a new connection for each test suite or even each test case.
|
|
96
|
+
|
|
97
|
+
### `networkHelpers`: EVM state manipulation
|
|
98
|
+
|
|
99
|
+
`networkHelpers` wraps all of Hardhat's development-only helpers behind a typed, ergonomic API. Prefer it over raw JSON-RPC calls:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
// Time
|
|
103
|
+
await networkHelpers.time.increase(60); // mine a block 60 s ahead
|
|
104
|
+
await networkHelpers.time.increaseTo(target); // mine to a specific timestamp
|
|
105
|
+
const now = await networkHelpers.time.latest(); // latest block timestamp
|
|
106
|
+
await networkHelpers.time.setNextBlockTimestamp(ts); // set without mining
|
|
107
|
+
|
|
108
|
+
// Blocks
|
|
109
|
+
await networkHelpers.mine(); // mine one block
|
|
110
|
+
await networkHelpers.mine(5); // mine several blocks
|
|
111
|
+
|
|
112
|
+
// Accounts
|
|
113
|
+
await networkHelpers.impersonateAccount(addr);
|
|
114
|
+
await networkHelpers.setBalance(addr, 10n ** 18n);
|
|
115
|
+
|
|
116
|
+
// Block parameters
|
|
117
|
+
await networkHelpers.setPrevRandao(value); // set block.prevrandao for the next block
|
|
118
|
+
await networkHelpers.setNextBlockBaseFeePerGas(baseFee);
|
|
119
|
+
|
|
120
|
+
// Fixtures
|
|
121
|
+
//
|
|
122
|
+
// loadFixture runs the setup once and snapshots the state. Subsequent calls
|
|
123
|
+
// restore the snapshot instead of re-deploying, much faster for large suites.
|
|
124
|
+
// The deploy step inside the fixture is toolbox-specific (e.g.
|
|
125
|
+
// viem.deployContract, an ethers ContractFactory) — see the matching
|
|
126
|
+
// hardhat-toolbox-* skill.
|
|
127
|
+
async function deployCounter() {
|
|
128
|
+
// ... toolbox-specific deploy ...
|
|
129
|
+
return { counter };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const { counter } = await networkHelpers.loadFixture(deployCounter);
|
|
133
|
+
// loadFixture requires a named function for caching to work (not an
|
|
134
|
+
// arrow/anonymous function)
|
|
135
|
+
|
|
136
|
+
// Snapshots (manual)
|
|
137
|
+
const snap = await networkHelpers.takeSnapshot();
|
|
138
|
+
// ... do things ...
|
|
139
|
+
await snap.restore();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
For plain TypeScript assertions (equality, arrays, types), use `node:assert/strict`. For ecosystem-specific assertions (reverts, events, balance changes), see the matching `hardhat-toolbox-*` skill.
|
|
143
|
+
|
|
144
|
+
## Typechecking
|
|
145
|
+
|
|
146
|
+
Generated contract types are derived from the compiled ABI (viem in the viem toolbox, TypeChain in the ethers toolbox), so recompile first, then typecheck. The example below uses npm; swap `npx` for whichever package manager runner this project uses:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npx hardhat build && npx tsc --noEmit
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The compiler will catch wrong argument types, missing arguments, and invalid options (e.g. `value` on a non-payable function) before you even start the test runner. Make this a habit: it surfaces many mistakes faster than running the full test suite.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hardhat-toolbox-mocha-ethers
|
|
3
|
+
description: Use alongside the `hardhat` skill when the project depends on `@nomicfoundation/hardhat-toolbox-mocha-ethers`. Covers the ethers helpers exposed on `network.create()`, contract interaction (`ethers.deployContract`, calling functions, `connect`), TypeChain-typed contract instances, and the chai matchers from `@nomicfoundation/hardhat-ethers-chai-matchers` (`.to.emit`, `.to.be.revertedWith*`, `.to.changeEtherBalance(s)`).
|
|
4
|
+
metadata:
|
|
5
|
+
package: "@nomicfoundation/hardhat-toolbox-mocha-ethers"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Hardhat toolbox: ethers + Mocha
|
|
9
|
+
|
|
10
|
+
This skill builds on the core **`hardhat`** skill. Load that first for test organization, the `network.create()` shape, `networkHelpers`, fixtures, and the typechecking workflow. Everything below hangs off the connection returned by `network.create()`.
|
|
11
|
+
|
|
12
|
+
This stack runs tests under **Mocha** (global `describe` / `it`) and asserts with **chai**. Mocha doesn't await `describe` callbacks, so the connection is set up at the top of the file with top-level `await`:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { expect } from "chai";
|
|
16
|
+
import { network } from "hardhat";
|
|
17
|
+
|
|
18
|
+
const { ethers, networkHelpers } = await network.create();
|
|
19
|
+
|
|
20
|
+
describe("Counter", function () {
|
|
21
|
+
// ...
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
One connection per file is the norm. State isolation between tests comes from `loadFixture` (see the `hardhat` skill), not from creating a fresh connection per `describe`.
|
|
26
|
+
|
|
27
|
+
## `ethers`: signers and contract interaction
|
|
28
|
+
|
|
29
|
+
Contract types are generated by **TypeChain** from the compiled ABI. Run `hardhat build` before typechecking so the types reflect the latest contracts.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// Provider (read-only chain data)
|
|
33
|
+
const blockNumber = await ethers.provider.getBlockNumber();
|
|
34
|
+
const balance = await ethers.provider.getBalance("0xabc...");
|
|
35
|
+
|
|
36
|
+
// Signers (for sending transactions)
|
|
37
|
+
const [owner, alice, bob] = await ethers.getSigners(); // default funded accounts
|
|
38
|
+
|
|
39
|
+
// Utilities
|
|
40
|
+
const oneEth = ethers.parseEther("1.0");
|
|
41
|
+
|
|
42
|
+
// Deploy a contract, returns a fully typed instance.
|
|
43
|
+
// Pass constructor args as the second argument, and (optionally) a signer
|
|
44
|
+
// other than the default as the third.
|
|
45
|
+
const counter = await ethers.deployContract("Counter");
|
|
46
|
+
const counterWithArgs = await ethers.deployContract("Counter", [42n]);
|
|
47
|
+
const counterFromAlice = await ethers.deployContract("Counter", [], alice);
|
|
48
|
+
|
|
49
|
+
// Read state and call functions. Args and return types are type-checked
|
|
50
|
+
// against the ABI at compile time; passing wrong types or wrong argument
|
|
51
|
+
// counts is a TypeScript error.
|
|
52
|
+
const value = await counter.x();
|
|
53
|
+
await counter.inc();
|
|
54
|
+
await counter.incBy(3n);
|
|
55
|
+
|
|
56
|
+
// Send from a different signer
|
|
57
|
+
await counter.connect(alice).inc();
|
|
58
|
+
|
|
59
|
+
// Send ETH along with a payable call
|
|
60
|
+
await counter.deposit({ value: oneEth });
|
|
61
|
+
|
|
62
|
+
// Attach to an already-deployed contract
|
|
63
|
+
const existing = await ethers.getContractAt("Counter", "0xabc...");
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Inside a `loadFixture` setup function (see the `hardhat` skill for the surrounding pattern), `ethers.deployContract` is the canonical deploy step:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
async function deployCounterFixture() {
|
|
70
|
+
const counter = await ethers.deployContract("Counter");
|
|
71
|
+
return { counter };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { counter } = await networkHelpers.loadFixture(deployCounterFixture);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
To send a transaction from an arbitrary address (not one of the default-funded accounts), fund it for gas and pull an impersonating signer with `ethers.getImpersonatedSigner` — it handles the impersonation internally, no separate `networkHelpers.impersonateAccount` call needed:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const addr = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
81
|
+
await networkHelpers.setBalance(addr, ethers.parseEther("1.0"));
|
|
82
|
+
const signer = await ethers.getImpersonatedSigner(addr);
|
|
83
|
+
await counter.connect(signer).inc();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Chai matchers: Ethereum-specific assertions
|
|
87
|
+
|
|
88
|
+
The `hardhat-ethers-chai-matchers` plugin extends chai's `expect` with matchers for transactions, events, and balance changes. Pass the **transaction promise** (the result of a write call, unawaited) into `expect`:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { expect } from "chai";
|
|
92
|
+
|
|
93
|
+
// Reverts
|
|
94
|
+
await expect(counter.connect(banned).inc()).to.revert(ethers);
|
|
95
|
+
await expect(counter.connect(banned).inc()).to.be.revertedWith(
|
|
96
|
+
"only the owner can increment the counter",
|
|
97
|
+
);
|
|
98
|
+
await expect(counter.connect(banned).inc()).to.be.revertedWithCustomError(
|
|
99
|
+
counter,
|
|
100
|
+
"Unauthorized",
|
|
101
|
+
);
|
|
102
|
+
await expect(counter.connect(banned).inc())
|
|
103
|
+
.to.be.revertedWithCustomError(counter, "Unauthorized")
|
|
104
|
+
.withArgs(banned.address);
|
|
105
|
+
|
|
106
|
+
// Events
|
|
107
|
+
await expect(counter.inc()).to.emit(counter, "Increment");
|
|
108
|
+
await expect(counter.inc()).to.emit(counter, "Increment").withArgs(1n);
|
|
109
|
+
|
|
110
|
+
// ETH balance changes (positive = received, negative = spent, before gas)
|
|
111
|
+
await expect(game.claim()).to.changeEtherBalance(ethers, winner, PRIZE);
|
|
112
|
+
await expect(game.claim()).to.changeEtherBalances(
|
|
113
|
+
ethers,
|
|
114
|
+
[winner, loser],
|
|
115
|
+
[PRIZE, -STAKE],
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
For plain assertions (equality, arrays, types), use `expect` from chai directly without the Ethereum matchers.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hardhat-toolbox-viem
|
|
3
|
+
description: Use alongside the `hardhat` skill when the project depends on `@nomicfoundation/hardhat-toolbox-viem`. Covers the viem clients exposed on `network.create()`, contract interaction (`viem.deployContract`, `read`, `write`, `getContractAt`), and `viem.assertions` (revert / event / balance assertions).
|
|
4
|
+
metadata:
|
|
5
|
+
package: "@nomicfoundation/hardhat-toolbox-viem"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Hardhat toolbox: viem
|
|
9
|
+
|
|
10
|
+
This skill builds on the core **`hardhat`** skill. Load that first for test organization, the `network.create()` shape, `networkHelpers`, fixtures, and the typechecking workflow. Everything below hangs off the connection returned by `network.create()`:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { network } from "hardhat";
|
|
14
|
+
import { describe, it } from "node:test";
|
|
15
|
+
import assert from "node:assert/strict";
|
|
16
|
+
|
|
17
|
+
describe("Counter", async function () {
|
|
18
|
+
const { viem, networkHelpers } = await network.create();
|
|
19
|
+
// ...
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## `viem`: clients and contract interaction
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// Clients
|
|
27
|
+
const publicClient = await viem.getPublicClient();
|
|
28
|
+
const [owner, alice, bob] = await viem.getWalletClients(); // default accounts
|
|
29
|
+
const testClient = await viem.getTestClient(); // dev-only operations
|
|
30
|
+
|
|
31
|
+
// Deploy a contract, returns a fully typed instance
|
|
32
|
+
const counter = await viem.deployContract("Counter");
|
|
33
|
+
|
|
34
|
+
// Read state (return type inferred from ABI)
|
|
35
|
+
const value = await counter.read.x();
|
|
36
|
+
|
|
37
|
+
// Write transactions. Args and options are type-checked against the ABI at
|
|
38
|
+
// compile time; passing wrong types, wrong argument counts, or `value` on a
|
|
39
|
+
// non-payable function is a TypeScript error
|
|
40
|
+
await counter.write.inc();
|
|
41
|
+
await counter.write.inc({ account: alice.account }); // different sender
|
|
42
|
+
await counter.write.incBy([3n]); // with args
|
|
43
|
+
await counter.write.deposit({ value: 10n ** 18n }); // no parameters and payable
|
|
44
|
+
|
|
45
|
+
// Attach to an already-deployed contract
|
|
46
|
+
const existing = await viem.getContractAt("Counter", "0xabc...");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Avoid using `walletClient.writeContract` to interact with contracts — it has no ABI typing, so wrong args slip through. Prefer the typed instance returned by `viem.deployContract` or `viem.getContractAt`.
|
|
50
|
+
|
|
51
|
+
Inside a `loadFixture` setup function (see the `hardhat` skill for the surrounding pattern), `viem.deployContract` is the canonical deploy step:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
async function deployCounter() {
|
|
55
|
+
const counter = await viem.deployContract("Counter");
|
|
56
|
+
return { counter };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { counter } = await networkHelpers.loadFixture(deployCounter);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## `viem.assertions`: Ethereum-specific assertions
|
|
63
|
+
|
|
64
|
+
Use `viem.assertions` for contract-specific checks. Pass the **unawaited** transaction promise as the first argument:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// Reverts
|
|
68
|
+
await viem.assertions.revert(counter.write.inc({ account: banned }));
|
|
69
|
+
await viem.assertions.revertWith(
|
|
70
|
+
counter.write.inc({ account: banned }),
|
|
71
|
+
"Not authorized",
|
|
72
|
+
);
|
|
73
|
+
await viem.assertions.revertWithCustomError(
|
|
74
|
+
counter.write.inc({ account: banned }),
|
|
75
|
+
counter,
|
|
76
|
+
"Unauthorized",
|
|
77
|
+
);
|
|
78
|
+
await viem.assertions.revertWithCustomErrorWithArgs(
|
|
79
|
+
counter.write.inc({ account: banned }),
|
|
80
|
+
counter,
|
|
81
|
+
"Unauthorized",
|
|
82
|
+
[banned],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Events
|
|
86
|
+
await viem.assertions.emit(counter.write.inc(), counter, "Increment");
|
|
87
|
+
await viem.assertions.emitWithArgs(counter.write.inc(), counter, "Increment", [
|
|
88
|
+
1n,
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// ETH balance changes (positive = received, negative = spent, before gas)
|
|
92
|
+
await viem.assertions.balancesHaveChanged(game.write.claim(), {
|
|
93
|
+
[winner]: PRIZE,
|
|
94
|
+
[loser]: -STAKE,
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The `*WithArgs` matchers (`revertWithCustomErrorWithArgs` and `emitWithArgs`) accept a `(value) => boolean` predicate at any arg position, alongside concrete values. The plugin also ships an `anyValue` helper for positions you don't care about:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { anyValue } from "@nomicfoundation/hardhat-toolbox-viem/predicates";
|
|
102
|
+
|
|
103
|
+
// Inline predicate at any arg position. Useful for ranges or computed conditions.
|
|
104
|
+
await viem.assertions.revertWithCustomErrorWithArgs(
|
|
105
|
+
contract.write.failing(),
|
|
106
|
+
contract,
|
|
107
|
+
"BadValue",
|
|
108
|
+
[(n: bigint) => n > 100n, "another error arg"],
|
|
109
|
+
);
|
|
110
|
+
await viem.assertions.emitWithArgs(
|
|
111
|
+
counter.write.incBy([3n]),
|
|
112
|
+
counter,
|
|
113
|
+
"Increment",
|
|
114
|
+
[(by: bigint) => by >= 1n],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// `anyValue` matches anything — handy for fields you don't care about.
|
|
118
|
+
await viem.assertions.revertWithCustomErrorWithArgs(
|
|
119
|
+
contract.write.failing(),
|
|
120
|
+
contract,
|
|
121
|
+
"BadValue",
|
|
122
|
+
[anyValue, "another error arg"],
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
For plain TypeScript assertions (equality, arrays, types), use `node:assert/strict`.
|
|
@@ -2,6 +2,7 @@ import type { NewTaskActionFunction } from "../../../types/tasks.js";
|
|
|
2
2
|
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
4
|
|
|
5
|
+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
|
5
6
|
import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
6
7
|
|
|
7
8
|
import {
|
|
@@ -261,7 +262,8 @@ function getPragmaAbicoderDirectiveInfo(
|
|
|
261
262
|
};
|
|
262
263
|
}
|
|
263
264
|
|
|
264
|
-
// Returns files sorted in topological order
|
|
265
|
+
// Returns files sorted in topological order. Throws if the graph contains a
|
|
266
|
+
// cycle.
|
|
265
267
|
function getSortedFiles(dependencyGraph: DependencyGraph): ResolvedFile[] {
|
|
266
268
|
const sortedFiles: ResolvedFile[] = [];
|
|
267
269
|
const visitedFiles = new Set<ResolvedFile>();
|
|
@@ -273,30 +275,58 @@ function getSortedFiles(dependencyGraph: DependencyGraph): ResolvedFile[] {
|
|
|
273
275
|
);
|
|
274
276
|
};
|
|
275
277
|
|
|
276
|
-
// Depth-first walking
|
|
277
|
-
|
|
278
|
+
// Depth-first walking. `importChain` is the chain of files leading to the
|
|
279
|
+
// current visit; a dep that reappears in it indicates a cycle.
|
|
280
|
+
const walk = (
|
|
281
|
+
files: ResolvedFile[],
|
|
282
|
+
importChain: readonly ResolvedFile[],
|
|
283
|
+
) => {
|
|
278
284
|
for (const file of files) {
|
|
279
|
-
if (visitedFiles.has(file))
|
|
285
|
+
if (visitedFiles.has(file)) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
280
288
|
|
|
281
|
-
|
|
289
|
+
throwIfCycle(file, importChain);
|
|
282
290
|
|
|
283
291
|
const dependencies = sortBySourceName(
|
|
284
292
|
Array.from(dependencyGraph.getDependencies(file)).map((d) => d.file),
|
|
285
293
|
);
|
|
286
294
|
|
|
287
|
-
walk(dependencies);
|
|
295
|
+
walk(dependencies, [...importChain, file]);
|
|
288
296
|
|
|
297
|
+
visitedFiles.add(file);
|
|
289
298
|
sortedFiles.push(file);
|
|
290
299
|
}
|
|
291
300
|
};
|
|
292
301
|
|
|
293
302
|
const roots = sortBySourceName(dependencyGraph.getRoots().values());
|
|
294
303
|
|
|
295
|
-
walk(roots);
|
|
304
|
+
walk(roots, []);
|
|
296
305
|
|
|
297
306
|
return sortedFiles;
|
|
298
307
|
}
|
|
299
308
|
|
|
309
|
+
function throwIfCycle(
|
|
310
|
+
file: ResolvedFile,
|
|
311
|
+
importChain: readonly ResolvedFile[],
|
|
312
|
+
): void {
|
|
313
|
+
const cycleStart = importChain.indexOf(file);
|
|
314
|
+
|
|
315
|
+
if (cycleStart === -1) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const cycle = [
|
|
320
|
+
...importChain.slice(cycleStart).map(formatSourceName),
|
|
321
|
+
formatSourceName(file),
|
|
322
|
+
].join(" -> ");
|
|
323
|
+
|
|
324
|
+
throw new HardhatError(
|
|
325
|
+
HardhatError.ERRORS.CORE.BUILTIN_TASKS.FLATTEN_CYCLIC_DEPENDENCY,
|
|
326
|
+
{ cycle },
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
300
330
|
function removeDuplicateAndSurroundingWhitespaces(str: string): string {
|
|
301
331
|
return str.replace(/\s+/g, " ").trim();
|
|
302
332
|
}
|