Forge Std: Standard library for Foundry testing
Collection of contracts and libraries that provide testing utilities and cheatcode wrappers for Forge and Foundry.
Learn more about Forge Std
Forge Std is a standard library that provides helper contracts and utilities for testing Solidity smart contracts with Forge and Foundry. It wraps Forge's cheatcodes in developer-friendly interfaces and includes utilities for error handling, storage manipulation, and test assertions. The library includes stdError for compiler built-in errors, stdStorage for finding and writing to storage slots without knowing the layout, and stdCheats for enhanced pranking functionality. It serves as the foundation for most Foundry-based smart contract testing workflows.
Storage Introspection
Automatically finds and writes to storage slots of any variable without requiring knowledge of the contract's storage layout, using SLOAD/SSTORE recording.
Cheatcode Wrappers
Provides developer-friendly interfaces around Forge's low-level cheatcodes, including enhanced pranking with automatic ETH provisioning and improved assertion utilities.
Built-in Error Handling
Includes comprehensive error definitions for all Solidity compiler built-in errors, making expectRevert testing more reliable and readable.
import "forge-std/Test.sol";
contract TestContract is Test {
ErrorsTest test;
function setUp() public {
test = new ErrorsTest();
}
function testExpectArithmetic() public {
vm.expectRevert(stdError.arithmeticError);
test.arithmeticError(10);
}
}
contract ErrorsTest {
function arithmeticError(uint256 a) public {
a = a - 100; // This will underflow
}
}See how people are using Forge Std
Related Repositories
Discover similar tools and frameworks used by developers
Optimism
Layer 2 blockchain that scales Ethereum using optimistic rollup technology and the open-source OP Stack framework.
Hyperledger Fabric
Modular enterprise blockchain framework with permissioned networks, pluggable consensus, and privacy controls.
Chainlink
Node software for operating in Chainlink's decentralized oracle network, connecting blockchain smart contracts to real-world data.
Aave V3 Core
Smart contracts for Aave Protocol V3, a decentralized liquidity market for lending and borrowing cryptocurrencies.
BFGMiner
Multi-threaded cryptocurrency miner supporting ASIC, FPGA, GPU, and CPU hardware with dynamic clocking and monitoring.