Initial commit

This commit is contained in:
2026-02-16 23:37:30 +01:00
commit 9ab5e3b873
10 changed files with 3175 additions and 0 deletions

45
test/Counter.ts Normal file
View File

@@ -0,0 +1,45 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { network } from "hardhat";
describe("Counter", async function () {
const { viem } = await network.connect();
const publicClient = await viem.getPublicClient();
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);
});
});