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
- 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
Description
DistributionEngine.distributeWithBatchguarantees the sum of payouts equalsrevenueAmountto the cent via a max-share adjustment, but this invariant is only spot-checked. Add fast-check property tests (the repo already depends onfast-check) asserting the invariant holds across randomized balances, investor counts, and revenue amounts.Requirements and context
src/services/distributionEngine.ts,src/services/distributionEngine.test.tssum(payouts) === revenueAmountand every payout>= 0Suggested execution
git checkout -b test/distribution-rounding-propertyfast-checkarbitraries for balance arrays and revenue amountsTest and commit
npm testExample commit message
test: property-based rounding invariants for DistributionEngineGuidelines