-
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
Cheatcode expectRevert
doesn't catch error messages from libraries
#4405
Comments
As a workaround, you can define a wrapper for your pure function and call it using contract Tests {
function testThing() public {
vm.expectRevert("...");
this.wrapPure();
}
function wrapPure() public { MyLib.wrapPure(); }
} |
I have an example where it's not catching a revert but it's not a library, instead it's an abstract contract. The wrapper trick above works also in this case. |
Just faced a similar issue with an abstract contract and I managed to solve it using this method |
// This doesn't work.
function testRevertTransfer() external {
vm.expectRevert(bytes("TRANSFER_FAILED"));
SafeTransferLib.safeTransfer(token, address(0xBEEF), 1e18);
} fails because Going to close this one and track it with #5367 as there is a broader discussion about. thank you! |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (b44b045 2023-02-21T00:22:41.521901Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
Helper Contract:
In the example bellow
testRevertTransfer
is expected to be successful as it was supposed to catch the error message from the library but in reality it doesn't.Repo with reproducible error: https://github.com/pedrommaiaa/Foundry-Library-Error
Issue also opened in the forge-std repo: foundry-rs/forge-std#306
The text was updated successfully, but these errors were encountered: