-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
bug(forge)!: strip "revert: " from vm.expectRevert reason #10144
base: master
Are you sure you want to change the base?
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.
this lgtm,
pending @grandizzy
Thank you, makes sense. please fix the fmt issue |
@grandizzy done - sry my IDE was not set with |
@Hugoo looks like the newly added |
|
||
// When using vm.expectRevert(abi.encodeWithSignature("Error(string)", "A"));, the expected | ||
// reason starts with "revert: " We strip redundant `revert: ` prefix from the revert reason | ||
let expected = &expected.replace("revert: ", ""); |
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 had to do the check here because I need the decoded "actual" value.
It relies on the &decoder.decode
which has: Note that this is just a best-effort guess, and should not be relied upon for anything other than user output.
I can add a specific check for this 0x08c379a0
: the function selector for Error(string) (i.e., keccak256("Error(string)")[:4] above but i think it adds overload but lmk what you think.
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.
To avoid relying purely on best-effort decoding, good to add a check for the 0x08c379a0
selector (Error(string)), which is the most common revert pattern. This keeps decoding accurate without affecting performance much.
I had a few weird cases, if I log like this: println!("expected decoded: {} - expected reason: {}", expected, &stringify(expected_reason));
println!("actual decoded: {} - actual reason: {}", actual, &stringify(actual_revert.as_slice())); When the revert message is a short string, function testExpectRevertWithEncodedErrorPrefix() public {
Reverter reverter = new Reverter();
vm.expectRevert(abi.encodeWithSignature("Error(string)", "A"));
reverter.revertWithMessage("A");
}
If not, then it is decoded correctly: function testExpectRevertWithEncodedErrorPrefix() public {
Reverter reverter = new Reverter();
vm.expectRevert(abi.encodeWithSignature("Error(string)", "randomString"));
reverter.revertWithMessage("randomString");
}
Try adding this to: function testExpectRevertShortString() public {
Reverter reverter = new Reverter();
vm.expectRevert("A");
reverter.revertWithMessage("A");
} Error:
There might be some contract conflicts and the decoder matchs it when decoding, I'm not sure I didn't have much time to look more into it. |
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.
nice @grandizzy thanks for handling the rest of this PR 🫡
np! yeah, still checking what would be the best way as this will be an breaking change, will update comments when ready |
e419cd0
to
fec971f
Compare
- match on ContractError:Revert - move checks before split first chunk / EvmError
fec971f
to
0729c2a
Compare
I added logic in |
yup nice thanks - yes i think this one is a little bit trickier than it looks like and def has breaking changes so... need to be handled with care 🫡 |
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.
lgtm!
Closes #10040
Solution
Please see the conv. here: #10040 (comment)
There is something to decide about backward compatibility + side effects
PR Checklist