foundry-testinglisted
Install: claude install-skill mrheyday/agentic-solidity-foundry-skill
# Foundry Testing Best Practices
## Fuzz Testing Strategy
1. **Fuzz function inputs by default** - When a test function has parameters, Foundry automatically fuzzes them
2. **Use `bound()` over `vm.assume`** - Prefer `bound(value, min, max)` to constrain inputs; `vm.assume` discards runs and wastes iterations
3. **Apply Equivalence Class Partitioning** - Only fuzz parameters that affect the code path under test. If a parameter doesn't change behavior, use a fixed representative value
4. **Maximize bounds** - Use the widest reasonable bounds to maximize coverage
```solidity
// Good: bound with max range
amount = bound(amount, 1, type(uint96).max);
// Avoid: vm.assume wastes fuzz runs
vm.assume(amount > 0 && amount < type(uint96).max);
```
## Test Organization
1. **Gas benchmarks use `_gas` suffix** - Enables filtering with `forge test --mt gas`
2. **Pattern**: `test_foo_gas()` calls `test_foo(fixed, values)` for deterministic gas measurement
3. **Tests can return values** for composition and reuse
4. **Group tests by functionality** with section headers
```solidity
function test_stake_gas() public returns (uint256 depositId) {
depositId = test_stake(address(this), 1 ether, OPERATOR, 0, address(this));
}
function test_stake(
address depositor,
uint96 amount,
address operator,
uint256 commissionRate,
address beneficiary
) public givenOperator(operator, commissionRate) returns (uint256 depositId) {
// Implementation...
}
```
## Modularity
1.