You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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
The text was updated successfully, but these errors were encountered: