Skip to content

test(web): unit-test DepositWizard's XLM → stroops conversion and bucket pass-through - #1259

Merged
vjuliaife merged 2 commits into
vjuliaife:mainfrom
abayomicornelius:test/667-deposit-stroops
Oct 18, 2026
Merged

vjuliaife merged 2 commits into
vjuliaife:mainfrom
abayomicornelius:test/667-deposit-stroops

Conversation

@abayomicornelius

@abayomicornelius abayomicornelius commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The conversion was inline in handleDeposit:

const stroops = BigInt(Math.round(Number(xlm) * 1e7)).toString();
const result = await api.deposit(importerId, { amountStroops: stroops, bucket });

apps/web has no component-test runner. vitest, @testing-library/react and jsdom aren't dependencies anywhere in the monorepo and there's no vitest config. The existing components/__tests__/Nav.*.test.tsx files import from vitest but can't actually run. I tried adding those dev dependencies, but:

  • the root package-lock.json has corrupted entries recording @rollup/plugin-commonjs@28.0.1 and @rollup/pluginutils as optional, Windows-only packages, so npm install fails on macOS and Linux with EBADPLATFORM;
  • forcing past that rewrote about 9,500 lockfile lines, which isn't reviewable in a test PR, and CI's npm ci needs the lockfile and package.json to stay in sync.

So instead, the existing lib/*.test.ts convention is used: node:test with node:assert, run via tsx --test like the root test:scripts.

What changed

Commit 1: refactor(web), no behaviour change

  • New apps/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: handleDeposit now calls api.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:

Input Expected amountStroops Criterion
'50' (default) '500000000' ✅ #1
'0.1' (minimum) '1000000', no off-by-one ✅ #2
'12.3' '123000000' = Math.round(12.3 × 1e7) ✅ #3
'0.07' '700000'. The test first asserts 0.07 * 1e7 !== 700000 (it's 700000.0000000001 in IEEE-754), proving the rounding really absorbs float error. float stress
every step-0.1 value from 0.1 to 100.0 exactly tenths × 1000000 float stress
'1.23456784' / '1.23456785' '12345678' / '12345679' (nearest stroop, half up) rounding
bucket: 'collateral' / 'reserve' passed through exactly, deepEqual on the whole payload ✅ #4

apps/web/components/__tests__/DepositWizard.deposit-request.test.ts pins the wiring: DepositWizard sends exactly buildDepositRequest(xlm, bucket) to api.deposit and 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

cd apps/web
npx tsx --test lib/deposit-request.test.ts components/__tests__/DepositWizard.deposit-request.test.ts
ℹ tests 8   ℹ pass 8   ℹ fail 0
  • tsc --noEmit --strict on lib/deposit-request.ts: clean.
  • The full web typecheck/lint weren'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

  1. Lockfile: @rollup/plugin-commonjs / @rollup/pluginutils are recorded as optional, Windows-only packages in package-lock.json, which breaks npm install of anything new on macOS and Linux.
  2. Web component tests: the Nav.*.test.tsx files depend on vitest + 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

…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
@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

Deployment failed for project tariff-shield-web with the following error:

The `vercel.json` schema validation failed with the following message: should NOT have additional property `rootDirectory`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tariff-shield-web Error Error Oct 18, 2026 2:09pm UTC

@vjuliaife
vjuliaife merged commit 264403f into vjuliaife:main Oct 18, 2026
9 of 27 checks passed

This branch had an error being deployed

1 failed deployment
Preview — 078fc1dc Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants