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
I'm trying to write unit tests in Foundry and I've quite enjoyed the ability to mock external calls using function mockCall(address where, uint256 value, bytes calldata data, bytes calldata retdata) external.
However, I can't figure out if there's any way to mock an external call that returns two different results when gets called twice in a function (similar to sideEffect in sinon).
If I use mockCall for calculator.getValue(), it will return the same result for both calls and I'll get 0. Hence, I'd like to be able to mock this call such that it returns different results.
This discussion was converted from issue #6110 on July 04, 2024 13:37.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Component
Forge
Describe the feature you would like
I'm trying to write unit tests in Foundry and I've quite enjoyed the ability to mock external calls using function
mockCall(address where, uint256 value, bytes calldata data, bytes calldata retdata) external
.However, I can't figure out if there's any way to mock an external call that returns two different results when gets called twice in a function (similar to sideEffect in sinon).
Example:
If I use mockCall for
calculator.getValue()
, it will return the same result for both calls and I'll get 0. Hence, I'd like to be able to mock this call such that it returns different results.Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions