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

Best practices for blockchain time management Invariant tests? #899

Open
JacoboLansac opened this issue May 17, 2023 · 0 comments
Open

Best practices for blockchain time management Invariant tests? #899

JacoboLansac opened this issue May 17, 2023 · 0 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

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

No branches or pull requests

1 participant