-
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
Add vm.expectRevert
overloads that take an address arg, to distinguish between error selectors that are identical but in different contracts.
#5299
Comments
If no one is working on this I'd like to 😄 |
We currently have these 3 cheats: // Expects an error on next call
function expectRevert(bytes calldata revertData) external;
function expectRevert(bytes4 revertData) external;
function expectRevert() external; Similar to the // Expects an error on next call
function expectRevert(bytes calldata revertData) external;
function expectRevert(bytes4 revertData) external;
function expectRevert() external;
// Expects an error on next call from the given address. If the revert data matches but the
// address that originated the revert does not, that is considered a failure.
function expectRevert(bytes calldata revertData, address reverter) external;
function expectRevert(bytes4 revertData, address reverter) external;
function expectRevert(address reverter) external; One consideration when implementing is how to handling bubbling up of reverts. Say we're expecting address A to revert with
@Evalir @xeno097 do you agree with that behavior? I'm not sure how feasible that third bullet is though. So it might be better to just consider all 3 of those bullets a success, i.e. we're expecting that A throws that error anywhere in the call stack, and does not have to be the originator |
Yep, I agree. I'll see how feasible it is to achieve the third bullet point and if not, then I'll stick to plan A. |
sorry what is "plan A", is that referring to the below plan?
|
Yep sorry for not being clear 😅 |
Implemented in #8770 |
Component
Forge
Describe the feature you would like
As described in this issue in the foundry book:
If you have two contracts with identical custom errors:
then:
A.NotValid.selector == B.NotValid.selector
.If you have a test that checks for a revert from
A.NotValid.selector
and the error is thrown byB
in the test, the test will still pass as the error selector comparisons will pass.By including the address of the contract in
expectRevert
, you can specify with greater granularity which error you wish to test for.As it stands, it is not practical to refactor common errors into a shared interface as there is no way of checking the source of a revert.
Additional context
No response
The text was updated successfully, but these errors were encountered: