custom-error-test-helper

1.0.6 • Public • Published

Custom Error Test Helper

Library for testing Solidity custom errors with Truffle/Ganache.

Installation

npm install --save-dev custom-error-test-helper

Usage

Import custom-error-test-helper in your test files to access the assertion.

const { expectRevertCustomError } = require("custom-error-test-helper");

const MyContract = artifacts.require("MyContract");

contract("MyContract", function (accounts) {
  beforeEach(async function () {
    this.contract = await MyContract.new();
  });

  it("reverts with an error with no parameters", async function () {
    // error SomeError0();
    await expectRevertCustomError(MyContract, this.contract.someFunction0(), "SomeError0");
  });

  it("reverts with an error with parameters", async function () {
    // error SomeError1(uint256 one, address vb);
    await expectRevertCustomError(MyContract, this.contract.someFunction1(), "SomeError1", [
      1,
      "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
    ]);
  });
});

Package Sidebar

Install

npm i custom-error-test-helper

Weekly Downloads

66

Version

1.0.6

License

MIT

Unpacked Size

12.8 kB

Total Files

6

Last publish

Collaborators

  • tomi_ohl