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

chore: document best practices for blockchain time management in invariant tests #899

Closed
JacoboLansac opened this issue May 17, 2023 · 3 comments

Comments

@JacoboLansac
Copy link

When doing invariant tests on a staking protocol, it is important to be able to simulate the passing of time. I tried two approaches:

Adding a function to a handler contract that internally uses skip(time). However, the blockchain timestamp was reverted to the original point after executing the function. Time advancement was not preserved outside that function.

In the handler contract, declare a state variable called timestamp and add a modifier to all functions in the handler contract, which would add some time to that variable before using vm.warp(timestamp). This worked.

Is there a better way of doing it?

--- Note ---
This issue was first open in the foundry-rs repo, but it was suggested to bring it up to this other repo. Find the link to the other issue, with the responses:
foundry-rs/forge-std#376

@zerosnacks zerosnacks changed the title Best practices for blockchain time management Invariant tests? chore: document best practices for blockchain time management in invariant tests Sep 16, 2024
@zerosnacks
Copy link
Member

cc @grandizzy possibly already covered but otherwise could be relevant

@grandizzy
Copy link
Collaborator

grandizzy commented Sep 16, 2024

@zerosnacks yeah, that behavior was fixed with foundry-rs/foundry#7819 so no additional time management needed in invariant tests

@zerosnacks
Copy link
Member

Great, marking as resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants