Skip to content

Add differential test harness comparing pre/post-refactor outputs for profit and fee math #1193

@Baskarayelu

Description

@Baskarayelu

Description

profits.rs::calculate_profit, calculate_treasury_split and fees.rs::calculate_transaction_fees have been refactored repeatedly (tiered fees, dust handling, treasury splits). To catch silent semantic drift during future refactors, add a differential harness that captures a frozen golden-vector corpus of (investment_amount, payment_amount, fee_bps, tier, volume) -> (investor_return, platform_fee, treasury, dust) and re-evaluates it against the live implementation. Any divergence fails CI and forces the author to explicitly bless the change.

Requirements and context

  • Secure: bless workflow is admin-reviewed via PR; no auto-bless.
  • Tested: corpus covers at least 500 input combinations including edge cases at i128::MAX, zero payment, overpayment.
  • Documented: docs/profit-fee-differential.md describing corpus refresh policy.
  • Reference: src/profits.rs, src/fees.rs.

Suggested execution

git checkout -b feature/profit-fee-differential

  • Add tests/profit_fee_golden.rs; store corpus as JSON under tests/fixtures/profit_fee_corpus.json.
  • Implement scripts/refresh-profit-fee-corpus.sh that regenerates the corpus from the current implementation, gated behind an env var to prevent accidental blessing.
  • Rust doc comments on the corpus loader explaining bless semantics.
  • Docs: docs/profit-fee-differential.md.
  • Validate that verify_no_dust is exercised across the corpus.

Test and commit

Run cargo test --test profit_fee_golden and confirm zero diffs against the committed corpus. Include the output and a note that any future delta requires a corpus refresh PR.

Example commit message

test(profits): add differential golden-vector harness for profit and fee math

Guidelines

  • Minimum 95% test coverage
  • Clear documentation in docs/profit-fee-differential.md
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    securitySecurity hardening and auditssmart-contractSoroban/Rust smart contract worksorobanStellar Soroban specifictestingTests and coverage

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions