-
Notifications
You must be signed in to change notification settings - Fork 796
Closed
Labels
Description
Chapter 8 -> section 8.1 lacks import of stdError & Vm
Issue
There are multiple places where forge-std's components are used without importing them .
- Lack of stdError and Vm import
A good practice is to use the pattern test_Revert[If|When]_Condition in combination with the [expectRevert](https://book.getfoundry.sh/cheatcodes/expect-revert.html) cheatcode (cheatcodes are explained in greater detail in the following [section](https://book.getfoundry.sh/forge/cheatcodes.html)). Also, other testing practices can be found in the [Tutorials section](https://book.getfoundry.sh/tutorials/best-practices.html). Now, instead of using testFail, you know exactly what reverted and with which error:
function test_CannotSubtract43() public {
vm.expectRevert(stdError.arithmeticError);
testNumber -= 43;
}
Impact
Beginners get confused when stdError is not found upon compilation of smart contracts because foundry demands explicit imports
Fix
Add following lines in the docs to import used components
import {Vm} from "forge-std/Vm.sol";
import {stdError} from "forge-std/StdError.sol";