import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { network } from "hardhat"; const { viem } = await network.connect(); const publicClient = await viem.getPublicClient(); describe("Counter", async function () { it("The value should match the sum of the increments", async function () { const counter = await viem.deployContract("Counter"); await counter.write.inc(); // run a series of increments // 3+...+10 = 52 for (let i = 3n; i <= 10n; i++) { await counter.write.incBy([i]); } // read the value const value = await counter.read.x(); assert.equal(value, 1n + 52n); }); it("Demo reading from a public client with Viem", async function () { const counter = await viem.deployContract("Counter"); await counter.write.inc(); await counter.write.inc(); await counter.write.inc(); // read the value const value = await publicClient.readContract({ address: counter.address, abi: counter.abi, functionName: "x", }); assert.equal(value, 3n); }); });