diff --git a/crates/ledger-core/tests/kernel_bridge/entries.rs b/crates/ledger-core/tests/kernel_bridge/entries.rs index 40bcf6a9..466f16e8 100644 --- a/crates/ledger-core/tests/kernel_bridge/entries.rs +++ b/crates/ledger-core/tests/kernel_bridge/entries.rs @@ -39,6 +39,13 @@ fn arb_direction() -> impl Strategy { ] } +/// Cents, plus the `i64` range's edges: [`arb_cents`] is bounded to ±2^40 +/// (what a journal line may carry), so it never reaches the negation that +/// overflows, and the refusal path would go untested. +fn arb_edge_cents() -> impl Strategy { + prop_oneof![arb_cents(), Just(i64::MIN), Just(i64::MAX)] +} + proptest! { #![proptest_config(ProptestConfig::with_cases(1000))] @@ -121,12 +128,15 @@ proptest! { } /// `kernel::reverse_target` is the exact opposite at both types, and - /// each refuses the same out-of-range inputs (law 24). + /// `i64` refuses its range's edge (`i64::MIN`, which no negation can + /// hold): the edge strategy reaches that arm, and Decimal, which can + /// hold the negation, answers the opposite (law 24). The refusal is + /// the integer proof model's bound, not the law's. #[test] fn reverse_target_agrees( - amount in arb_cents(), - cash in arb_cents(), - in_kind in arb_cents(), + amount in arb_edge_cents(), + cash in arb_edge_cents(), + in_kind in arb_edge_cents(), direction in arb_direction(), ) { let t = kernel::PartyTarget { @@ -147,10 +157,24 @@ proptest! { cash: dec(r.cash), in_kind: dec(r.in_kind), }; - prop_assert_eq!( - kernel::reverse_target(t).map(as_dec), - kernel::reverse_target(d) - ); + match kernel::reverse_target(t) { + Some(r) => prop_assert_eq!(Some(as_dec(r)), kernel::reverse_target(d)), + None => { + prop_assert!( + amount == i64::MIN || cash == i64::MIN || in_kind == i64::MIN, + "reverse_target refused an in-range target" + ); + prop_assert_eq!( + kernel::reverse_target(d), + Some(kernel::PartyTarget { + amount: -dec(amount), + direction: direction.flip(), + cash: -dec(cash), + in_kind: -dec(in_kind), + }) + ); + } + } } /// `kernel::part_weight` is the same weight at i32, i64 and i128, and diff --git a/docs/proofs/entries.md b/docs/proofs/entries.md index 86efac50..930aeb56 100644 --- a/docs/proofs/entries.md +++ b/docs/proofs/entries.md @@ -45,9 +45,12 @@ verification, 3 covers, build included). - `part_weight_agrees`: `part_weight` is the same weight at `i32`, `i64` and `i128`, and `None` exactly for a part no month has (laws 26-28). - `reverse_target_agrees`: `reverse_target` is the exact opposite at both - types and refuses the same out-of-range inputs (law 24). The earlier - bridge only passed it to `and_then`, which is a mention, not a call; this - property calls it. + types. The edge strategy reaches `i64::MIN`, which `i64` refuses because + no negation can hold it; `Decimal` can hold the negation, so the property + compares its answer there (the exact opposite). The refusal is the + integer proof model's bound, not the law's. The earlier bridge only + passed it to `and_then`, which is a mention, not a call; this property + calls it. Why these laws: `Direction::of` is the sign classification the party direction law (23) is stated over, and `part_weight` is the weight the