Skip to main content
Use pcl test to run Forge-style fuzz tests against assertions across random inputs.

Prerequisites

Start with a working local assertion test, a pinned library, and the assertion profile defined by your project. Confirm an allowed case and an expected assertion rejection before varying the inputs.

Example

This illustrative fragment assumes a PhyLockAssertion, a funded user1 with a 5 ether deposit, and the matching protocol fixture. It is not a standalone runnable test. Adapt it to a passing test in your project; the starter tutorial documents the separate failure in its pinned PhyLock suite.
With runs = 256, the runner targets 256 accepted fuzz cases within the vm.assume() constraints. The selected profile controls the run count; rejected inputs do not count as policy tests. This example checks allowed withdrawals only. Add separate tests for intended violations and legitimate exceptions.
Use vm.assume() to filter out invalid inputs that would cause the test to fail for reasons unrelated to your assertion logic.

Best Practices

Constrain inputs to realistic ranges with vm.assume(). Include valid boundary cases and combinations of inputs that affect the policy.

Running Fuzz Tests

Fuzz tests run automatically with pcl test:
You can configure the number of runs in your foundry.toml:
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.

Verify the Run

Confirm that the intended fuzz tests ran under the selected profile and inspect the reported run counts, failures, and rejected-input limits. A filtered-out test provides no evidence. Preserve any failing input as a regression case and run the full assertion suite before preparing a release. Learn More: