CredibleTest and the Forge test utilities. Use the testing strategy for integration tests and production readiness.
Prerequisites
Use a project with PCL installed, a pinnedcredible-std dependency, the assertion under test, and protocol fixtures. Run commands from the project root using the assertion test profile configured in foundry.toml; see profile configuration.
For a complete first exercise, use Run an Example Policy Locally. The patterns below assume you already have a test project.
Register an Assertion for the Next External Call
The interface below explains the harness mechanism. In your test project, importCredibleTest from your pinned credible-std dependency, as the next example does; do not create a second local definition.
Using the Testing Interface
This example uses the contracts and layout from the pinned starter tutorial. In another project, substitute your own target, assertion, imports, and expected failure. A test registers the assertion, calls the protocol, and checks the result:Local assertion tests use reverts to model rejection by a participating builder. They do not exercise Ethereum block markers, guard coverage, or RPC routing; test those with the integration testing plan. See Local Testing vs. Production for details.
cl.assertion() registers one assertion function for the next monitored external call. Its trigger must match that call. Use vm.prank() to select the caller and vm.expectRevert() to check the expected failure. Successful transactions retain their state changes.
Testing Assertion Contracts with Constructor Arguments
Useph.getAssertionAdopter() inside an assertion function to obtain its assigned contract; it is unavailable in the constructor. If your assertion declares constructor arguments, append their ABI encoding to the creation bytecode in the exact declared order. The following fragment illustrates an assertion with one address argument; only use it if that constructor exists:
Testing Patterns
Batch Operation Testing Pattern
Use a helper contract to execute several operations in one transaction. Check their cumulative effect on the final state.Prefer the helper function above. A fallback call through
address(batchUpdater).call("") does not propagate revert data automatically. If you use it, check the result explicitly:Protocol Mocking
Use a mock protocol to create states that the real protocol’s checks prevent. For example, expose a balance change that should make the assertion fail. See the credible-std examples for mocks.Gas Limits
Assertion execution has a runtime-configured gas budget. Obtain the active budget from the deployment operator and test the maximum expected workload against it; do not infer it from the local EVM block gas limit. Exceeding the limit causesOutOfGas and invalidates the candidate, even if the intended policy condition would pass. This prevents attackers from bypassing enforcement through expensive inputs. Test the maximum expected workload.
The Happy Path Problem
Successful checks often cost more gas because loops and checks run to completion. Failure cases can exit early. Match the compiler and optimizer settings used for deployment. Thecredible-std protection tests use FOUNDRY_PROFILE=ci, which enables optimization. With the reviewed library and PCL 1.6.0, the Safe configuration test with 32 modules exceeds the assertion gas limit under the default unoptimized profile and passes under ci.
Testing Recommendations
- Test with realistic data volumes - if your assertion loops through items, test with the maximum expected count
- Test batch operations at maximum expected size
- Use
pcl test -vvvto monitor gas usage - If approaching the limit, optimize or split the assertion
Run and Verify Your Tests
Runpcl test with your project’s assertion profile. Use --match-contract or --match-test to isolate a case, then run the full assertion suite before preparing a release.
Check that the intended assertion function executed, allowed operations retained their expected state changes, and rejected operations failed for the expected assertion reason. A test passing because the protocol reverted before the assertion ran does not validate that assertion. Include legitimate exceptions and maximum-workload cases.
When the results match the approved policy, prepare a release. If a case fails unexpectedly, use Troubleshooting before continuing.
What’s Next?
- If you encounter issues while testing, check the Troubleshooting Guide
- Learn more about Writing Your Own Policies
- Explore assertion examples in the Use Cases Book

