Credible Layer
Testing Assertions
Testing assertions is very similar to writing regular Forge tests. If you’re familiar with Forge testing, you’ll feel right at home. You get access to all the same testing utilities:
- Standard assertions (
assertEq
,assertTrue
, etc.) - Cheatcodes (
vm.prank
,vm.deal
,vm.warp
, etc.) - Console logging
- Test setup with
setUp()
function
PCL Testing Interface
PCL extends Forge’s testing capabilities with additional utilities specifically for testing assertions. Here’s the key interface:
Using the Testing Interface
Here’s how to use these utilities in your tests:
Key concepts:
- Use
cl.addAssertion()
to register assertions with contracts you want to monitor - Use
cl.validate()
to test how assertions respond to transactions - No return value from
cl.validate()
, but you can usevm.expectRevert()
to check if it reverts - Multiple assertions can be linked to the same contract
This means you can leverage your existing Forge testing knowledge while using these additional features to verify your assertions work correctly.