Contract safety · Invariant testing

Invariant test generator

Generate Foundry, Echidna or Medusa invariant tests and handlers from a contract ABI.

Runs in your browser

Contract ABI

The generator reads the ABI's function list and scaffolds one handler per state-changing function.

Options

Used for the test contract's name and the commented-out import.

Which runner the generated suite targets.

The JSON array from your build artifact's abi field.

No test suite yet

Paste an ABI and the generated invariants, handlers and view helpers appear here, ready to copy into your test folder.

Framework notes

These follow the framework you picked above.

Best for: Developers already using Foundry ecosystem

Properties: Use invariant_ prefix functions

Run: forge test --match-contract InvariantTest

About this tool

Invariant testing, also called stateful fuzzing, calls a contract's functions in random order and checks properties that must always hold, such as total supply equalling the sum of balances. Paste a contract ABI and this generator scaffolds a Foundry, Echidna or Medusa suite with a handler for every state-changing function and helpers for view functions. You then write the invariants your contract needs.

Common questions

What is the difference between a fuzz test and an invariant test in Foundry?

A fuzz test calls one function with random inputs. An invariant test runs random sequences of calls across many functions, usually through handlers, and checks your invariant_ functions after each call.

Does it write the invariants for me?

It writes the structure: the target setup, the handlers and example invariants to replace. Only you know which properties your contract must keep, so treat the output as a starting point and fill in the real checks.