Skip to content

test: add fee, commission, and net-proceeds calculation tests - #574

Merged
dadadave80 merged 1 commit into
Heliobond:mainfrom
CodedMumu:feat/fee-calc-tests
Sep 6, 2026
Merged

test: add fee, commission, and net-proceeds calculation tests#574
dadadave80 merged 1 commit into
Heliobond:mainfrom
CodedMumu:feat/fee-calc-tests

Conversation

@CodedMumu

@CodedMumu CodedMumu commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fee, commission, and net-proceeds calculations had zero test coverage. Any change to DEPOSIT_FEE_USDC, roundToCents, projectedReturn, or the inline net-proceeds formula could silently break the values shown to investors in the Deposit screen.

This PR adds src/lib/feeCalculations.test.ts — 48 tests covering every financial formula in the deposit flow.

What was added

src/lib/feeCalculations.test.ts (333 lines, 48 tests)

Test suite # tests What it guards
DEPOSIT_FEE_USDC constant 4 Exact fee value, sub-cent promise, positivity, below MIN_DEPOSIT
Net proceeds (amount − fee) 8 roundToCents(n - DEPOSIT_FEE_USDC) formula
projectedReturn — simple interest 13 Guard rails + 1y/5y/10y projections matching the Deposit screen
roundToCents — monetary precision 7 The 1.005 float trap and standard rounding cases
formatDecimal — display precision 6 Trailing zeros, round-before-format, string type
roundToDecimals — generic precision 4 0/3/7 decimal places, epsilon drift
Integration: full deposit preview 5 All fields composed together (fee + proceeds + shares + projections)

Key regressions now caught

  • If DEPOSIT_FEE_USDC is changed from 0.01, the constant suite fails immediately
  • If roundToCents loses the Number.EPSILON fix, the 1.005 → 1.01 test fails
  • If projectedReturn is accidentally made compound instead of simple, the linear scaling tests fail
  • If the net-proceeds formula drops the fee subtraction, the integration tests fail

What was tested

All 48 tests pass:

✓ src/lib/feeCalculations.test.ts (48 tests) 11ms
Test Files  1 passed (1)
Tests       48 passed (48)

No runtime code was changed — test-only PR.

closes #447

Zero test coverage existed for the financial math shown in the Deposit
screen. Any change to fee constants, roundToCents, projectedReturn, or
the net-proceeds formula could silently regress.

This commit adds src/lib/feeCalculations.test.ts (48 tests, all passing):

  DEPOSIT_FEE_USDC constant (4 tests)
    - exact value, sub-cent promise, positive/finite, smaller than min deposit

  Net proceeds — amount minus fee (8 tests)
    - standard 100 USDC, minimum deposit, fee-sized input, sub-fee input,
      large amounts, decimal precision, formula parity with roundToCents,
      idempotency check

  projectedReturn — simple interest (13 tests)
    - zero/negative/NaN/Infinity amounts return 0
    - 1/5/10-year returns at 6%
    - linear scaling with years and amount
    - fractional rates (4.75%), default years=1, zero rate
    - matches the three Deposit screen projections (1y/5y/10y)

  roundToCents — monetary precision (7 tests)
    - the classic 1.005 float trap (rounds to 1.01 not 1.00)
    - 2.355 → 2.36, 1.004 → 1.00
    - zero, negative, idempotency, max 2 decimal digits

  formatDecimal — display precision (6 tests)
    - 0 and 100 USDC at 2dp, share count at 4dp
    - round-before-format, string return, trailing zeros

  roundToDecimals — generic precision helper (4 tests)
    - 0/3/7 decimals, 0.1+0.2 epsilon drift

  Integration: full deposit preview (5 tests)
    - 100 USDC / 1.0 price / 6%: verifies fee, proceeds, shares, 1y/5y/10y
    - 250 USDC / 1.05 price / 5.5%
    - minimum deposit yields positive net proceeds
    - fee is flat (same for $10 and $10k deposits)
    - proceeds scale linearly with amount
@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

@CodedMumu is attempting to deploy a commit to the David Dada's projects Team on Vercel.

A member of the Team first needs to authorize it.

@sshdopey

sshdopey commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution! ❤️ It looks like this PR isn't linked to an issue yet. Please add Fixes #123 (or Closes #123) to the PR description, or link it via the Development sidebar on the right. Once linked, I'll automatically re-review and merge if the changes show effort toward the issue. No stress — we'll help fix things up if needed!

@dadadave80
dadadave80 merged commit a803806 into Heliobond:main Sep 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testing: No unit tests for investment calculation logic — high-risk area

3 participants