Skip to main content

Crate example_cheatcode_inspector

Crate example_cheatcode_inspector 

Source
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.

Re-exportsยง

pub(crate) use account::JournaledAccount; ๐Ÿ”’
pub(crate) use AccountInfoLoad; ๐Ÿ”’
pub(crate) use JournalLoadError; ๐Ÿ”’
pub(crate) use result::InvalidTransaction; ๐Ÿ”’
pub(crate) use BlockEnv; ๐Ÿ”’
pub(crate) use Cfg; ๐Ÿ”’
pub(crate) use CfgEnv; ๐Ÿ”’
pub(crate) use ContextTr; ๐Ÿ”’
pub(crate) use Evm; ๐Ÿ”’
pub(crate) use LocalContext; ๐Ÿ”’
pub(crate) use TxEnv; ๐Ÿ”’
pub(crate) use AccountLoad; ๐Ÿ”’
pub(crate) use JournalCheckpoint; ๐Ÿ”’
pub(crate) use TransferError; ๐Ÿ”’
pub(crate) use result::EVMError; ๐Ÿ”’
pub(crate) use Block; ๐Ÿ”’
pub(crate) use JournalTr; ๐Ÿ”’
pub(crate) use Transaction; ๐Ÿ”’
pub(crate) use database::InMemoryDB; ๐Ÿ”’
pub(crate) use instructions::EthInstructions; ๐Ÿ”’
pub(crate) use EthPrecompiles; ๐Ÿ”’
pub(crate) use inspectors::TracerEip3155; ๐Ÿ”’
pub(crate) use JournalExt; ๐Ÿ”’
pub(crate) use interpreter::EthInterpreter; ๐Ÿ”’
pub(crate) use CallInputs; ๐Ÿ”’
pub(crate) use CallOutcome; ๐Ÿ”’
pub(crate) use SStoreResult; ๐Ÿ”’
pub(crate) use SelfDestructResult; ๐Ÿ”’
pub(crate) use StateLoad; ๐Ÿ”’
pub(crate) use hardfork::SpecId; ๐Ÿ”’
pub(crate) use Address; ๐Ÿ”’
pub(crate) use AddressMap; ๐Ÿ”’
pub(crate) use AddressSet; ๐Ÿ”’
pub(crate) use HashSet; ๐Ÿ”’
pub(crate) use Log; ๐Ÿ”’
pub(crate) use StorageKey; ๐Ÿ”’
pub(crate) use StorageValue; ๐Ÿ”’
pub(crate) use B256; ๐Ÿ”’
pub(crate) use U256; ๐Ÿ”’
pub(crate) use Account; ๐Ÿ”’
pub(crate) use Bytecode; ๐Ÿ”’
pub(crate) use EvmState; ๐Ÿ”’
pub(crate) use Context; ๐Ÿ”’
pub(crate) use Database; ๐Ÿ”’
pub(crate) use DatabaseCommit; ๐Ÿ”’
pub(crate) use InspectEvm; ๐Ÿ”’
pub(crate) use Inspector; ๐Ÿ”’
pub(crate) use Journal; ๐Ÿ”’
pub(crate) use JournalEntry; ๐Ÿ”’
pub(crate) use convert::Infallible; ๐Ÿ”’
pub(crate) use fmt::Debug; ๐Ÿ”’
pub(crate) use fmt::Debug; ๐Ÿ”’

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ยง

DatabaseExt ๐Ÿ”’
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. Mimics commit_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.