Add unit tests for stellar.ts; fix build-breaking errors across the codebase - #15
Merged
Conversation
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.
What changed
1. Add test coverage for src/lib/stellar.ts
package.jsonalready had"test": "vitest run"wired up, but therewas no
vitest.config.tsand zero test files anywhere in the repo.Added:
vitest.config.ts— points vitest atsrc/**/*.test.tssrc/lib/stellar.test.ts— 21 unit tests covering the pure,network-free helpers (
getNetworkPassphrase,getHorizonUrl,parseAsset,isValidPublicKey,isValidSecretKey), including thepublic/secret-key-swap case that's an easy mistake for consumers of
this library to make.
2. Fix npm run build (was failing before this PR)
Running the build surfaced a series of pre-existing, unrelated issues:
src/index.ts— raw CSS had been appended after the exports,breaking esbuild's parser. Moved the intended style
(
*:focus-visible) intosrc/styles/index.css.src/components/ui/Field.tsx— a duplicate, unreachable{error && (...)}block was pasted directly insidereturn (,before the root element (invalid JSX). Removed it — the correct
{error && ...}rendering already exists later in the file. Alsofixed two type mismatches: the
valuepassed toAssetInputwascast to a loose shape instead of the real
Assettype, anderror(typed
string | null) needed?? undefinedbefore being passed toAssetInput, which only acceptsstring | undefined.src/components/TransactionBuilder/OperationsStep.tsx— an orphanedfield-validation snippet referenced undefined variables (
fieldDef,newValue,fieldKey) and wasn't wired into any handler; removedit. Also fixed a
Type 'unknown' is not assignable to type 'ReactNode'error by wrappingop.params.destinationinBoolean(...)before the&&.src/lib/stellar.ts— removed an unusedTransactionParamsimport,and fixed a real SDK type mismatch:
Memo.return()'s typedefinition only accepts
string(unlikeMemo.hash(), whichaccepts
string | Buffer), so passingBuffer.from(value, "hex")failed to typecheck. Confirmed against the SDK's runtime
implementation that passing the hex string directly is equivalent.
src/lib/operationDefinitions.ts— twovalidatefunctions(added for the
paymentoperation'sdestinationandamountfields) narrowed their
unknownparameter with!v || ..., whichTypeScript narrows to
{}rather thanstringon the truthybranch — a known TS quirk. Switched to
typeof v !== "string" || ...,which narrows correctly.
import React from "react"(and one unusedXdrImportimport) across several components — the project uses"jsx": "react-jsx", so the default React import isn't needed.Restored named imports (
useEffect,Fragment) where a fileactually used
React.something.Testing
npx vitest run— 21/21 passingnpm run build— CJS, ESM, and DTS all build successfully