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

feat: vm.assume support in invariant tests #4190

Closed
mds1 opened this issue Jan 26, 2023 · 3 comments · Fixed by #7309
Closed

feat: vm.assume support in invariant tests #4190

mds1 opened this issue Jan 26, 2023 · 3 comments · Fixed by #7309
Labels
T-feature Type: feature

Comments

@mds1
Copy link
Collaborator

mds1 commented Jan 26, 2023

Component

Forge

Describe the feature you would like

Invariant tests support this cheat, which I believe is because assume was added before invariant tests. There are two ways we should support:

  • vm.assume directly in a function invariant_MyInvariantTest() method. Currently a failed assume here fails the test with [FAIL. Reason: Assertion failed.]. To be fair this usage is a bit limited since you can't make assumptions on fuzzed inputs, but still seems worthwhile to support
  • vm.assume in a handler contract. This lets you reject e.g. owner addresses from a fuzzed owner input. I tried putting a quick test together and it seems these are just ignored since the cheat isn't being called in a test method

Additional context

No response

@PaulRBerg
Copy link
Contributor

For historical context on this issue, see the discussion here:

foundry-rs/book#760 (comment)

@amarcu
Copy link

amarcu commented Apr 4, 2023

What are good ways to work around this issue for now? I'm considering using bound() to filter out addresses like address(0). Would love to be able to use vm.assume() in handler contracts. We're using the fail_on_revert = true flag for invariant tests and it would make everything a lot easier to manage.

@PaulRBerg
Copy link
Contributor

The only workarounds for now are:

  1. Use bound (as you suggested)
  2. Good old if and return statements, e.g.
if (value == address(0) {
    return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants