-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(cheatcodes
): add vm.expectMockCall
to enforce that a mocked function is called with certain arguments
#5480
Comments
You might be interested in |
adding a mock+expect combination in forge-std makes sense to me |
Thanks, that makes sense to me too. I won't make any changes to the std lib right now, but I'm working on some code-gen stuff that might be useful for others once it is done to assist with mocking. |
Also FYI - my codegen work will allow mocking of internal functions without needing to move the the REVM as mentioned in this PR - #432 . Like I say, I'll definitely share my work on that in the coming weeks/months 👍 |
@brockelmore Perhaps we should transfer this to Forge Std as well? Or maybe just close it and open up a new issue? Wdyt? |
Per #3782, I'm going to move this back to the foundry repo I'm also not too clear on the exact proposal here, I'd be curious to see sample code of that the cheat/UX would look like |
cheatcodes
): add vm.expectMockCall
to enforce that a mocked function is called with certain arguments
@JasoonS please reopen this if still needed and provide a sample code of that the cheat/UX would look like as mentioned in above comment. thank you! |
It would be nice to have this: vm.expectAndMockCall(
inboxes_[0],
abi.encodeWithSelector(
MockERC20Inbox.sendContractTransaction.selector,
100_001,
1_000_000,
_appChainGateway,
0,
abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
),
abi.encode(uint256(11))
); instead of this: vm.expectCall(
inboxes_[0],
abi.encodeWithSelector(
MockERC20Inbox.sendContractTransaction.selector,
100_000,
1_000_000,
_appChainGateway,
0,
abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
)
);
vm.mockCall(
inboxes_[0],
abi.encodeWithSelector(
MockERC20Inbox.sendContractTransaction.selector,
100_001,
1_000_000,
_appChainGateway,
0,
abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
),
abi.encode(uint256(11))
); Sure, we could make a helper function: function _expectAndMockCall(address callee, bytes memory data, bytes memory returnData) internal {
vm.expectCall(callee, data);
vm.mockCall(callee, data, returnData);
} but |
Component
Forge
Describe the feature you would like
Currently tests don't break if a mocked function is called with different arguments to what was expected.
Currently for example:
With the above code it will return 6 if the function is called with an argument of 5 or anything else, additionally it won't fail if it isn't called with 5 (which is something you sometimes want to check.
I propose adding a function called something like
mockCallStrict
to the cheats so that tests can be more strict about this.Additional context
This is a feature of Smock: https://smock.readthedocs.io/en/latest/fakes.html#asserting-call-arguments
The text was updated successfully, but these errors were encountered: