Docs / Guides
Writing good properties
- State the rule, not an example.
fee(amount) <= amount and "exact math agrees" catch whole classes of bugs. fee(10000) == 30 catches one.
- Compare against a reference. A slow, obviously correct version (wider types, a loop) is the strongest oracle there is.
prop_fee_matches_exact_math compares against u128 arithmetic.
- Round trips and inverses.
decode(encode(x)) == x, redeem(deposit(x)) <= x.
- Conservation. A transfer neither creates nor destroys tokens.
- Monotonicity. Depositing more never yields fewer shares; a schedule that started later has vested no more.
- Guard preconditions by returning
true. If an input is outside the function's contract, if amount > balance { return true } keeps it from being reported. Prefer an input range when the region is contiguous, so no runs are wasted.
- Let aborts be findings. A property does not need to catch overflow. An abort is reported with its input recovered, which is usually exactly the bug.
Edit this page on GitHub