Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
0.1.0 (39b6e39 2022-03-08T00:08:31.449073+00:00)
What command(s) is the bug in?
forge test
Operating System
macOS (M1)
Describe the bug
when trying to test internal calls (like libraries), expectRevert cheat code doesn't work.
example code:
pragma solidity ^0.8.4;
import { DSTest } from "ds-test/test.sol";
import { CheatCodes } from "./utils/CheatCodes.sol";
library Library {
function willRevert() internal pure {
revert("reason");
}
}
contract RevertTest is DSTest {
CheatCodes private constant VM = CheatCodes(HEVM_ADDRESS);
function testExternal() external {
VM.expectRevert("reason");
this.willRevert();
}
function testInternal() external {
VM.expectRevert("reason");
willRevert();
}
function testLibrary() external {
VM.expectRevert("reason");
Library.willRevert();
}
function willRevert() public pure {
revert("reason");
}
}
forge test output:
Running 3 tests for RevertTest.json:RevertTest
[PASS] testExternal() (gas: 3762)
Traces:
[3762] RevertTest::testExternal()
├─ [0] VM::expectRevert(reason)
│ └─ ← ()
├─ [326] RevertTest::willRevert()
│ └─ ← "reason"
└─ ← ()
[FAIL. Reason: reason] testInternal() (gas: 3299)
Traces:
[3299] RevertTest::testInternal()
├─ [0] VM::expectRevert(reason)
│ └─ ← ()
└─ ← "reason"
[FAIL. Reason: reason] testLibrary() (gas: 3233)
Traces:
[3233] RevertTest::testLibrary()
├─ [0] VM::expectRevert(reason)
│ └─ ← ()
└─ ← "reason"
Failed tests:
[FAIL. Reason: reason] testInternal() (gas: 3299)
[FAIL. Reason: reason] testLibrary() (gas: 3233)
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
0.1.0 (39b6e39 2022-03-08T00:08:31.449073+00:00)
What command(s) is the bug in?
forge test
Operating System
macOS (M1)
Describe the bug
when trying to test internal calls (like libraries),
expectRevertcheat code doesn't work.example code:
forge testoutput: