Repository navigation
test(web): unit-test DepositWizard's XLM → stroops conversion and bucket pass-through - #1259
Merged
vjuliaife merged 2 commits intoOct 18, 2026
Merged
Conversation
…ildDepositRequest Move the api.deposit payload (BigInt(Math.round(Number(xlm) * 1e7)) and the bucket pass-through) into a pure lib/deposit-request.ts so it can be unit-tested. Behaviour is unchanged. Refs vjuliaife#667
…ough '50' -> 500000000, '0.1' -> 1000000, '12.3' -> 123000000, a real float-error case (0.07 * 1e7 = 700000.0000000001 -> 700000), every step-0.1 value up to 100 XLM, half-up rounding of sub-stroop input, and the bucket passed through exactly; plus a check that DepositWizard sends buildDepositRequest(xlm, bucket) to api.deposit. Closes vjuliaife#667
|
@abayomicornelius Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Deployment failed for project tariff-shield-web with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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
The conversion was inline in
handleDeposit:apps/webhas no component-test runner.vitest,@testing-library/reactandjsdomaren't dependencies anywhere in the monorepo and there's no vitest config. The existingcomponents/__tests__/Nav.*.test.tsxfiles import fromvitestbut can't actually run. I tried adding those dev dependencies, but:package-lock.jsonhas corrupted entries recording@rollup/plugin-commonjs@28.0.1and@rollup/pluginutilsas optional, Windows-only packages, sonpm installfails on macOS and Linux withEBADPLATFORM;npm cineeds the lockfile andpackage.jsonto stay in sync.So instead, the existing
lib/*.test.tsconvention is used:node:testwithnode:assert, run viatsx --testlike the roottest:scripts.What changed
Commit 1:
refactor(web), no behaviour changeapps/web/lib/deposit-request.ts:buildDepositRequest(xlm, bucket)returns{ amountStroops, bucket }using the identical formula,BigInt(Math.round(Number(xlm) * STROOPS_PER_XLM)).toString().DepositWizard.tsx:handleDepositnow callsapi.deposit(importerId, buildDepositRequest(xlm, bucket)). Nothing else in the component changed.Commit 2:
test(web)apps/web/lib/deposit-request.test.ts, one test per acceptance criterion, plus edge cases:amountStroops'50'(default)'500000000''0.1'(minimum)'1000000', no off-by-one'12.3''123000000'=Math.round(12.3 × 1e7)'0.07''700000'. The test first asserts0.07 * 1e7 !== 700000(it's700000.0000000001in IEEE-754), proving the rounding really absorbs float error.0.1to100.0tenths × 1000000'1.23456784'/'1.23456785''12345678'/'12345679'(nearest stroop, half up)bucket: 'collateral'/'reserve'deepEqualon the whole payloadapps/web/components/__tests__/DepositWizard.deposit-request.test.tspins the wiring:DepositWizardsends exactlybuildDepositRequest(xlm, bucket)toapi.depositand no longer converts inline. So the tested function is the one users actually get. It checks at the source level, because there's no React test runner (see above).Testing
tsc --noEmit --strictonlib/deposit-request.ts: clean.typecheck/lintweren't run, because I didn't do a full install (see the lockfile note above). The component change is one import plus one call-site line.Follow-ups worth filing
@rollup/plugin-commonjs/@rollup/pluginutilsare recorded as optional, Windows-only packages inpackage-lock.json, which breaksnpm installof anything new on macOS and Linux.Nav.*.test.tsxfiles depend onvitest+ Testing Library, which aren't installed, and no CI job runs web unit tests. They need a runner added (once the lockfile is fixed) or converting.Closes #667
Closes #663
Closes #664
Closes #666