pub trait MockHandler<T: Config> {
// Provided methods
fn mock_call(
&self,
_callee: H160,
_call_data: &[u8],
_value_transferred: U256,
) -> Option<ExecReturnValue> { ... }
fn mock_caller(&self, _frames_len: usize) -> Option<OriginFor<T>> { ... }
fn mock_origin(&self) -> Option<&Origin<T>> { ... }
fn mock_delegated_caller(
&self,
_dest: H160,
_input_data: &[u8],
) -> Option<DelegateInfo<T>> { ... }
fn mocked_code(&self, _address: H160) -> Option<&[u8]> { ... }
}Expand description
A trait that provides hooks for mocking EVM contract calls and callers. This is useful for testing and simulating contract interactions within foundry forge tests.
Provided Methods§
Sourcefn mock_call(
&self,
_callee: H160,
_call_data: &[u8],
_value_transferred: U256,
) -> Option<ExecReturnValue>
fn mock_call( &self, _callee: H160, _call_data: &[u8], _value_transferred: U256, ) -> Option<ExecReturnValue>
Mock an EVM contract call.
Returns Some(ExecReturnValue) if the call is mocked, otherwise None.
Sourcefn mock_caller(&self, _frames_len: usize) -> Option<OriginFor<T>>
fn mock_caller(&self, _frames_len: usize) -> Option<OriginFor<T>>
Mock the caller of a contract.
§Parameters
_frames_len: The current number of frames on the call stack.
Returns Some(OriginFor<T>) if the caller is mocked, otherwise None.
Sourcefn mock_origin(&self) -> Option<&Origin<T>>
fn mock_origin(&self) -> Option<&Origin<T>>
Mock the origin of a contract.
Returns Some(&Origin<T>) if the caller is mocked, otherwise None.
Sourcefn mock_delegated_caller(
&self,
_dest: H160,
_input_data: &[u8],
) -> Option<DelegateInfo<T>>
fn mock_delegated_caller( &self, _dest: H160, _input_data: &[u8], ) -> Option<DelegateInfo<T>>
Mock a delegated caller for a contract call.
Returns Some(DelegateInfo<T>) if the delegated caller is mocked, otherwise None.
Sourcefn mocked_code(&self, _address: H160) -> Option<&[u8]>
fn mocked_code(&self, _address: H160) -> Option<&[u8]>
Returns dummy code for mocked addresses.
This method serves two purposes:
- Indicates whether an address has mocked calls (Some = mocked, None = not mocked)
- Provides the dummy bytecode for
EXTCODESIZEandEXTCODEHASHopcodes
§Returns
Some(bytecode)containing dummy bytecode if the address has mocked callsNoneif the address is not mocked