Foundry Example
Work in Progress -- This guide provides a starting point for using Foundry (Forge) for smart contract testing on the Lithosphere network. Full examples will be added as the contract suite grows.
Overview
Foundry is used alongside Hardhat in the Lithosphere development stack as defined in ADR-002 (Technology Stack). While Hardhat serves as the primary TypeScript-native development framework, Foundry provides fast fuzz testing through Forge.
Forge
Fast compilation and fuzz testing of Solidity contracts
Cast
Command-line tool for interacting with deployed contracts
Anvil
Local testnet node (alternative to Hardhat Network)
Basic Setup
Install Foundry
# Install Foundryup (the Foundry installer)
curl -L https://foundry.paradigm.xyz | bash
# Install/update Foundry tools
foundryupThis installs forge, cast, and anvil.
Initialize a Foundry Project
This generates the following structure:
Configure for Lithosphere
Edit foundry.toml:
Building Contracts
Running Tests
Standard Tests
Fuzz Testing
Fuzz testing is a key reason Foundry is included in the Lithosphere stack. Forge automatically fuzzes any test function that takes parameters:
Run fuzz tests with a high number of runs for thorough coverage:
This is the same configuration used in the Lithosphere CI pipeline for contract auditing.
Security Analysis
Slither Static Analysis
Run Slither and output results in SARIF format for integration with CI tools:
Contract CI Pipeline
The full contract audit pipeline used in the Lithosphere CI (from ADR-002):
Gas Snapshots
Foundry can generate gas snapshots for tracking gas usage over time:
Deploying with Forge
Further Reading
Hardhat Example -- Primary development framework with TypeScript support
Smart Contracts -- Lithosphere smart contract architecture
CI/CD Guide -- How Foundry fits into the automated pipeline
Foundry Book -- Official Foundry documentation
Last updated