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.

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.