foundry - Ethereum Development Framework (original) (raw)

Forge Standard Library Reference

Forge Standard Library (Forge Std for short) is a collection of helpful contracts that make writing tests easier, faster, and more user-friendly.

Using Forge Std is the preferred way of writing tests with Foundry.

What's included:

import {Vm} from "forge-std/Vm.sol";  
import {console} from "forge-std/console.sol";  

Note: console2.sol contains patches to console.sol that allow Forge to decode traces for calls to the console, but it is not compatible with Hardhat.

import {console2} from "forge-std/console2.sol";  
import {Script} from "forge-std/Script.sol";  
import {Test} from "forge-std/Test.sol";  

Forge Std's Test

The Test contract in Test.sol provides all the essential functionality you need to get started writing tests.

Simply import Test.sol and inherit from Test in your test contract:

import {Test} from "forge-std/Test.sol";
 
contract ContractTest is Test { ...

What's included:

console.log(alice.balance); // or `console2`  
assertEq(dai.balanceOf(alice), 10000e18);  
// Compute the address a contract will be deployed at for a given deployer address and nonce  
address futureContract = computeCreateAddress(alice, 1);