Skip to main content
In this tutorial, you will run an ownership assertion against a small contract. You will see a normal operation succeed, an ownership change revert, and a temporary change escape an endpoint-only check.

Prerequisites

Install PCL and Foundry. This walkthrough was tested with PCL 1.6.0. It uses local contracts and needs no wallet or RPC connection.

1. Check out the reviewed library

The profile compiles the book’s examples. Compilation does not execute assertions. At this revision, the book profile has no supplied behavior tests; add the test below before running pcl test.

2. Add a target and three tests

Save this file as examples/assertions-book/test/OwnerPolicy.t.sol:
The target deliberately has an unrestricted ownership setter so the assertion has a violating transaction to reject. Its owner occupies slot 0, matching the example. It is a test fixture, not a contract to deploy. cl.assertion arms the selected assertion function for the next monitored call. This test selects the owner check. The source also has an admin check, which needs its own fixture and tests.

3. Run the tests

Expected result: 3 passed, 0 failed.

Adapt the example

Replace the teaching target with your deployed contract’s layout and call paths. Keep the accepted, rejected, and restored-state cases. If temporary authority changes are prohibited, an endpoint equality check is insufficient; the policy must observe the relevant writes or operations. For a constructor with configuration arguments, append abi.encode(...) to its creation code when calling cl.assertion. Do not fetch protocol state in that constructor: the assertion deployment runtime is isolated from the test’s contract state. Pass addresses explicitly and read protocol state during assertion execution. Continue with the ERC-4626 policy. Test each selected assertion function through a matching trigger. Before deployment, run historical backtests and scenarios on a replica of your protocol in alerting.