Fuzz testing is a technique for testing general robustness of code by running many tests with random inputs. This is useful for assertions as it helps identify edge cases and unexpected behavior. You can use Forge’s built-in fuzz testing capabilities to test your assertions with random inputs.
Example
function testAssertionAllowsValidWithdrawalFuzz(uint256 withdrawalAmount) public {
    // Bound the withdrawal amount to reasonable values
    vm.assume(withdrawalAmount > 0);
    vm.assume(withdrawalAmount <= assertionAdopter.deposits(user1));
    vm.assume(withdrawalAmount <= 100 ether); // Reasonable upper bound
    assertEq(assertionAdopter.deposits(user1), 5 ether);
    // Setup assertion for next transaction
    cl.assertion({
        adopter: address(assertionAdopter),
        createData: type(PhyLockAssertion).creationCode,
        fnSelector: PhyLockAssertion.assertionWithdrawInvariant.selector
    });
    // Execute withdrawal - this should succeed
    vm.prank(user1);
    assertionAdopter.withdraw(withdrawalAmount);
    assertEq(assertionAdopter.deposits(user1), 5 ether - withdrawalAmount);
}
 
This would run the test with 256 different values for withdrawalAmount that adhere to the bounds set by the vm.assume() constraints.
Use vm.assume() to filter out invalid inputs that would cause the test to fail for reasons unrelated to your assertion logic.
 
Best Practices
- Set reasonable bounds - Use 
vm.assume() to constrain inputs to valid ranges 
- Test multiple parameters - Fuzz multiple inputs simultaneously to catch interaction bugs
 
- Use meaningful ranges - Consider the actual values your protocol will encounter
 
- Check for reverts - Ensure assertions don’t false-positive on valid edge cases
 
Running Fuzz Tests
Fuzz tests run automatically with pcl test:
# Run with default profile
pcl test --match-test testFuzz
# Run with dedicated fuzz profile
FOUNDRY_PROFILE=fuzz-assertions pcl test
 
You can configure the number of runs in your foundry.toml:
[fuzz]
runs = 256  # Default is 256
max_test_rejects = 65536  # Maximum rejected inputs before failing
 
Consider creating a separate profile for fuzz tests so they don’t run during quick local development cycles. See CI/CD Integration for complete profile configuration examples.  
Learn More: