|
| 1 | +# `mock_call_when` |
| 2 | + |
| 3 | +Cheatcodes mocking contract entry point calls: |
| 4 | + |
| 5 | +## `MockCallData` |
| 6 | + |
| 7 | +```rust |
| 8 | +pub enum MockCallData { |
| 9 | + Any, |
| 10 | + Values: Span<felt252>, |
| 11 | +} |
| 12 | +``` |
| 13 | + |
| 14 | +`MockCallData` is an enum used to specify for which call data the contract entry point will be mocked. |
| 15 | +- `Any` mock the contract entry point for any call data. |
| 16 | +- `Values` mock the contract entry point only for this call data. |
| 17 | + |
| 18 | +## `mock_call_when` |
| 19 | +> `fn mock_call_when<T, impl TSerde: serde::Serde<T>, impl TDestruct: Destruct<T>>( |
| 20 | +> contract_address: ContractAddress, function_selector: felt252, call_data: MockCallData, ret_data: T, n_times: u32 |
| 21 | +> )` |
| 22 | +
|
| 23 | +Mocks contract call to a `function_selector` of a contract at the given address, with the given call data, for `n_times` first calls that are made |
| 24 | +to the contract. |
| 25 | +A call to function `function_selector` will return data provided in `ret_data` argument. |
| 26 | +An address with no contract can be mocked as well. |
| 27 | +An entrypoint that is not present on the deployed contract is also possible to mock. |
| 28 | +Note that the function is not meant for mocking internal calls - it works only for contract entry points. |
| 29 | + |
| 30 | +## `start_mock_call_when` |
| 31 | +> `fn start_mock_call<T, impl TSerde: serde::Serde<T>, impl TDestruct: Destruct<T>>( |
| 32 | +> contract_address: ContractAddress, function_selector: felt252, call_data: MockCallData, ret_data: T |
| 33 | +> )` |
| 34 | +
|
| 35 | +Mocks contract call to a `function_selector` of a contract at the given address, with the given call data, indefinitely. |
| 36 | +See `mock_call_when` for comprehensive definition of how it can be used. |
| 37 | + |
| 38 | + |
| 39 | +### `stop_mock_call_when` |
| 40 | + |
| 41 | +> `fn stop_mock_call_when(contract_address: ContractAddress, function_selector: felt252, call_data: MockCallData)` |
| 42 | +
|
| 43 | +Cancels the `mock_call_when` / `start_mock_call_when` for the function `function_selector` of a contract at the given addressn with the given call data |
0 commit comments