Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Jul 24, 2024
1 parent a2ed767 commit a041859
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions content/tutorials/how-to-test-contracts/10.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ First, initialize a new Hardhat TypeScript project:
npx hardhat init
```

Select the `Create a TypeScript project` option and install the sample project's dependencies `hardhat` and `@nomicfoundation/hardhat-toolbox`.
Select the `Create a TypeScript project` option and install the sample project's dependencies: `hardhat` and `@nomicfoundation/hardhat-toolbox`.

To install the `hardhat-zksync-node` plugin and additional necessary packages, execute the following command:
To install the `hardhat-zksync-node` plugin, execute the following command:

<span id="install-hh-zksync" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span>

Expand Down Expand Up @@ -152,6 +152,32 @@ import "@matterlabs/hardhat-zksync";
import "@nomicfoundation/hardhat-chai-matchers";
```

With the previous steps completed, your `hardhat.config.ts` file should now be properly configured to include settings for local testing.

<span id="compare-config" data-name="compareToFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts"></span>

```ts [hardhat.config.ts]
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync";
import "@nomicfoundation/hardhat-chai-matchers";

const config: HardhatUserConfig = {
solidity: "0.8.24",
zksolc: {
version: "latest",
},
networks: {
hardhat: {
zksync: true,
},
},
};

export default config;
```

## Smart contract example

To set up the environment for using chai matchers and writing tests, you'll need to create some contracts.
Expand Down Expand Up @@ -195,35 +221,9 @@ contract Greeter {

## Write Test Cases

With the previous steps completed, your `hardhat.config.ts` file should now be properly configured to include settings for local testing.

<span id="compare-config" data-name="compareToFile" data-filepath="tests-output/hardhat-project/hardhat.config.ts"></span>

```ts [hardhat.config.ts]
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync";
import "@nomicfoundation/hardhat-chai-matchers";

const config: HardhatUserConfig = {
solidity: "0.8.24",
zksolc: {
version: "latest",
},
networks: {
hardhat: {
zksync: true,
},
},
};

export default config;
```

Now you can create a test with the `hardhat-chai-matchers` plugin:

Inside the `/test` folder, renamefile named `test.ts`.
Inside the `/test` folder, rename the example test file to `test.ts`.

<span id="rename-test-file" data-name="runCommand" data-command-folder="tests-output/hardhat-project"></span>

Expand Down Expand Up @@ -309,9 +309,11 @@ However, if you prefer to compile manually, simply run the following command `np
The `hardhat-zksync-node` plugin overrides the default behavior of the Hardhat `test` task.
It starts the **ZKsync Era Test Node** before running tests, executes the tests,
and then automatically shuts down the node after the test cases are completed.

Additionally, the plugin generates a log file named `era_test_node.log`,
which indicates the node's activity and transactions made during the tests.
Whenever you re-run the `test` command, the content of `era_test_node.log` is refreshed.

This setup ensures that your tests are executed against a controlled environment,
mimicking the behavior of a live network but in a local sandboxed context.
It's a common practice to ensure that smart contracts behave
Expand Down

0 comments on commit a041859

Please sign in to comment.