/quabi

Solidity library to query contract ABI in Foundry tests and scripts

Primary LanguageSolidityGNU Affero General Public License v3.0AGPL-3.0

Quabi

A Solidity library for querying contract ABI data using Foundry's ffi cheatcode in Forge Tests and Scripts.

Roadmap

  • Function selectors
  • Functions selectors that have a specific modifier
  • Errors
  • Events
  • State Variables
  • Others?

Getting Started

Install in your forge project

forge install https://github.com/Oighty/quabi

Import Quabi and use it in your tests

import {Quabi} from "lib/quabi/src/Quabi.sol";
...
contract MyTest is Test {
   
  ContractToTest internal testme;
  ...
  
  bytes4[] memory selectors = Quabi.getFunctions(type(ContractToTest).name);
  bytes4[] memory authSelectors = Quabi.getFunctionsWithModifier(type(ContractToTest).name, "requiresAuth");
  
  ...
  
}

Run your test file with the --ffi flag

forge test --ffi --match-contract MyTest

Acknowledgement

This project was conceived while developing some testing utilities for OlympusDAO.

The project is inspired by Surl and leveraged some of their ideas on preparing shell commands within Solidity.