Skip to content

Add unit tests for stellar.ts; fix build-breaking errors across the codebase - #15

Merged
cokehill merged 1 commit into
mainfrom
test/stellar-lib-unit-tests
Jul 12, 2026
Merged

Add unit tests for stellar.ts; fix build-breaking errors across the codebase#15
cokehill merged 1 commit into
mainfrom
test/stellar-lib-unit-tests

Conversation

@cokehill

Copy link
Copy Markdown
Contributor

What changed

1. Add test coverage for src/lib/stellar.ts

package.json already had "test": "vitest run" wired up, but there
was no vitest.config.ts and zero test files anywhere in the repo.
Added:

  • vitest.config.ts — points vitest at src/**/*.test.ts
  • src/lib/stellar.test.ts — 21 unit tests covering the pure,
    network-free helpers (getNetworkPassphrase, getHorizonUrl,
    parseAsset, isValidPublicKey, isValidSecretKey), including the
    public/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) into src/styles/index.css.
  • src/components/ui/Field.tsx — a duplicate, unreachable
    {error && (...)} block was pasted directly inside return (,
    before the root element (invalid JSX). Removed it — the correct
    {error && ...} rendering already exists later in the file. Also
    fixed two type mismatches: the value passed to AssetInput was
    cast to a loose shape instead of the real Asset type, and error
    (typed string | null) needed ?? undefined before being passed to
    AssetInput, which only accepts string | undefined.
  • src/components/TransactionBuilder/OperationsStep.tsx — an orphaned
    field-validation snippet referenced undefined variables (fieldDef,
    newValue, fieldKey) and wasn't wired into any handler; removed
    it. Also fixed a Type 'unknown' is not assignable to type 'ReactNode' error by wrapping op.params.destination in
    Boolean(...) before the &&.
  • src/lib/stellar.ts — removed an unused TransactionParams import,
    and fixed a real SDK type mismatch: Memo.return()'s type
    definition only accepts string (unlike Memo.hash(), which
    accepts string | Buffer), so passing Buffer.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 — two validate functions
    (added for the payment operation's destination and amount
    fields) narrowed their unknown parameter with !v || ..., which
    TypeScript narrows to {} rather than string on the truthy
    branch — a known TS quirk. Switched to typeof v !== "string" || ...,
    which narrows correctly.
  • Removed unused import React from "react" (and one unused
    XdrImport import) across several components — the project uses
    "jsx": "react-jsx", so the default React import isn't needed.
    Restored named imports (useEffect, Fragment) where a file
    actually used React.something.

Testing

  • npx vitest run — 21/21 passing
  • npm run build — CJS, ESM, and DTS all build successfully

@cokehill
cokehill merged commit ec78e32 into main Jul 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant