Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core-wallet | Add proptests to notes #3309

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

welf
Copy link
Contributor

@welf welf commented Jan 1, 2025

Add proptests to notes

  • Add proptest to Cargo.toml
  • Implement FromIterator<(BlsScalar, NoteLeaf)> for NoteList but keep the existing current From<Vec<(BlsScalar, NoteLeaf)>> for NoteList implementation for backward compatibility
  • Add test_balance_calculation_properties property test
    Tests the balance calculation functionality ensuring that:
    • Total balance correctly represents sum of all note values
    • Balances are always non-negative
    • Spendable balance never exceeds total balance
    • For small note sets (<=MAX_INPUT_NOTES), spendable equals total
    • Spendable balance is sum of MAX_INPUT_NOTES highest value notes
  • Add test_note_picking_properties property test
    Tests note picking behavior:
    • Returns empty list if MAX_INPUT_NOTES highest value notes can't cover target
    • If sum is sufficient AND count <= MAX_INPUT_NOTES, returns all notes
    • Otherwise uses pick_lexicographic to find valid combination
  • Add test_note_picking_lexicographic_order property test
    Tests that note picking follows lexicographic ordering of indices when selecting notes from larger set:
    • Returns empty list if MAX_INPUT_NOTES largest notes can't cover target
    • Returns all notes if count <= MAX_INPUT_NOTES
    • Otherwise finds first valid combination in lexicographic order
  • Add test_note_picking_duplicate_values property test
    Tests note picking behavior with duplicate value notes:
    • Returns empty list if target exceeds MAX_INPUT_NOTES * value
    • Picks enough notes to meet target
    • Never picks more than MAX_INPUT_NOTES
  • Add test_note_picking_max_input_boundary property test
    Tests note picking behavior at MAX_INPUT_NOTES boundary conditions:
    • Proper handling of note count at MAX_INPUT_NOTES boundary
    • Correct selection when multiple valid combinations exist
    • Adherence to lexicographic ordering with sequential values
  • Add test_note_picking_minimal_differences property test
    Tests note picking implementation's core behavior with minimal value differences:
    • Notes are sorted by value in ascending order
    • Algorithm always attempts to use exactly MAX_INPUT_NOTES notes unless:
      • Input is empty (returns empty)
      • Input size <= MAX_INPUT_NOTES (returns all)
      • MAX_INPUT_NOTES largest notes can't cover target (returns empty)
    • For large inputs:
      • Tries combinations of exactly MAX_INPUT_NOTES notes
      • Tests combinations in lexicographic order: [0,1,2,3], [0,1,2,4], etc.
      • Returns first combination whose sum >= target
  • Add test_note_picking_extreme_distributions property test
    Tests note picking with extreme value distributions:
    • Mix of very small and very large values
    • Target values that could be met by either many small or few large notes
    • Correct order-dependent selection (uses first valid combination)
    • Proper handling of large value differences without overflow
  • Add test_note_picking_target_boundaries property test
    Tests note picking with specific target edge cases:
    • Target exactly equals sum of some combination
    • Target greater than sum of MAX_INPUT_NOTES largest notes
    • Target less than smallest note (should still work if sum sufficient)
  • Add test_note_picking_degenerate_cases property test
    Tests note picking with degenerate inputs:
    • Notes with minimum possible values
    • Notes with maximum possible values
    • Target values at u64 boundaries

@welf welf self-assigned this Jan 1, 2025
@welf welf requested review from ZER0, HDauven and Neotamandua January 1, 2025 23:53
@HDauven HDauven requested review from Daksh14 and moCello January 2, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant