I am writing invariant tests using a handler contract in foundry. However, for some reason, the handler contract is not fuzzing (I know because when I run forge test --mt assertSomething It doesn't show amount of runs / depth / anything fuzz related).

contract Invariant is StdInvariant, Test {

    Handler handler;

    //additional logic ...

    function setUp() public {
        handler = new Handler(pool);

        //additional logic ...

        bytes4[] memory _selectors = new bytes4[](4);
        _selectors[0] = handler.deposit.selector;
        _selectors[1] = handler.swap.selector;

        targetSelector(FuzzSelector({ addr: address(handler), selectors: _selectors}));

    function assertSomething() {
    //logic ...

Functions in handler contract:

    function deposit(uint256 approvedAndDepositedToken, uint256 approvedAndDepositedWeth) public {
        //logic ...

    function swap(uint256 swapAmt) public {
    //logic ...

Why are the functions in my handler contract not fuzzing (maybe not even running at all)?

This is my output: output

  • Add arguments to you test function, those arguments will be used for fuzzing. Jan 26 at 5:02

1 Answer 1


I figured it out. The problem was the array length I specified was too large (4). The space of the array I specified is not the amount that I actually used.

Foundry probably checks if any selector of the selectors array is empty / not used.

I had to change the code from:

bytes4[] memory selectors = new bytes4[](4);


bytes4[] memory selectors = new bytes4[](2);

Because I only had 2 functions to fuzz call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.