Skip to content

Fix: 4 issues (#933, #934, #935, #936) - #1017

Merged
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
temma02:simple/933-934-935-936
Oct 17, 2026
Merged

Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
temma02:simple/933-934-935-936

Conversation

@temma02

@temma02 temma02 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Closes #933
Closes #934
Closes #935
Closes #936

Issues

#933 Test escapeHtml in receipt-utils (XSS safety)

Description

HTML escaping used when generating receipts currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/receipt-utils.ts (escapeHtml, ~line 161)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • escapes & < > " '
  • leaves safe text untouched
  • a stream name like <img src=x onerror=alert(1)> is escaped in the generated receipt

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

#934 Test generateReceiptHTML

Description

Receipt HTML generation currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/receipt-utils.ts (generateReceiptHTML, ~line 176)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • includes stream id, parties, token and amounts
  • formats amounts with token decimals
  • cancelled vs active streams

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

#935 Test custom token storage in lib/stellar.ts

Description

Persisting user-added custom tokens currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/stellar.ts (getCustomTokens, saveCustomToken, ~lines 192–240)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • empty storage → []
  • save then read back
  • no duplicates
  • corrupt JSON handled

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

#936 Test favorite tokens in lib/stellar.ts

Description

Favorite token management currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/stellar.ts (getFavoriteTokens, toggleFavoriteToken, isFavoriteToken, ~lines 241–280)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • toggle on/off
  • isFavoriteToken reflects state
  • persists across reads

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

Summary

Both target test files already exist and are collected by Vitest, so extend them rather than creating new files. escapeHtml in lib/receipt-utils.ts is currently a module-private function (no export); to test it directly you would need to add export — prefer testing it indirectly through generateReceiptHTML to honor the 'no production code changes' acceptance criterion, and note the choice in the PR. lib/stellar.ts uses typeof window === 'undefined' guards, so tests must run in the jsdom environment (Vitest default for this repo) and clear localStorage in beforeEach to avoid cross-test leakage. The custom-token storage key is flowstar:custom-tokens:<network> and the favorites key is flowstar:favorite-tokens; use these exact keys when seeding corrupt JSON. saveCustomToken caps the list at 10 entries — not required by the issues but a useful extra assertion if convenient.

Changes

  • Add tests for escapeHtml and generateReceiptHTML from @/lib/receipt-utils. Import both functions (note: escapeHtml is not currently exported — if it isn't exported, either test it indirectly through generateReceiptHTML or add export to the function; prefer indirect testing to avoid production changes, and note any export change in the PR). Reuse the existing makeStream fixture and buildReceiptData to construct ReceiptData. For escapeHtml (issue Test escapeHtml in receipt-utils (XSS safety) #933): assert each of &, <, >, ", ' is converted to &amp;, &lt;, &gt;, &quot;, &#x27; respectively; assert plain text like 'hello world' is returned unchanged; and build a stream whose id is <img src=x onerror=alert(1)>, generate the HTML, and assert the output contains &lt;img src=x onerror=alert(1)&gt; and does NOT contain the raw <img src=x onerror=alert(1)> tag. For generateReceiptHTML (issue Test generateReceiptHTML #934): build a receipt via buildReceiptData(makeStream(), 'creation-tx', ['withdraw-tx-1'], 'cancel-tx') and assert the HTML contains the stream id (stream-123), sender (GSENDER123), recipient (GRECIPIENT456), token symbol (USDC), and formatted amounts (e.g. 100 for total, 0 for withdrawn, 100 for remaining with 7-decimal token). Add a fixture with a non-round amount (e.g. depositedAmount: 2_500_000_000n → 250) to verify decimal formatting. Add separate active vs cancelled fixtures: assert the active receipt contains status-active and Active, and the cancelled receipt contains status-cancelled and Cancelled (and does not contain status-active). Run npm test to confirm all new tests pass. (tests/lib/receipt-utils.test.ts)
  • Add tests for custom token storage and favorite token management from @/lib/stellar. Import getCustomTokens, saveCustomToken, getFavoriteTokens, toggleFavoriteToken, and isFavoriteToken. Add a top-level beforeEach that clears localStorage (jsdom is available via Vitest) so tests are isolated. For custom tokens (issue Test custom token storage in lib/stellar.ts #935): assert getCustomTokens('testnet') returns [] when storage is empty; call saveCustomToken('testnet', { address: 'CABC', symbol: 'TKN', decimals: 7 }) then getCustomTokens('testnet') and expect the token back; save the same token twice and assert the list length is 1 (no duplicates); write invalid JSON to the key flowstar:custom-tokens:testnet via localStorage.setItem and assert getCustomTokens('testnet') returns [] without throwing. Also verify network isolation (saving on testnet does not appear on mainnet). For favorite tokens (issue Test favorite tokens in lib/stellar.ts #936): assert getFavoriteTokens() returns [] initially and isFavoriteToken('CABC') is false; call toggleFavoriteToken('CABC') and assert isFavoriteToken('CABC') is true and getFavoriteTokens() includes 'CABC'; call toggleFavoriteToken('CABC') again and assert isFavoriteToken('CABC') is false and getFavoriteTokens() no longer includes it; toggle two tokens and re-read getFavoriteTokens() to confirm persistence across reads. Run npm test to confirm all new tests pass. (tests/lib/stellar.test.ts)

Co-authored-by: Simple Agent <agent@simple.dev>
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@temma02 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

@Austinaminu2
Austinaminu2 merged commit 44d93f6 into FlowwStar:main Oct 17, 2026
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