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 the
Cheatcodes
inspector.
Functionsยง
- commit_
transaction ๐ - Executes a transaction and runs the inspector using the
Backend
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.