-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mock_call
with dynamic return data
#2861
Comments
Can i take this one up? Would love to work on it |
Hi, here is a proposal for mock callback interface: trait MockCallback<T, R> {
fn execute(ref self: T, input: Span<felt252>) -> R;
} What do you think about adding also |
@ptisserand this is nice but I wonder if we shouldn't reduce the scope of this issue and simply extend fn mock_call( contract_address: ContractAddress, function_selector: felt252, calldata: Span<felt252>, ret_data: T, n_times: u32) This should cover most user cases and be more in-line with other cheatcodes (also much easier to implement). |
@cptartur what do you think to use My idea is when calldata is Or we can have a more explicit enum like: enum MockCallData {
Any,
Value: Span<felt252>,
} |
Here is a test example with #[test]
fn mock_call_simple() {
let calldata = array![420];
let contract = declare("MockChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@calldata).unwrap();
let dispatcher = IMockCheckerDispatcher { contract_address };
let specific_mock_ret_data = 421;
let default_mock_ret_data = 404;
let expected_calldata = MockCallData::Values([].span());
start_mock_call(contract_address, selector!("get_thing"), expected_calldata, specific_mock_ret_data);
start_mock_call(contract_address, selector!("get_thing"), MockCallData::Any, default_mock_ret_data);
let thing = dispatcher.get_thing();
assert(thing == specific_mock_ret_data, 'Incorrect thing');
stop_mock_call(contract_address, selector!("get_thing"), expected_calldata);
let thing = dispatcher.get_thing();
assert(thing == default_mock_ret_data, 'Incorrect thing');
stop_mock_call(contract_address, selector!("get_thing"), MockCallData::Any);
let thing = dispatcher.get_thing();
assert(thing == 420, 'Incorrect thing');
} |
Which component is your feature related to?
Forge
Feature Request
mock_call
cheatcode accepts staticret_data
. It could be useful if it was possible to define a function in in that can receive the calldata and dynamically return different ret_data.The text was updated successfully, but these errors were encountered: