Skip to content

Commit 269d4e9

Browse files
Fix testing for new version of hardhat and viem
1 parent d2dfbc3 commit 269d4e9

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

docs/tutorials/marketpulse/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It provides low-level, efficient blockchain interactions with minimal abstractio
1919

2020
```bash
2121
npm init -y
22-
npm install -D typescript @types/node ts-node
22+
npm install -D typescript @types/node ts-node chai @types/chai
2323
```
2424

2525
1. Install Hardhat and initialize it:

docs/tutorials/marketpulse/test.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
---
22
title: Test the contract
33
dependencies:
4-
viem: 0
4+
viem: 2.41.2
5+
hardhat: 3.0.17
56
---
67

78
With blockchain development, testing is very important because you don't have the luxury to redeploy application updates as it. Hardhat provides you smart contract helpers on `chai` Testing framework to do so.
89

9-
1. Rename the default `./test/Lock.ts` test file to `./test/Marketpulse.ts`:
10+
1. Rename the default `./test/Counter.ts` test file to `./test/Marketpulse.ts`:
1011

1112
```bash
12-
mv ./test/Lock.ts ./test/Marketpulse.ts
13+
mv ./test/Counter.ts ./test/Marketpulse.ts
1314
```
1415

1516
1. Replace the default file with this code:
1617

1718
```TypeScript
18-
import { loadFixture } from "@nomicfoundation/hardhat-toolbox-viem/network-helpers";
1919
import { expect } from "chai";
2020
import hre from "hardhat";
2121
import { ContractFunctionExecutionError, parseEther } from "viem";
22+
import { describe, it } from "node:test";
23+
const { viem, networkHelpers } = await hre.network.connect();
2224

2325
//constants and local variables
2426
const ODD_DECIMALS = 10;
@@ -38,19 +40,17 @@ With blockchain development, testing is very important because you don't have th
3840
// and reset Hardhat Network to that snapshot in every test.
3941
async function deployContractFixture() {
4042
// Contracts are deployed using the first signer/account by default
41-
const [owner, bob] = await hre.viem.getWalletClients();
43+
const [owner, bob] = await viem.getWalletClients();
4244

4345
// Set block base fee to zero because we want exact calculation checks without network fees
44-
await hre.network.provider.send("hardhat_setNextBlockBaseFeePerGas", [
45-
"0x0",
46-
]);
46+
await networkHelpers.setNextBlockBaseFeePerGas("0x0");
4747

48-
const marketpulseContract = await hre.viem.deployContract(
48+
const marketpulseContract = await viem.deployContract(
4949
"Marketpulse",
5050
[]
5151
);
5252

53-
const publicClient = await hre.viem.getPublicClient();
53+
const publicClient = await viem.getPublicClient();
5454

5555
initAliceAmount = await publicClient.getBalance({
5656
address: owner.account.address,
@@ -70,7 +70,7 @@ With blockchain development, testing is very important because you don't have th
7070

7171
describe("init function", function () {
7272
it("should be initialized", async function () {
73-
const { marketpulseContract, owner } = await loadFixture(
73+
const { marketpulseContract, owner } = await networkHelpers.loadFixture(
7474
deployContractFixture
7575
);
7676

@@ -82,7 +82,7 @@ With blockchain development, testing is very important because you don't have th
8282
});
8383

8484
it("should return Pong", async function () {
85-
const { marketpulseContract, publicClient } = await loadFixture(
85+
const { marketpulseContract, publicClient } = await networkHelpers.loadFixture(
8686
deployContractFixture
8787
);
8888

@@ -112,7 +112,7 @@ With blockchain development, testing is very important because you don't have th
112112
owner: alice,
113113
publicClient,
114114
bob,
115-
} = await loadFixture(deployContractFixture);
115+
} = await networkHelpers.loadFixture(deployContractFixture);
116116

117117
expect(await marketpulseContract.read.betKeys.length).to.equal(0);
118118

@@ -160,9 +160,7 @@ With blockchain development, testing is very important because you don't have th
160160
console.log("Lions bet for 2 ethers should return a hash");
161161

162162
// Set block base fee to zero
163-
await hre.network.provider.send("hardhat_setNextBlockBaseFeePerGas", [
164-
"0x0",
165-
]);
163+
await networkHelpers.setNextBlockBaseFeePerGas("0x0");
166164

167165
const betLions2IdHash = await marketpulseContract.write.bet(
168166
["lions", parseEther("2")],

0 commit comments

Comments
 (0)