-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(forge): native support for simulating the passage of time when running invariants #4994
Comments
I would also like something like this, but I would add that I think it makes sense to move forward blocks by some amount as well (e.g. perhaps by allowing the user to set the average frequency a new block is expected, to allow for variations across chains). |
I like the idea here. I'd suggest also adding a Like @simplyoptimistic I think we should couple this with block number increases to keep those in sync to make sure things are realistic and minimize footguns. Partly related to #749 (comment) where we discuss the idea of codegen'ing handler contracts that have properties like this defined |
hey guys, |
@viraj124 not sure about any ETA but in the meantime you can look at how we tackled this issue in our project sablier-labs/v2-core: |
Thanks a lot @PaulRBerg this looks a elegant workaround was working on enabling something like this |
Component
Forge
Describe the feature you would like
Because most smart contract systems expect time to pass, it is a common need to simulate the passage of time (with
vm.warp
) when running invariant test campaigns with Foundry.But this is difficult to do today because state is not preserved during invariants runs. Just look at Maple Finance's solution - they have to apply the
useCurrentTimestamp
modifier to all invariant tests, as well as all functions in the handler contracts.Now, regardless of the state-preserving limitation and if and when it will be lifted, I posit that it would be helpful to offer native support for time warps in invariants.
Here's what I have in mind :
Nevermind the names - we can think about what would fit best later. What matters is the idea - to introduce two new config options which would be used for bounding a time jump that gets applied after every invariant test run, i.e. have Foundry do something like this:
This way, an invariant test campaign would more accurately simulate the real world, where time passes between function calls.
Additional context
Related discussions:
The text was updated successfully, but these errors were encountered: