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
DatabaseExttrait. - Env ๐
- EVM environment
Traitsยง
- Database
Ext ๐ - Used in Foundry to provide extended functionality to cheatcodes.
The methods are called from the
Cheatcodesinspector.
Functionsยง
- commit_
transaction ๐ - Executes a transaction and runs the inspector using the
Backendas the state. Mimicscommit_transactionhttps://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.