Skip to content

Add property-based tests for DistributionEngine rounding invariants #348

@thlpkee20-wq

Description

@thlpkee20-wq

Description

DistributionEngine.distributeWithBatch guarantees the sum of payouts equals revenueAmount to the cent via a max-share adjustment, but this invariant is only spot-checked. Add fast-check property tests (the repo already depends on fast-check) asserting the invariant holds across randomized balances, investor counts, and revenue amounts.

Requirements and context

  • Must be secure, tested, and documented
  • Should be efficient and easy to review
  • Relevant code: src/services/distributionEngine.ts, src/services/distributionEngine.test.ts
  • Property: sum(payouts) === revenueAmount and every payout >= 0

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/distribution-rounding-property
  • Implement changes
    • Add fast-check arbitraries for balance arrays and revenue amounts
    • Assert payout sum equals revenue and no negative payouts
    • Assert idempotent resume produces identical totals
  • Validate security and correctness assumptions

Test and commit

  • Run tests
    • npm test
  • Cover edge cases
    • Single investor, zero-balance investors filtered, dust remainder of 0.01, large counts
  • Include test output and notes

Example commit message

test: property-based rounding invariants for DistributionEngine

Guidelines

  • Minimum 95 percent test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions