Effects and fixtures
Fe passes state and context into functions as effects (uses). Fuzzloom supports this pattern directly. For each effect type a target uses, provide a public function whose name starts with fixture_ and which returns that type:
pub struct Ledger { pub alice: u128, pub bob: u128, pub fees: u128 }
pub fn fixture_ledger() -> Ledger {
Ledger { alice: 1000000, bob: 0, fees: 0 }
}
pub fn prop_overdraft_changes_nothing(_ amount: u128) -> bool
uses (ledger: mut Ledger, policy: FeePolicy) {
let alice = ledger.alice
if amount <= alice { return true }
!transfer(amount, to_bob: true) && ledger.alice == alice
}How the fixture is found.
- Fuzzloom first looks for exactly one
pub fn fixture_*()that returns the effect's type. - If there is none, it looks for exactly one fixture named after the type in snake case. For
uses (clock: Clock)that isfixture_clock.
The second rule is for trait effects. The fixture returns any type that implements the trait:
pub trait Clock { fn now(self) -> u64 }
pub struct FixedClock { pub at: u64 }
impl Clock for FixedClock { fn now(self) -> u64 { self.at } }
pub fn fixture_clock() -> FixedClock { FixedClock { at: 1700000000 } }Fresh state every time. Every evaluation builds every effect from its fixture again. Evaluations never see each other's changes, so a failure replays exactly, and shrinking compares like with like. A bug that only appears after a particular sequence of calls is therefore out of reach for now; see what Fuzzloom does not do.
When a target is skipped. A target whose effect has no fixture, or several, is skipped with the reason:
skip prop_two src/lib.fe:4 uses L, and more than one fixture builds it (fixture_a, fixture_b)
skip prop_none src/lib.fe:5 uses Wallet, but the ingot has no `pub fn fixture_wallet() -> Wallet` to build itWhere the types live. The effect type must be defined in your ingot, or imported with a use line in the file that defines the target. fuzzloom list shows what each target uses and which fixture builds it:
prop prop_transfer_conserves_supply(amount: u128, to_bob: bool) src/lib.fe:54
uses mut Ledger <- fixture_ledger(), FeePolicy <- fixture_policy()