Library for testing Solidity custom errors with Truffle/Ganache.

Overview

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",
    ]);
  });
});
You might also like...

Javascript-testing-practical-approach-2021-course-v3 - Javascript Testing, a Practical Approach (v3)

Javascript-testing-practical-approach-2021-course-v3 - Javascript Testing, a Practical Approach (v3)

Javascript Testing, a Practical Approach Description This is the reference repository with all the contents and the examples of the "Javascript Testin

Nov 14, 2022

AREX: It is a “Differential Testing” and “Record and Replay Testing” Tool.

AREX: It is a “Differential Testing” and “Record and Replay Testing” Tool. Test restful API by record, replay and stub request/response. Differential

Nov 1, 2022

This experimental library patches the global custom elements registry to allow re-defining or reload a custom element.

Redefine Custom Elements This experimental library patches the global custom elements registry to allow re-defining a custom element. Based on the spe

Dec 11, 2022

Auto-Fix Hundreds of Grammarly Errors With This Script

Auto-Fix Hundreds of Grammarly Errors With This Script

This script automatically applies your Grammarly suggestions. Use case: Large document with 100+ errors How to use: Go to Grammarly Web app Go to Edit

Jan 3, 2023

Beautiful errors for Remix, both in browser and console

Beautiful errors for Remix, both in browser and console

Rekindled Beautiful errors for Remix, both in browser and console. This project is inspired by php's ignition. I am personally in love with the idea o

Nov 22, 2022

In Your Face shows you Doom 'Ouch Faces' that correlate to the number of errors in your code!

In Your Face shows you Doom 'Ouch Faces' that correlate to the number of errors in your code!

In Your Face Watch how I made this extension on YouTube here In Your Face is a VS Code extension that shows you Doom 'Ouch Faces' that correlate to th

Dec 25, 2022

Handle errors like it's 2022 🔮

Handle errors like it's 2022 🔮 Error handling framework that is minimalist yet featureful. Features Minimalist API Custom error types Wrap any error'

Jan 7, 2023

Notes may contain grammatical errors and some wont make sense and will only make sense to me

Notes may contain grammatical errors and some wont make sense and will only make sense to me

This is my own notes containing all the information and knowledge I've gained during my studying sessions. The notes are all topics that relates to technology such as computers, software or programming.

Dec 15, 2022

Parse Ethers.js errors with ease 💅🏻

ethers-error-parser Parse Ethers.js errors with ease 💅🏻 Highlights Zero dependencies 🧹 Lightweight (637 bytes gzipped) 📦 Simple to use ⚡️ Work in

Dec 28, 2022
Comments
  • Cannot read properties of undefined (reading 'result')

    Cannot read properties of undefined (reading 'result')

    Hi I am trying to use your library hardhat but have an error when trying to expectRevertCustomError. Since the test-helper library is not compatible with ethers.js I have to use truffle/web3. Below is my hardhat config:

    import { HardhatUserConfig } from "hardhat/config";
    import "@nomicfoundation/hardhat-toolbox";
    require("@nomicfoundation/hardhat-chai-matchers");
    import "hardhat-contract-sizer";
    import "@nomiclabs/hardhat-web3";
    require("@nomiclabs/hardhat-truffle5");
    
    const config: HardhatUserConfig = {
      // solidity: "0.8.0",
      solidity: {
        compilers: [
          { version: "0.8.17", settings: {} }
        ],
      },
    };
    
    export default config;
    

    With my current setup I am able to create test cases which follow the truffle pattern with no issues. I then try to unit test custom errors using the similar truffle pattern like below:

    const {
        balance,
        ether,
        expectEvent, 
        expectRevert,
        BN, 
    } = require('@openzeppelin/test-helpers');
    const { expectRevertCustomError } = require("custom-error-test-helper");
    const Marketplace = artifacts.require("Marketplace");
    
    describe("Marketplace contract", function () {
      let marketplace;
      beforeEach(async function () {
          marketplace = await Marketplace.new();
      });
        it("Should validate listed 721 errors", async function () {
            await expectRevertCustomError(Marketplace, marketplace.listNFT(marketplace.address, BigNumber.from("1"), BigNumber.from("1"), BigNumber.from(TOMORROW), BigNumber.from(IN_FIVE_DAYS), 
            { from: TOKEN_OWNER, value: listingFee}), "UnsupportedNftInterface");
        });
       
       /* more test cases*/
    });
    

    Below is the error when this case is rase. Do you know what is causing this and how to fix the error?

     1) Marketplace contract
           Validate Listings
             Should validate listed 721 errors:
         TypeError: Cannot read properties of undefined (reading 'result')
          at expectRevertCustomError (node_modules/custom-error-test-helper/build/index.js:17:88)
          at processTicksAndRejections (node:internal/process/task_queues:95:5)
          at runNextTicks (node:internal/process/task_queues:64:3)
          at listOnTimeout (node:internal/timers:533:9)
          at processTimers (node:internal/timers:507:7)
          at async Context.<anonymous> (test/Marketplace.js:374:9)
    
    opened by advra 3
Owner
null
Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Hajar OUAAROUCH 5 May 24, 2022
Solidity Quickstart is an extensive solidity guide for the solidity newbies out there.

?? Solidity Quickstart Solidity Quickstart is an extensive solidity guide for the solidity newbies out there. ?? How does it work? All the guides rela

Kira 8 Aug 6, 2022
CLI tool to add @ts-expect-errors to typescript type errors

suppress-ts-errors Cli tool to add comments to suppress typescript type errors. Add @ts-expect-error or @ts-ignore comments to all locations where err

ryo 53 Dec 8, 2022
A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Prisma ORM. Deploys to Fly.io

Live Demo · Twitter A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Pris

Remix Stacks 18 Oct 31, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A hardhat solidity template with necessary libraries that support to develop, compile, test, deploy, upgrade, verify solidity smart contract

solidity-hardhat-template A solidity hardhat template with necessary libraries that support to develop, compile, test, deploy, upgrade, verify solidit

ChimGoKien 4 Oct 16, 2022
Kuldeep 2 Jun 21, 2022
Small js library to animate some writing effect through a list of strings. It also supports settings for typo errors, to make it more human likely.

Write and Delete Small js library to animate some writing effect through a list of strings. It also supports settings for typo errors, to make it more

fabs 2 Nov 15, 2022