test(ledger): add proptest coverage for balance math#719
Draft
nicolasburtey wants to merge 1 commit into
Draft
Conversation
Adds 11 properties at 4096 cases each across two modules in cala-ledger, ~0.7s combined runtime. No production code changes. Snapshots (cala-ledger/src/balance/snapshot.rs, 5 properties): - new_snapshot_only_touches_target_cell — initial snapshot has all-zero balance cells except the (layer, direction) the entry targets - version_increments_by_one — every update_snapshot bumps version by 1 - sum_of_units_lands_on_target_cell — N entries to one (layer, direction) yield total == sum of units; cross-layer cells stay zero - balance_amounts_are_order_independent — applying any permutation of the same multiset of entries yields the same balance amounts. The additive-commutativity property the per-account double-entry contract rests on - available_rollup_composition — BalanceSnapshot::available rollup is (settled, settled+pending, settled+pending+encumbrance) on dr/cr AccountBalance (cala-ledger/src/balance/account_balance.rs, 6 properties): - settled_direction_dependent — Credit account: cr-dr; Debit account: dr-cr; sign flip on direction - pending_and_encumbrance_direction_dependent - available_layered_composition — available(Settled) == settled(); available(Pending) == pending() + settled(); available(Encumbrance) == encumbrance() + pending() + settled() - account_balance_available_matches_view — AccountBalance::available agrees with BalanceWithDirection::available for any direction/layer - derive_diff_with_zero_is_identity — diff against zero baseline returns self on all four amount fields - derive_diff_with_self_is_zero — diff against self returns zero on all four amount fields Adds proptest = "1.5" to workspace dependencies and to cala-ledger [dev-dependencies]. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
📊 Performance ReportCommit: be424d5 Cala Performance Benchmark Results (non-representative)Criterion Benchmark Results (single-threaded)
Load Testing Results (parallel-execution)
Note: Performance results may vary based on system resources and database state. Last updated by commit be424d5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds property-based test coverage for the pure balance math in `cala-ledger` — the closest CALA analog to "debits == credits" invariants. 11 properties at 4096 cases each, ~0.7s combined runtime. No production code changes.
`Snapshots` (cala-ledger/src/balance/snapshot.rs) — 5 properties
`AccountBalance` / `BalanceWithDirection` (cala-ledger/src/balance/account_balance.rs) — 6 properties
Notes
Test plan
Note
Low Risk
Adds only property-based tests and dev-dependencies (
proptest) around balance/snapshot math, with no production logic changes. Main risk is increased test runtime/flakiness or dependency/lockfile churn.Overview
Adds
proptestto the workspace andcala-ledgerdev-dependencies (updatingCargo.lock) to enable property-based testing.Introduces new
#[cfg(test)]proptest modules inbalance/account_balance.rsandbalance/snapshot.rsthat exercise invariants for direction-aware signed balances,available()rollups, snapshot update behavior (cell targeting, version increments, sum-of-units), order-independence, andAccountBalance::derive_diffidentity/zero-diff properties.Reviewed by Cursor Bugbot for commit be424d5. Bugbot is set up for automated code reviews on this repo. Configure here.