-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
More versatile expectRevert
#2014
Comments
Can you give a specific example of the scenario? |
Sure, in my case I have a contract that self-calls at some point. I'd like to see that self-call fail. |
I don't understand - you have something like:
|
Sorry I don't think I get your diagram. I have something like
I ended up testing other behaviors around the revert, and you could even say I shouldn't test a nested revert, but it would be nice. |
Yeah that's essentially what I meant - I don't think this is super feasible because of e.g. #864 (which this is sort of a dupe of?) and #432. Both of them are really hard to implement, and likely to break in many situations for very opaque reasons. Imo, since you catch the revert, it should be sufficient to test the state/output in the case it doesn't revert, and test the opposite as well (in the case it does revert) Another thing is that under the hood |
AFAICT my use case does not involve "internal calls" but actual |
Yeah, as mentioned it works in some cases, but I have definitely seen cases where jumps were used, and it's not entirely clear when that happens and the support (bug fixing, answering questions/helping people) would probably be a lot since the error isn't necessarily immediately clear :) |
I don't think a Regardless, the feature I'm talking about here would strictly be about being able to qualify which next CALL to invert. For instance |
I have another use case right now. I'm testing contract I'd like to check that some transaction makes
|
That's true, however the important bit is |
Agreed, managing internal calls seems difficult. Doing something similar to |
A lot has been discussed, and I think:
So going to close this optimistically, but if there's a feature request here we still want to track feel free to create a new issue describing the scope + sample UX |
I'm not sure how this PR is addressed by supporting For instance :
The only potential workaround here is to do The simplest UX I can think of (it doesn't handle all use cases but a lot) is to enrich // expect next call with given calldata input to revert, optionally with reason
vm.expectRevert(bytes|bytes4 input, [reason])
// expect next call to address to revert, optionally with calldata input, optionally with reason
vm.expectRevert(address,[bytes|bytes4 input, [reason]]) This is useful to pseudo-integration tests where you are testing either |
Sorry, saw some discussion above about reverts for internal function calls (which are JUMPs), but I see that's not the idea here
One I had in mind was the import "forge-std/Test.sol";
contract Foo {
function foo() public {
revert("oops");
}
}
contract Bar {
Foo foo;
constructor() {
foo = new Foo();
}
function bar() public {
foo.foo();
}
}
contract MyTest is Test {
// This test passes.
function testCounter() public {
Bar bar = new Bar();
vm.expectRevert(bytes("oops"));
bar.bar();
}
}
I think I'm not following the use case and what you can't do currently. What does the above example—where a call to |
Component
Forge
Describe the feature you would like
It would be useful to have more control over which call
expectRevert
applies to. Sometimes I don't want to expect the next call to revert but one a little later. And it's not that simple to insert myexpectRevert
between the upcoming call and the call I expect to revert.Possible solutions
New cheat code:
vm.wontRevert()
, which tells forge to ignore the next call for the purpose ofexpectRevert
.Enrich
expectRevert
:vm.expectRevert(bytes|bytes4 input, msg)
where you expect a revert on the next call where the first argument matches the calldata, egvm.expectRevert(ERC20.transferFrom.selector,"lowAllowance")
.Additional context
No response
The text was updated successfully, but these errors were encountered: