@ensdomains/hardhat-chai-matchers-viem
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

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(...)

Readme

Keywords

none

Package Sidebar

Install

npm i @ensdomains/hardhat-chai-matchers-viem

Weekly Downloads

102

Version

0.0.6

License

none

Unpacked Size

158 kB

Total Files

124

Last publish

Collaborators

  • davidchu
  • taytems
  • makoto_inoue
  • decanus
  • nickjohnson
  • jefflau
  • mdt.
  • leeondamiky