Lab 1
This commit is contained in:
45
test/Counter.ts
Normal file
45
test/Counter.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user