A fork test is useful when it reproduces a specific execution environment. Forking the latest block and changing balances until a swap passes answers a different question from explaining the original failure.
Foundry's createSelectFork documentation supports selecting a fork by block or transaction context. Use an appropriate pinned state and record the tool version, chain and RPC capabilities needed to reproduce it.
Capture a reproduction bundle
Preserve sender, destination, calldata, native value, relevant block identity and the observed error. Record the intended token amounts and approvals separately from the raw payload so a reviewer can compare the economic request with execution.
If the failure happened inside a particular block, preceding transactions may matter. A state snapshot after the block can already include changes that were absent when the failed transaction ran.
Declare every override
Impersonation, injected balances, altered allowances and time changes can isolate causes, but they also change the scenario. Run the closest reproduction first, then vary one condition at a time and label each modified case.
A balance override that makes execution pass suggests a funding dependency. It does not prove that the actual user had sufficient funds. Likewise, extending time or replacing a signature cannot validate the original quote's expiry conditions.
Inspect effects, not just non-reversion
Check asset movements, recipient, spent amount, residual balances and applicable minimum-output constraints. A transaction can succeed while delivering a result your adapter did not intend.
Keep test keys and local development accounts isolated from production signing. The fork should be an observation and reproduction environment, not a route for accidentally broadcasting diagnostic transactions.
Finally, state the limit of the result: passing at one historical state does not guarantee a later live execution. Market state, contract configuration and time-sensitive authorizations can change after the pinned point.
Sources & verification (1)
Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.
- createSelectFork
Pinning chain state by block or transaction for fork testing
https://getfoundry.sh/reference/cheatcodes/create-select-fork