Writing properties
A property is a public function whose name starts with prop_ and which returns bool. It states something that must be true for every input. Put it anywhere under your ingot's src/:
fe
/// Fee charged on `amount`, rounded down: 30 basis points.
pub fn fee(_ amount: u64) -> u64 {
amount.wrapping_mul(30) / 10000
}
/// The fee matches exact arithmetic for every amount.
pub fn prop_fee_matches_exact_math(_ amount: u64) -> bool {
let exact: u128 = (amount as u128) * 30 / 10000
(fee(amount) as u128) == exact
}bash
npx fuzzloom list # confirm Fuzzloom sees it
npx fuzzloom fuzz --seed 7text
FAIL prop_fee_matches_exact_math(u64) counterexample at input 2
amount = 614891469123651721
shrunk from 4762291152399575021 in 1414 evaluations
reproduce: fuzzloom reproduce prop_fee_matches_exact_math-0e05b819614891469123651721 is u64::MAX / 30 + 1, the smallest amount for which amount * 30 wraps. The shrinker found the exact threshold, not just some large failing value.
What can be an argument: 1 to 3 arguments, each u8, u16, u32, u64, u128, u256, i8, i16, i32, i64, i128, i256 or bool. Arguments may be positional (_ amount: u64) or labelled (amount: u64). A prop_ function that does not fit is listed as skipped by list and doctor, with the reason:
text
skip prop_addr src/lib.fe:12 parameter "a" has type Address; supported: u8, u16, ...