Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: expectNoCall #159

Closed
ashhanai opened this issue Aug 25, 2022 · 1 comment
Closed

Feature request: expectNoCall #159

ashhanai opened this issue Aug 25, 2022 · 1 comment

Comments

@ashhanai
Copy link
Contributor

Image setup, where I have an external contract and I want to test, that it's called when a condition is met.

contract Foo {
    Set set;

    function foo(uint256 x) external {
        if (x < 100) {
            set.remove(x);
        }
    }
}

Currently I can easily test the first condition, where x < 100:

function test_removeFromSet_whenLessThen100() external {
    uint256 x = 80;

    vm.expectCall(
        address(set),
        abi.encodeWithSignature("remove(uint256)", x);
    );
    foo(x);
}

But if I want to test the second condition, I have no easy way how to do that:

function test_notRemoveFromSet_whenMoreOrEqThen100() external {
    uint256 x = 110;

    vm.?????;
    foo(x);
}

One workaround is to instantiate the actual Set contract and check for storage changes, but I would rather mock everything in my unit tests.
I would like to propose new assertion cheatcode expectNoCall as a counter party to an exiting one, but this would fail if a call occurs.
New possible test would look like this:

function test_notRemoveFromSet_whenMoreOrEqThen100() external {
    uint256 x = 110;

    vm.expectNoCall(
        address(set),
        abi.encodeWithSignature("remove(uint256)", x);
    );
    foo(x);
}

Optionally it's possible to propose expectNoRevert, expectNoEmit to have consistency around assertion cheatcodes, but I don't think it's necessary at the moment.

@mds1
Copy link
Collaborator

mds1 commented Aug 25, 2022

Closing this as a duplicate of foundry-rs/foundry#509, but feel free to reopen if I misunderstood

@mds1 mds1 closed this as completed Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants