From d703874f8723ceec8c2400abc60f73b144aa7560 Mon Sep 17 00:00:00 2001 From: Stephen Waits <1+swaits@noreply.git.swaits.com> Date: Sun, 11 Oct 2026 02:25:59 +0000 Subject: [PATCH] asset slice + testing initiative: fixed assets, property/mutation/fuzz testing, docs --- fuzz/fuzz_targets/fuzz_journal_line.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 fuzz/fuzz_targets/fuzz_journal_line.rs diff --git a/fuzz/fuzz_targets/fuzz_journal_line.rs b/fuzz/fuzz_targets/fuzz_journal_line.rs new file mode 100644 index 0000000..5c0b10f --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_journal_line.rs @@ -0,0 +1,24 @@ +// Fuzz target: journal line parsing must never panic, and the canonical +// form must be a fixed point: parse(canonical(x)) re-serializes to the +// same canonical bytes. Staged here; `cargo fuzz init` wires it up. +#![no_main] + +use libfuzzer_sys::fuzz_target; +use ledger_store::JournalLine; + +fuzz_target!(|data: &[u8]| { + // Garbage must return Err, never panic. + if let Ok(line) = serde_json::from_slice::(data) { + let canon = line.to_canonical(); + let line2: JournalLine = + serde_json::from_str(&canon).expect("canonical form must re-parse"); + assert_eq!( + line2.to_canonical(), + canon, + "canonical form is not a fixed point" + ); + // Sequence numbers survive the round trip. + assert_eq!(line.seq, line2.seq); + assert_eq!(line.line_type, line2.line_type); + } +});