0.0.8 • Published 11 months ago

@ensdomains/hardhat-chai-matchers-viem v0.0.8

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

hardhat-chai-matchers-viem

This plugin is based on the existing @nomicfoundation/hardhat-chai-matchers. If you are using ethers, you should use that instead.

Installation

bun add @ensdomains/hardhat-chai-matchers-viem

In your hardhat config:

import("@ensdomains/hardhat-chai-matchers-viem");

Getting started

Deploy contracts with deployContract and pass them into expect to use matchers from this plugin:

import { expect } from "chai";
import hre from "hardhat";

it("works", async () => {
  const example = await hre.viem.deployContract("ExampleContract", []);
  await expect(example)
    .write("revertWithSomeCustomError")
    .toBeRevertedWithCustomError("SomeCustomError");
});

To speed up tests, you should use hardhat fixtures:

import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import hre from "hardhat";

async function deployExample() {
  const example = await hre.viem.deployContract("ExampleContract", []);
  return example;
}

it("works", async () => {
  const example = await loadFixture(deployExample);
  await expect(example)
    .write("revertWithSomeCustomError")
    .toBeRevertedWithCustomError("SomeCustomError");
});

Available matchers

  • expect(contract).read(...)
  • expect(contract).write(...)
  • expect(contract).transaction(...)
  • .toBeReverted()
  • .toBeRevertedWithCustomError(...)
    • .withArgs(...)
  • .toBeRevertedWithoutReason()
  • .toBeRevertedWithPanic(...)
  • .toBeRevertedWithString(...)
  • .toEmitEvent(...)
    • .withArgs(...)
  • .toEmitEventFrom(...)
    • .withArgs(...)
0.0.8

11 months ago

0.0.7

12 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago