foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(`cheatcodes`): assert execution revert trace of a function call within `try {} catch` context

Open Brivan-26 opened this issue 1 year ago • 1 comments

Component

Forge, Other (please describe)

Describe the feature you would like

With the introduction of try{}catch blocks in Solidity, nested calls that might revert can be handled gracefully to not enforce Transaction revert. It would be better to add an assertion in the tests suite to assert a revert of function call instead of a transaction call

For example: Let's say function x on contract A calls function y on contract B in which it handles the revert of y gracefully using try{}catch. It would be awesome to have an assertion function that asserts the revert of function y during the execution of function x. Obviously, expectRevert can not be used since it expects transaction revert instead of function revert

Additional context

No response

Brivan-26 avatar Aug 26 '24 12:08 Brivan-26

I think this should already be possible by using vm.startStateDiffRecording and vm.stopAndReturnStateDiff by checking that reverted call to the given address is present in the returned array

Though it's not as simple as expectRevert

klkvr avatar Aug 26 '24 17:08 klkvr

@Brivan-26 @zerosnacks @klkvr I think this should be solved by https://github.com/foundry-rs/foundry/issues/5299#issuecomment-1623838745 wdyt?

grandizzy avatar Aug 29 '24 12:08 grandizzy

solved by #5299

jenpaff avatar Sep 24 '24 13:09 jenpaff