You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
If you import as follows: import "forge-std/Test.sol";, as mentioned at the start, it will work
That said, I think we should modify the example code to reflect the best practices (e.g. named imports), especially as this is the entrypoint for beginners. We should also update the Solidity pragma to use pragma solidity ^0.8.13; to reflect the one generated by forge init.
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 .
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
The text was updated successfully, but these errors were encountered: