# Enabling foundry-esque Fork Tests on Sui

**URL:** <https://forums.sui.io/t/enabling-foundry-esque-fork-tests-on-sui/44946>\
**Category:** General\
**Tags:** sui, feature, sui-foundation\
**Created:** [August 16, 2023, 2:19am UTC](https://forums.sui.io/t/enabling-foundry-esque-fork-tests-on-sui/44946 "2023-08-16T02:19:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daweth](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/daweth/32/30498_2.png) [@daweth](https://forums.sui.io/u/daweth)\
**Post date:** [August 16, 2023, 2:19am UTC](https://forums.sui.io/t/enabling-foundry-esque-fork-tests-on-sui/44946/1 "2023-08-16T02:19:00Z")

</div>

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](https://book.getfoundry.sh/forge/fork-testing)  
Code: [https://github.com/foundry-rs/foundry/blob/d15450758ae3744dc6861956d5ebde554356683a/crates/anvil/src/eth/backend/fork.rs](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.

---

<div class="post-metadata">

**Author:** ![daweth](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/daweth/32/30498_2.png) [@daweth](https://forums.sui.io/u/daweth)\
**Post date:** [August 18, 2023, 6:07pm UTC](https://forums.sui.io/t/enabling-foundry-esque-fork-tests-on-sui/44946/2 "2023-08-18T18:07:58Z")

</div>

Currently:

[Create a local Sui network | Sui Docs](https://docs.sui.io/build/sui-local-network) is the base of what I will build from  
(sui-test-validator crate)

I am trying to figure out how to sync the state up to a certain checkpoint on mainnet. I will try to create the `local-cluster` with the state sync of a full node running on mainnet. Stopping it will be a challenge as I don’t know how yet to specify a state sync to a certain checkpoint only. Since the canonical full node should not be participating in consensus as it doesn’t have voting capability, I think this is theoretically possible. We only care about the transaction data.

Configuring the node seems difficult (NodeConfig)  
I’m also not sure if creating a node from scratch is the best option (all we need is the Arc of the handle)

Some Important Files:

**sui-test-validator/src/main.rs**  
is a script that starts a `LocalCluster`, a Faucet (rich account), and an (optional) indexer.

**sui-cluster-test/src/cluster.rs**  
LocalNewCluster - can pass in a config file  
if we pass in the fullnode config for a devnet/mainnet instance into this cluster - what happens?

- Has the `test_cluster` field, which no other “cluster” has

RemoteRunningCluster - a handle to an existing (remote) cluster

**sui-core/src/checkpoints/checkpoint\_executor/mod.rs**

**test-cluster/src/lib.rs**

---

<div class="post-metadata">

**Author:** ![23f61237d045016cbfd4](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/23f61237d045016cbfd4/32/31710_2.png) [@23f61237d045016cbfd4](https://forums.sui.io/u/23f61237d045016cbfd4)\
**Post date:** [May 20, 2026, 2:27am UTC](https://forums.sui.io/t/enabling-foundry-esque-fork-tests-on-sui/44946/3 "2026-05-20T02:27:34Z")

</div>

For your information, there is a sui-replay feature, with their CLI, to replay a transaction at specified checkpoint state, precisely…
