test: add fee, commission, and net-proceeds calculation tests - #574
Merged
Conversation
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
|
@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. |
Contributor
|
Thanks for your contribution! ❤️ It looks like this PR isn't linked to an issue yet. Please add |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)DEPOSIT_FEE_USDC constantNet proceeds (amount − fee)roundToCents(n - DEPOSIT_FEE_USDC)formulaprojectedReturn — simple interestroundToCents — monetary precisionformatDecimal — display precisionroundToDecimals — generic precisionIntegration: full deposit previewKey regressions now caught
DEPOSIT_FEE_USDCis changed from0.01, the constant suite fails immediatelyroundToCentsloses theNumber.EPSILONfix, the1.005 → 1.01test failsprojectedReturnis accidentally made compound instead of simple, the linear scaling tests failWhat was tested
All 48 tests pass:
No runtime code was changed — test-only PR.
closes #447