I am working on adding a feature which allows us to run fork tests on Mainnet state without committing the effects
Foundry (development framework for the EVM) creates a local fork of the EVM state at a given block, allowing users to write tests on that fork as a superuser. This is useful for getting a local copy of arbitrary mainnet/devnet state to test with, especially so for the security community (where a POC for a vulnerability would need to be tested with as the alternative would be executing it on-chain)
You can read more about it here: Fork Testing - Foundry Book
Code: https://github.com/foundry-rs/foundry/blob/d15450758ae3744dc6861956d5ebde554356683a/crates/anvil/src/eth/backend/fork.rs
You might think that this is an unecessary feature as there are sui_devInspectTransactionBlock
and sui_dryRunTransactionBlock
, however these only return transaction effects and do not keep a local copy of the entire blockchain state. What if we want the option of executing some fake transactions now, and waiting a bit for new transactions to run against the state? What if we want to go back in time at a given checkpoint and execute tests from that state? Even if the clock itself can be rewinded (as Sam mentioned), that will only get us so far. It seems to me that we can’t do these things currently with devInspect alone. Additionally, for long sequences of transactions exceeding the PTB limit of 1024, we cannot fit all the transactions into one block
After discussion with members of the Mysten Labs Team and Sam Blackshear I’ve determined the following requirements
Here are the requirements:
- wind and unwind the clock object (provide helper methods to do so easily)
- get local network state from mainnet/devnet at any given checkpoint
- have persistent state changes after individual transactions
- execute transactions from any account
currently, I am looking into how to isolate AuthorityState
after it has caught up to the desired checkpoint. would appreciate any pointers from the mysten team, I will continue to post updates.