Skip to content

Commit 3d611a5

Browse files
committed
docs: update testing guide with small tweaks
1 parent 6abfedc commit 3d611a5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/src/content/hardhat-runner/docs/guides/test-contracts.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
After [compiling your contracts](./compile-contracts.md), the next step is to write some tests to verify that they work as intended.
44

5-
This guide explains our recommended approach for testing contracts in Hardhat. It relies on [ethers](https://docs.ethers.org/v6/) to connect to [Hardhat Network](/hardhat-network) and on [Hardhat Ignition](/ignition), [Mocha](https://mochajs.org/), and [Chai](https://www.chaijs.com/) for the tests. It also uses our custom [Chai matchers](/hardhat-chai-matchers) and our [Hardhat Network Helpers](/hardhat-network-helpers) to make it easier to write clean test code. These packages are part of the Hardhat Toolbox plugin; if you followed the previous guides, you should already have them installed.
5+
This guide explains our recommended approach for testing contracts in Hardhat. It relies on [ethers](https://docs.ethers.org/v6/) to connect to [Hardhat Network](/hardhat-network), [Hardhat Ignition](/ignition) to deploy the contracts and [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/) for the tests. It also uses our custom [Chai matchers](/hardhat-chai-matchers) and our [Hardhat Network Helpers](/hardhat-network-helpers) to make it easier to write clean test code. These packages are part of the Hardhat Toolbox plugin; if you followed the previous guides, you should already have them installed.
66

77
While this is our recommended test setup, Hardhat is flexible: you can customize the approach or take a completely different path with other tools.
88

@@ -27,11 +27,11 @@ For our first test we’ll deploy the `Lock` contract and assert that the unlock
2727
```tsx
2828
import { expect } from "chai";
2929
import hre from "hardhat";
30-
import { buildModule } from "@nomicfoundation/hardhat-toolbox";
30+
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
3131
import { time } from "@nomicfoundation/hardhat-toolbox/network-helpers";
3232

3333
// We define a module in the test file here, but you can also `import` it.
34-
const LockModule = buildModule("Lock", (m) => {
34+
const LockModule = buildModule("LockModule", (m) => {
3535
const lockedAmount = m.getParameter("lockedAmount");
3636
const unlockTime = m.getParameter("unlockTime");
3737

@@ -44,14 +44,14 @@ const LockModule = buildModule("Lock", (m) => {
4444

4545
describe("Lock", function () {
4646
it("Should set the right unlockTime", async function () {
47-
const lockedAmount = 1_000_000_000;
47+
const lockedAmount = 1_000_000_000n;
4848
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
4949
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
5050

5151
// deploy a lock contract where funds can be withdrawn
5252
// one year in the future
5353
const { lock } = await hre.ignition.deploy(LockModule, {
54-
parameters: { Lock: { lockedAmount, unlockTime } },
54+
parameters: { LockModule: { lockedAmount, unlockTime } },
5555
});
5656

5757
// assert that the value is correct
@@ -71,7 +71,7 @@ const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
7171
const { time } = require("@nomicfoundation/hardhat-toolbox/network-helpers");
7272

7373
// We define a module in the test file here, but you can also `require` it.
74-
const LockModule = buildModule("Lock", (m) => {
74+
const LockModule = buildModule("LockModule", (m) => {
7575
const lockedAmount = m.getParameter("lockedAmount");
7676
const unlockTime = m.getParameter("unlockTime");
7777

@@ -84,14 +84,14 @@ const LockModule = buildModule("Lock", (m) => {
8484

8585
describe("Lock", function () {
8686
it("Should set the right unlockTime", async function () {
87-
const lockedAmount = 1_000_000_000;
87+
const lockedAmount = 1_000_000_000n;
8888
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
8989
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
9090

9191
// deploy a lock contract where funds can be withdrawn
9292
// one year in the future
9393
const { lock } = await hre.ignition.deploy(LockModule, {
94-
parameters: { Lock: { lockedAmount, unlockTime } },
94+
parameters: { LockModule: { lockedAmount, unlockTime } },
9595
});
9696

9797
// assert that the value is correct
@@ -104,7 +104,7 @@ describe("Lock", function () {
104104

105105
::::
106106

107-
First we import the things we are going to use: the [`expect`](https://www.chaijs.com/api/bdd/) function from `chai` to write our assertions, the [Hardhat Runtime Environment](../advanced/hardhat-runtime-environment.md) (`hre`), the [`buildModule`](/ignition/docs/guides/creating-modules) function from Hardhat Ignition to deploy and interact with our contracts, and the [network helpers](/hardhat-network-helpers) to interact with the Hardhat Network. After that we use the `describe` and `it` functions, which are global Mocha functions used to describe and group your tests. (You can read more about Mocha [here](https://mochajs.org/#getting-started).)
107+
First we import the things we are going to use: the [`expect`](https://www.chaijs.com/api/bdd/) function from `chai` to write our assertions, the [Hardhat Runtime Environment](../advanced/hardhat-runtime-environment.md) (`hre`), the [`buildModule`](/ignition/docs/guides/creating-modules) function from Hardhat Ignition to deploy our contracts, and the [network helpers](/hardhat-network-helpers) to interact with the Hardhat Network. After that we use the `describe` and `it` functions, which are global Mocha functions used to describe and group your tests. (You can read more about Mocha [here](https://mochajs.org/#getting-started).)
108108

109109
Before we write our actual test, we define an Ignition module to deploy our contract using the `buildModule` function. For brevity, we define our module in the test file here, but the recommended way to define your Ignition modules is in separate files. You can read more about creating Ignition modules in the [Hardhat Ignition docs](/ignition/docs/guides/creating-modules).
110110

0 commit comments

Comments
 (0)