How to test assertions
assertEq
, assertTrue
, etc.)vm.prank
, vm.deal
, vm.warp
, etc.)setUp()
functioncl.assertion()
to register assertions that will be run on the next transactionvm.prank()
to simulate a transaction from a specific addressvm.expectRevert()
to verify that the assertion reverts when expectedvm.expectRevert()
allows you to verify the exact error message returned by the assertioncl.assertion()
will be validated against the assertionph.getAssertionAdopter()
to get the assertion adopter instead of explicitly setting it in the constructor of the assertion contract.
There might however be cases where you want to define additional values that your assertion contract should have access to. For example, this could be the address of a token.
In this case you need to append the ABI-encoded constructor arguments to the contract bytecode.
The abi.encodePacked()
function concatenates the bytecode with the encoded arguments, creating the complete deployment data needed to deploy the contract with the correct constructor parameters.
type(OwnableAssertion).creationCode
- the contract bytecodeabi.encode(address(token))
- the encoded constructor argumentsaddress(batchUpdater).call("")
.
This is not the recommended way to do batch operations, since it’s a low level call and it doesn’t properly bubble up the revert reason. We recommend using the pattern above instead.If you do use a fallback function, you can use the following pattern to check the result of the batch operation: