Skip to content

Commit c8924e4

Browse files
fix: restore testing contracts tutorial (#140)
Restores the original flow in the "how to test contracts with Hardhat" tutorial, minor updates
1 parent 0b97e8f commit c8924e4

5 files changed

Lines changed: 42 additions & 49 deletions

File tree

.github/workflows/playwright.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ jobs:
7777

7878
# Setup Anvil for local testing
7979
- name: Run anvil-zksync
80-
# temporarily running anvil-zksync node for how-to-test-contracts tutorial
81-
if: matrix.tutorial.test-file-name != 'walletconnect' && matrix.tutorial.test-file-name != 'viem'
80+
if: matrix.tutorial.test-file-name != 'how-to-test-contracts' && matrix.tutorial.test-file-name != 'walletconnect' && matrix.tutorial.test-file-name != 'viem'
8281
uses: dutterbutter/anvil-zksync-action@v1.3.0
8382
with:
8483
token: ${{ secrets.GITHUB_TOKEN }}

code/test-contracts/hardhat.config.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ const config: HardhatUserConfig = {
2222
hardhat: {
2323
zksync: true,
2424
},
25-
anvilZKsync: {
26-
url: 'http://127.0.0.1:8011',
27-
ethNetwork: 'http://localhost:8545',
28-
zksync: true,
29-
accounts: process.env.WALLET_PRIVATE_KEY ? [process.env.WALLET_PRIVATE_KEY] : [],
30-
},
3125
},
3226
// ANCHOR_END: config
3327
};

content/tutorials/how-to-test-contracts/10.index.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
---
2-
title: How to test smart contracts with Hardhat
3-
description: Learn how to test your smart contracts locally using era-test-node and Hardhat
2+
title: How to test EraVM smart contracts with Hardhat
3+
description: Learn how to test your EraVM smart contracts locally using anvil-zksync and Hardhat
44
---
55

6-
7-
This tutorial provides a step-by-step guide on testing smart contracts using the `hardhat-chai-matchers` plugin
6+
This tutorial provides a step-by-step guide on testing EraVM smart contracts using the `hardhat-chai-matchers` plugin
87
in conjunction with the **Anvil ZKsync** node on your local machine.
98
To facilitate this process of running tests on the **Anvil ZKsync** node, you'll also utilize the `hardhat-zksync` plugin.
109

10+
Note that for EVM contracts,
11+
the standard method of [testing with Hardhat](https://hardhat.org/hardhat-runner/docs/guides/test-contracts) works out-of-the-box.
12+
To learn more about how EVM is supported,
13+
you can read about ZKsync's
14+
[EVM Interpreter](https://docs.zksync.io/zksync-era/unique-features/evm-interpreter/evm-interpreter) in the docs.
15+
1116
## Prerequisites
1217

1318
- Node.js installed (version 14.x or later)
14-
- Either yarn or npm installed
19+
- Either `yarn`, `npm`, `pnpm`, or `bun` installed
1520

16-
## Era-test-node plugin
21+
## Anvil ZKsync plugin
1722

1823
In this tutorial, the contract functionality is tested using [Anvil ZKsync](https://docs.zksync.io/build/test-and-debug/in-memory-node).
1924
To start local node we use the `hardhat-zksync` plugin to integrate this functionality within the Hardhat project.
@@ -68,14 +73,10 @@ Once installed, add the plugin at the top of your `hardhat.config.ts` file.
6873
6974
You can now run the **Anvil ZKsync node** with the following command:
7075
71-
```bash
72-
npx zksync-cli dev start
73-
```
76+
:test-action{actionId="run-hh-node"}
7477
75-
<!-- :test-action{actionId="run-hh-node"} -->
78+
::code-group
7679
77-
<!-- ::code-group -->
78-
<!--
7980
```bash [npx]
8081
npx hardhat node-zksync
8182
```
@@ -90,17 +91,17 @@ pnpm hardhat node-zksync
9091
9192
```bash [bun]
9293
bun hardhat node-zksync
93-
``` -->
94+
```
9495
95-
<!-- :: -->
96+
::
9697
97-
<!-- :test-action{actionId="wait-for-hh-node"} -->
98-
<!-- :test-action{actionId="test-hh-node"} -->
98+
:test-action{actionId="wait-for-hh-node"}
99+
:test-action{actionId="test-hh-node"}
99100
100-
<!-- ::callout{icon="i-heroicons-exclamation-circle"} -->
101-
<!-- We'll want to verify the correctness of our installations and test if we can run a **Anvil ZKsync node**,
102-
without further use of this command in the tutorial. -->
103-
<!-- :: -->
101+
::callout{icon="i-heroicons-exclamation-circle"}
102+
We'll want to verify the correctness of our installations and test if we can run a **Anvil ZKsync node**,
103+
without further use of this command in the tutorial.
104+
::
104105
105106
You should see the node endpoint logged in the console:
106107
@@ -110,9 +111,8 @@ You should see the node endpoint logged in the console:
110111
========================================
111112
```
112113
113-
<!--
114114
Since we've confirmed that the **Anvil ZKsync node** is functioning properly with the help of the `hardhat-zksync` plugin,
115-
we can shut it down and continue with the tutorial. -->
115+
we can shut it down and continue with the tutorial.
116116
117117
### Integration with Hardhat
118118
@@ -140,19 +140,19 @@ In the root directory of your project, execute this command:
140140
::code-group
141141
142142
```bash [npm]
143-
npm i -D @nomicfoundation/hardhat-chai-matchers chai@4.3.6
143+
npm i -D @nomicfoundation/hardhat-chai-matchers
144144
```
145145
146146
```bash [yarn]
147-
yarn add -D @nomicfoundation/hardhat-chai-matchers chai@4.3.6
147+
yarn add -D @nomicfoundation/hardhat-chai-matchers
148148
```
149149
150150
```bash [pnpm]
151-
pnpm add -D @nomicfoundation/hardhat-chai-matchers chai@4.3.6
151+
pnpm add -D @nomicfoundation/hardhat-chai-matchers
152152
```
153153
154154
```bash [bun]
155-
bun add -D @nomicfoundation/hardhat-chai-matchers chai@4.3.6
155+
bun add -D @nomicfoundation/hardhat-chai-matchers
156156
```
157157
158158
::
@@ -220,19 +220,19 @@ Execute the following command in your terminal to run the tests:
220220
::code-group
221221
222222
```bash [npx]
223-
npx hardhat test --network anvilZKsync
223+
npx hardhat test
224224
```
225225
226226
```bash [yarn]
227-
yarn hardhat test --network anvilZKsync
227+
yarn hardhat test
228228
```
229229
230230
```bash [pnpm]
231-
pnpm hardhat test --network anvilZKsync
231+
pnpm hardhat test
232232
```
233233
234234
```bash [bun]
235-
bun hardhat test --network anvilZKsync
235+
bun hardhat test
236236
```
237237
238238
::
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: How to test contracts with Hardhat
1+
title: How to test EraVM contracts with Hardhat
22
authors:
33
- name: Matter Labs
44
url: https://matter-labs.io
@@ -9,14 +9,14 @@ tags:
99
- how-to
1010
- testing
1111
- hardhat
12-
summary: Learn how to test smart contracts with Hardhat
13-
description: This how-to guide explains how to test smart contracts on ZKsync using Hardhat.
12+
summary: Learn how to test EraVM smart contracts with Hardhat
13+
description: This how-to guide explains how to test EraVM smart contracts on ZKsync using Hardhat.
1414
what_you_will_learn:
15-
- How to install era-test-node.
16-
- How to write local tests for smart contracts.
17-
updated: 2025-07-09
15+
- How to write local tests for smart contracts
16+
- How to test with anvil-zksync
17+
updated: 2025-07-14
1818
tools:
1919
- zksync-ethers
2020
- hardhat-zksync-deploy
2121
- hardhat-chai-matchers
22-
- era-test-node
22+
- anvil-zksync

tests/configs/how-to-test-contracts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ const steps: IStepConfig = {
7070
action: 'writeToFile',
7171
filepath: 'tests-output/hardhat-project/test/test.ts',
7272
},
73-
// 'run-test': {
74-
// action: 'runCommand',
75-
// commandFolder: 'tests-output/hardhat-project',
76-
// },
73+
'run-test': {
74+
action: 'runCommand',
75+
commandFolder: 'tests-output/hardhat-project',
76+
},
7777
};
7878

7979
export default steps;

0 commit comments

Comments
 (0)