Skip to content

Add property-based dust-conservation tests for distribute_usdc_hashed across all percentage splits #1012

Description

@Baskarayelu

📋 Description

calculate_split and distribute_usdc_hashed in remittance_split/src/lib.rs split a total_amount across four categories (spending, savings, bills, insurance) emitting a DistributionCompletedEvent. Existing tests cover happy paths, but there is no systematic proof that the four split amounts always sum back to the original total with zero dust loss across the full space of valid percentage configurations.

This issue adds a property-based suite asserting the conservation invariant spending + savings + bills + insurance == total_amount for distribute_usdc_hashed across randomized percentages summing to 100 and randomized totals.

Why this matters: rounding bugs in split math silently leak or duplicate funds. Conservation is the single most important financial invariant for this contract and must hold for every valid config, not just the ones that happen to divide evenly.

🎯 Requirements & Context

Functional requirements

  • Add a test module exercising distribute_usdc_hashed (and calculate_split) with randomized inputs.
  • Assert the four allocation amounts sum exactly to total_amount (no dust created or lost).
  • Assert no allocation is negative and that PercentagesDoNotSumTo100 / PercentageOutOfRange reject invalid configs.
  • Cover the DistributionCompletedEvent payload matching the computed amounts.

Context & constraints

  • Soroban SDK 21.7.7; reuse the existing Env::default() + Address::generate() token mint helpers from remittance_split/src/test.rs.
  • Test-only change; if a real conservation bug is found, document it in the PR rather than silently patching.
  • Tests run with cargo test -p remittance_split.

🛠️ Suggested Execution

1. Fork & branch

git checkout -b test/split-dust-conservation

2. Implement changes

  • Add the property suite in a new test module wired under #[cfg(test)].
  • Add /// doc comments documenting the conservation invariant being proven.

3. Test & commit

cargo test -p remittance_split
  • Cover edge cases: total of 1 unit, totals near i128::MAX/2, all-to-one-category splits (100/0/0/0), and near-even four-way splits that force remainder distribution.

Example commit message

test(remittance): add property-based dust-conservation suite for distribute_usdc_hashed

Proves spending+savings+bills+insurance == total across randomized valid splits.

✅ Acceptance Criteria & Guidelines

Requirement Target
Conservation invariant proven across randomized configs Required
Negative/invalid-config rejection covered Required
Coverage of split math paths ≥ 95%, all branches
Doc comments explaining invariants Required
cargo test -p remittance_split + cargo clippy clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Questions and design discussion — join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA

Please drop a note in the channel when you pick this up so we can avoid duplicate work and unblock you fast. 🚀

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions