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
87in conjunction with the ** Anvil ZKsync** node on your local machine.
98To 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
1823In this tutorial, the contract functionality is tested using [ Anvil ZKsync] ( https://docs.zksync.io/build/test-and-debug/in-memory-node ) .
1924To 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
6974You 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 ]
8081npx hardhat node -zksync
8182` ` `
@@ -90,17 +91,17 @@ pnpm hardhat node-zksync
9091
9192` ` ` bash [bun ]
9293bun 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
105106You 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- <!--
114114Since 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::
0 commit comments