-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(forge
) expectRevert for cheatcodes
#6833
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this simply moves revert handling above the cheatcode check and thereby makes it possible to use revert handling on cheatcodes?
/// Flag which is being switched once we exit `expectRevert` call | ||
/// Needed to not fail due to `expectRevert` not reverting | ||
pub pending: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand this, but would love to have a bit more context here
if expected_revert.pending { | ||
let expected_revert = self.expected_revert.as_mut().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add some docs here?
@mattsse it seems that failing CI is caused by |
oh and it breaks some external codebases as well for example, snekmate tests are failing right now because of such patterns: vm.expectRevert(bytes("Ownable: caller is not the owner"));
ERC721Extended.set_minter(makeAddr(minter), true);
not sure if this should be merged now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think the fs failures are windows-related, so we'll need a windows box to properly deal with those
I think making expect*
cheatcodes compatible with other cheatcodes is something we probably do want later on, this will break existing codebases as expect*
not interacting with other cheatcodes is sort of an undocumented-but-known foundry quirk. I think we should hold off from merging this now but proposing this as a breaking change later, if we gain something from this
I see, what's the best way to write negative tests for cheatcodes then? initially I've discovered this while writing tests for #6803, so not sure how to proceed with it |
Just noting that I agree with @Evalir that supporting |
yeah, I think we shouldn't merge that, can't imagine usecase when someone would want to use I didn't realize initially that it will be breaking as we've already used Now it seems that some of those tests are incorrect, and imo it makes sense to rewrite them anyway |
Closed in favor of #6841 |
Motivation
Currently
expectRevert
isn't working correctly for reverts coming from cheatcodes invocations and may cause false-positives.For example, such test will pass at the moment:
This is happening because
call_end
hook in Cheatcodes inspector always exists early for calls to cheatcodes address, forwarding reverts from cheatcodes further. Because of that, test is reverting, but not failing because revert is being processed as an expected revert in the nextcall_end
invocation.Solution
pending
flag which is tracking that we've exitedvm.expectRevert
call context, because otherwise we would always expect it to revert which won't happen.