Repository navigation
test(wallet): cover truncateAddress edge cases - #11
Merged
Miracle656 merged 2 commits intoSep 6, 2026
Merged
Conversation
truncateAddress had two tests covering a C-address, a short input and an empty string. Adds the G-address case the issue asks for plus the boundaries that were unpinned: an input exactly as long as the elision, one character past it, a nullish address reaching the `|| ''` guard, the 6/6 defaults, and custom head/tail lengths. Also asserts both ends survive truncation and that two addresses sharing a 49-character prefix still render differently, so a head-only regression cannot pass. Verified by mutation: dropping the tail fails 7 tests, changing `<=` to `<` fails 1, removing the nullish guard fails 1, and altering the 6/6 defaults fails 4. Tests only; lib/nfts.ts is unchanged.
lib/__tests__/feeBump.test.ts has been failing to load with "ReferenceError: TextEncoder is not defined", taking the wallet suite to 20/21. The suite mocks @stellar/stellar-sdk, but the failing import arrives through lib/fees -> @veil/sdk -> sdk/src/core.ts, which resolves a different physical copy of the package (sdk/node_modules, or the repo root when that is absent). Jest keys mocks by resolved path, so the mock covers the wallet's copy only and the real bundle loads, reaching for TextEncoder at module scope. jsdom does not define it. Polyfills TextEncoder/TextDecoder from node:util in setupFiles, which runs before modules load. Not moduleNameMapper: the note at jest.config.js:18 records that forcing a single copy breaks jsdom's browser-field resolution. Verified 21/21 suites and 260 tests both with and without sdk/node_modules present, since the two shapes resolve different copies.
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.
Closes #7
Two commits, readable separately: the tests, then a jest fix the acceptance criteria needed.
1.
truncateAddresscoverageThe helper is
truncateAddressinfrontend/wallet/lib/nfts.ts. It already had two tests covering a C-address, a short input and an empty string, so this fills in what was missing: the G-address case the issue names, plus the boundaries that were unpinned.Added 8 tests (22 → 30 in that suite):
GAAAAA…AAAWLT|| ''guard and returns'', which is what happens when an API payload omits the fieldVerified by mutation, since tests that only pass prove nothing. Breaking the helper four ways:
<=→<at the boundary6,6→4,8The two caught by exactly one test each are caught only by tests added here.
lib/nfts.tsis byte-identical; no network calls, the suite already mocksfetch.2.
TextEncoderpolyfillnpm testcould not be green before this:lib/__tests__/feeBump.test.tswas failing to load withReferenceError: TextEncoder is not defined, holding the suite at 20/21.The suite does mock
@stellar/stellar-sdk, but the failing import arrives throughlib/fees→@veil/sdk→sdk/src/core.ts, which resolves a different physical copy of the package (sdk/node_modules, or the repo root when that is absent). Jest keys mocks by resolved path, so the mock covers the wallet's copy only, the real bundle loads, and it reaches forTextEncoderat module scope. jsdom does not define it.Fixed with a 3-line
jest.setup.jspolyfillingTextEncoder/TextDecoderfromnode:util, wired throughsetupFiles(which runs before modules load, unlike the already-present emptysetupFilesAfterEnv).Deliberately not
moduleNameMapper: the note atjest.config.js:18-22records that forcing a single copy breaks jsdom's browser-field resolution.How tested
npm testinfrontend/wallet: 21/21 suites, 260 tests, up from 20/21 and 259.sdk/node_modulespresent, since those two shapes resolve different copies of stellar-sdk. Green in both.npm run typecheckinfrontend/walletclean.Not tested: nothing on a device, and nothing in a browser. This change is test-only.
Notes
The wallet's jest suite does not run in CI. Parsing
ci.yml, the only jobs invoking tests aresdk(npm test --if-present) andmobile(npm test). Bothfrontend/walletjobs are typecheck/build and Lighthouse. That is presumably why a fully broken suite went unnoticed, and it means these tests will not be enforced on future PRs either. I leftci.ymlalone since adding a job is your call on cost and scope, but happy to send that as a one-step follow-up if you want it.Smaller thing, unrelated to this diff: the wallet UI truncates addresses inline as
.slice(0, 6)….slice(-6)in about nine places (dashboard,send,agent,activity,token/[code],AppShell,TxPreviewCard) at three different widths, rather than calling this helper. Consolidating ontotruncateAddresswould make these tests cover the real UI rather than just the NFT page, but it touches far more files than this issue, so I have not done it here.