Repository navigation
Conversation
These two money-conversion helpers in web/lib/agentvouchUsdc.ts had no behavioral test. The only existing reference was a source-text grep in web/__tests__/components/wallet-detection-source.test.ts, which asserts the import, not the behavior. Per AGENTS.md §3, pure helpers need real behavioral tests. Adds a behavioral suite pinning: - usdcToMicros: whole/fractional conversion, 6-decimal rounding (halfway rounds up, sub-micro truncates to 0), and the rejection of negative/non-finite inputs. - formatUsdcMicrosValue: null/undefined defaults to '0.00', bigint/number/ string input equivalence, minimum/maximum decimal formatting, thousand grouping, and the minimumFractionDigits override. Every value is the exact output confirmed against the implementation.
This branch was successfully 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
Adds behavioral tests for the two USDC money-conversion helpers in
web/lib/agentvouchUsdc.ts:usdcToMicros(amountUsdc)— converts a human decimal USDC amount to the6-decimal micro-unit the app and on-chain contract use.
formatUsdcMicrosValue(micros, minimumFractionDigits)— formats a microvalue back to a human-readable USDC string.
These functions sit on every USDC amount a user sees and every micro amount the
app converts between the decimal world and the on-chain 6-decimal micro-unit,
so a subtle rounding bug here corrupts displayed balances, purchase amounts, and
the on-chain transfer amount.
Why
The only prior reference for these helpers was a source-text grep in
web/__tests__/components/wallet-detection-source.test.ts, which asserts theimport exists but says nothing about behavior. Per AGENTS.md §3.24, pure helpers
get real behavioral tests, not source-text assertions.
What was verified
implementation with a throwaway probe run before the assertions were written,
so the tests pin exact behavior, not just shape.
usdcToMicros:0 -> 0,1 -> 1_000_000n,0.01 -> 10_000n,0.1 -> 100_000n,12345.6789 -> 12_345_678_900n,0.0000005 -> 1n(halfway rounds up via
Math.round),0.0000004 -> 0n(below half truncates),1.23456789 -> 1_234_568n, sub-micro ->0n, and rejection of negative andNaN/Infinity/-Infinityinputs with the clear message.formatUsdcMicrosValue:null/undefined -> "0.00",0 -> "0.00",10_000n -> "0.01",1_500_000n -> "1.50",999_999n -> "0.999999",12_345_678n -> "12.345678",1_000_000_000_000n -> "1,000,000.00",identical bigint/number/string input handling (
1_000_000/1000000->"1.00"), andminimumFractionDigitsoverrides ("0.0100"for 4,"0.010000"for 6,"1.5"for 0).Verification
npx vitest run __tests__/lib/agentvouchUsdc.test.ts— 10 tests passed.npm run format:check— all files Prettier-clean.npm run lint— passed.npm run typecheck— passed (tsc --noEmitafternext typegen).npm run test— 153 test files / 1321 tests passed (web + cli workspaces).npm exec --workspace @agentvouch/web -- next build --webpack— notrunnable in this cron environment because
web/.env.local/DATABASE_URLis absent; the build fails during prerendering on
DATABASE_URLbefore itcould compile the new file. This is a local-environment limitation (documented
in AGENTS.md §1.3), not caused by this change — the change is a
single, pure test file under
web/__tests__/lib/that no route or appmodule imports, so it cannot affect bundling or output.
Scope
One new file:
web/__tests__/lib/agentvouchUsdc.test.ts. No source, config, ordependency changes.
Rollback
Delete the new test file; nothing else was touched.
Notes
git config user.signingkeyis empty). This matches the precedent of priorcron PRs (chore(web): remove dead EIP-8004 feedback module #191, chore(web): remove dead author dispute helpers #192). If GPG signing is required, re-sign with:
git commit --amend -S --no-edit && git push --force-with-lease.