feat: add time advance call to anvil client #2043
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support to call the advance time from anvil. This will be useful in the MCMS fork test use cases where we need to advance the timelock time in order to not wait the elapsed time during fork tests.
AI Summary
This pull request adds support for advancing the EVM time in Anvil via the
evm_increaseTimeRPC method. It introduces a new method in theRPCClientand a corresponding integration test to verify its functionality.EVM time manipulation support:
EVMIncreaseTimeto theRPCClientinrpc.goto send theevm_increaseTimeRPC call, allowing tests to programmatically advance the EVM's internal clock.Testing:
rpc_test.gothat verifies theevm_increaseTimemethod correctly advances the blockchain timestamp when used with Anvil. The test mines a block, advances time, mines another block, and checks the timestamp difference.Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.
Why
The changes introduce a new function for advancing the EVM's time in tests, update the import path for the
math/randpackage tomath/rand/v2, and add a comprehensive test to validate theEVMIncreaseTimefunction's behavior. These changes are aimed at enhancing testing capabilities in blockchain simulations, particularly for scenarios that require time manipulation.What
framework/rpc/rpc.go
math/randupdated tomath/rand/v2. This change modernizes the codebase by adopting the latest version of themath/randpackage, which may include optimizations or new features.EVMIncreaseTimefunction. This function allows advancing the EVM's virtual time by a specified number of seconds, enabling more dynamic and temporal test scenarios.framework/rpc/rpc_test.go
(anvil) evm_increaseTime advances timestampto validate the behavior of the newly introducedEVMIncreaseTimefunction. This test ensures that the blockchain's timestamp advances correctly when the function is invoked, enhancing confidence in time-dependent contract testing.