You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function mockCalls(addresswhere, bytescalldatadata, bytes[] calldataretdata) external;
function mockCalls(
addresswhere,
uint256value,
bytescalldatadata,
bytes[] calldataretdata
) external;
Notice the bytes[] for the retdata. The idea is to mock the same call with different return values each time.
Additional context
Motivation
Today, we can mock the return value of a function call by using mockCall. Sometimes, it is useful to mock the same call twice with different return values.
In inspector.rs in the call function, use the MockCallReturnData vector as a stack, removing the first item each time the inspector is triggered
Add the mockCalls cheatcodes, including a mock_calls function that takes rdata: Vec<Vec<u8>> as argument and maps it to a MockCallReturnData vector
Open Qs
What should happen if we mock 2 calls but invoke the function 3 times? Should the last retdata stay for the rest of the transaction (i.e. the stack not be emptied, but kept at size 1)? This would preserve existing behavior of mockCall
The Solidity API in the example I provided above with a dynamic array feels a bit clunky. Does anyone have an idea for a better API?
Notes
I did not try to implement this yet. This is just from looking at the code. First I'd like to know if this is something you'd accept a PR for. I will of course take it on myself. If this feature is desired, we can better define the API and the implementation.
Thank you 🙂
The text was updated successfully, but these errors were encountered:
@Tudmotu thank you for the report! this improvement is not on our roadmap for 1.0 but we would be happy to review and accept PR for (and include it). thank you!
@grandizzy I could take a stab at it though I'm not sure if the proposed design is still relevant since I proposed this a while ago. I will take a look.
Component
Forge
Describe the feature you would like
Notice the
bytes[]
for theretdata
. The idea is to mock the same call with different return values each time.Additional context
Motivation
Today, we can mock the return value of a function call by using
mockCall
. Sometimes, it is useful to mock the same call twice with different return values.Consider the following function:
Both invocations of
token.balanceOf()
have the same calldata. This means we cannot use two differentmockCall
to test this behavior.With
mockCalls
we would test it like so:Suggested implementation
mock_calls
field inCheatcodes
to:mock_call
inmock.rs
tovec![]
the return data:inspector.rs
in thecall
function, use theMockCallReturnData
vector as a stack, removing the first item each time the inspector is triggeredmockCalls
cheatcodes, including amock_calls
function that takesrdata: Vec<Vec<u8>>
as argument and maps it to aMockCallReturnData
vectorOpen Qs
retdata
stay for the rest of the transaction (i.e. the stack not be emptied, but kept at size 1)? This would preserve existing behavior ofmockCall
Notes
I did not try to implement this yet. This is just from looking at the code. First I'd like to know if this is something you'd accept a PR for. I will of course take it on myself. If this feature is desired, we can better define the API and the implementation.
Thank you 🙂
The text was updated successfully, but these errors were encountered: