Introduction to Assertions
Resource for assertion use cases and patterns
Assertions Book
This resource is a collection of use cases and patterns for assertions. Each assertions is named after the use case it is intended to solve and will be accompanied by an explanation and a code example.
In the menu to the left you can find all the assertions.
If you have any questions or issues getting things to work please reach out on telegram @phylax_credible_layer.
If you think that an assertion is missing, please don’t hesitate to open a PR or reach out.
Introduction to Assertions
Assertions are a way to define states that should never be reached in your smart contracts. You can think of them as opposite intents. Instead of defining what you want to happen, you define what you don’t want to happen.
In the use case and patterns of this book, we will only show the functions of the assertions. Below is a full example of an assertion contract for reference:
It can be assumed that all assertion examples will have a similar structure, but only the assertions functions will be shown.
For the actual example listed above see the Owner Change assertion.
The ph
keyword is a global keyword that is used to interact with the Phylax Credible Layer. It is imported from the credible-std
library.
The Trigger
struct is a struct that is used to define the triggers for the assertion. It is imported from the credible-std
library.
The TriggerType
enum is an enum that is used to define the type of trigger. It is imported from the credible-std
library.