Closed pedrommaiaa closed 1 month ago
As a workaround, you can define a wrapper for your pure function and call it using this
in your test:
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.
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
expectRevert
cheatcode expects an revert from the next external call, so in the original issue
// This doesn't work.
function testRevertTransfer() external {
vm.expectRevert(bytes("TRANSFER_FAILED"));
SafeTransferLib.safeTransfer(token, address(0xBEEF), 1e18);
}
fails because SafeTransferLib
is inlined in contract. To check behavior you can change the signature of SafeTransferLib.safeTransfer
(lib/solmate/src/utils/SafeTransferLib.sol
) to public instead internal and test is going to pass.
Going to close this one and track it with https://github.com/foundry-rs/foundry/issues/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: https://github.com/foundry-rs/forge-std/issues/306