Expand description
An example that shows how to implement a Foundry-style Solidity test cheatcode inspector.
The code below mimics relevant parts of the implementation of the transact
and rollFork(uint256 forkId, bytes32 transaction)
cheatcodes.
Both of these cheatcodes initiate transactions from a call step in the cheatcode inspector which is the most advanced cheatcode use-case.
Structsยง
- Backend ๐Backend for cheatcodes. The problematic cheatcodes are only supported in fork mode, so weโll omit the non-fork behavior of the Foundry
Backend
. - Cheatcodes ๐An REVM inspector that intercepts calls to the cheatcode address and executes them with the help of the
DatabaseExt
trait. - Env ๐EVM environment
Traitsยง
- Database
Ext ๐Used in Foundry to provide extended functionality to cheatcodes. The methods are called from theCheatcodes
inspector.
Functionsยง
- commit_
transaction ๐Executes a transaction and runs the inspector using theBackend
as the state. Mimicscommit_transaction
https://github.com/foundry-rs/foundry/blob/25cc1ac68b5f6977f23d713c01ec455ad7f03d21/crates/evm/core/src/backend/mod.rs#L1931 - main ๐
- update_
state ๐Mimics https://github.com/foundry-rs/foundry/blob/25cc1ac68b5f6977f23d713c01ec455ad7f03d21/crates/evm/core/src/backend/mod.rs#L1968 Omits persistent accounts (accounts that should be kept persistent when switching forks) for simplicity.