Skip to content

[Testing] Zero test coverage for useStellarWallet hook — wallet creation, import, and balance refresh #68

Description

@cybermax4200

Why this matters now: useStellarWallet.ts handles all wallet operations: Freighter connection, Lobstr deep-link connection, in-app wallet creation, wallet import, balance refresh, and disconnection. It's the primary interface between the app and the Stellar blockchain. A bug here could prevent users from connecting wallets, lose funds on import, or show stale balances.

Problem / What: src/hooks/useStellarWallet.ts (233 lines) — no test file. The hook has five wallet operations, two balance refresh functions, error handling with setIsConnecting/setError state, and integration with stellar.ts, lobstr.ts, and walletVault.ts.

Key Challenges:

  • Mock stellar.ts functions: createTestnetAccount, getBalance, getTokenBalance, isValidSecretKey, getPublicKeyFromSecret.
  • Mock lobstr.ts: isLobstrInstalled, openLobstrForSigning.
  • Mock walletVault.ts: saveInAppSecret, clearInAppSecret.
  • Mock useWalletStore Zustand store.
  • Test: connectFreighter — success, extension not found, not connected.
  • Test: connectLobstr — success, not installed, signing cancelled.
  • Test: createInAppWallet — success, network failure.
  • Test: importWallet — valid key, invalid key.
  • Test: disconnectWallet — clears vault and store.
  • Test: refreshBalance — success, network failure.

Acceptance Criteria:

  • Test file src/__tests__/useStellarWallet.test.ts with 15+ test cases.
  • All five wallet operations covered.
  • Error scenarios for each operation.
  • Balance refresh with mocked Horizon responses.
  • Disconnect clears vault entry.
  • All tests pass with npm test.

Relevant files/functions:

  • src/hooks/useStellarWallet.ts (entire file)
  • src/__tests__/useStellarWallet.test.ts (new)

Out of scope: Real Stellar network interaction tests.

Labels: testing, advanced, wallet

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions