Skip to content

test: add comprehensive unit tests for usePathPayment - strict-send and strict-receive modes#1

Open
believetimothy wants to merge 2 commits into
mainfrom
usepathpayment-test
Open

test: add comprehensive unit tests for usePathPayment - strict-send and strict-receive modes#1
believetimothy wants to merge 2 commits into
mainfrom
usepathpayment-test

Conversation

@believetimothy

Copy link
Copy Markdown
Owner

Summary

Adds 13 new unit tests to usePathPayment.test.ts, expanding coverage from 8 to 21 tests. The new tests cover both strict-send and strict-receive modes with better asset resolution, Horizon/Stellar SDK interaction verification, and edge case handling.

Changes

New Strict-Send Tests

  • Credit send asset resolution — verifies new Asset(code, issuer) is called for credit-type send assets
  • Native destination asset — verifies Asset.native() is called for native-type dest assets
  • Default empty path — confirms an empty array is passed when no path option is provided
  • Horizon Server creation — validates server is created with config.horizonUrl
  • TransactionBuilder params — checks fee and networkPassphrase are forwarded correctly
  • Custom timeoutSeconds — ensures custom timeout flows through
  • Source account loading — verifies loadAccount is called with the correct publicKey
  • Builder chaining — confirms addOperation and setTimeout are invoked on the TransactionBuilder
  • reset() delegation — verifies reset delegates to useTransaction
  • Null publicKey error — properly tests the hook throws when Freighter is disconnected (using mutable mock via vi.hoisted)
  • Credit send to native dest parameter mapping — validates sendAmount and destMin with mixed asset types

New Strict-Receive Tests

  • sendMax / destAmount mapping — confirms sendAmount maps to sendMax and destMin maps to destAmount
  • Credit to credit path — validates parameter mapping for credit send and credit dest
  • Native to native path — validates parameter mapping with both assets as native

Infrastructure

  • Used vi.hoisted to create a mutable publicKey mock, avoiding hoisting issues with inline vi.mock calls inside test bodies

Test Plan

 ✓ src/__tests__/usePathPayment.test.ts  (21 tests)
Test Files  1 passed (1)
Tests  21 passed (21)

Closes dark-princezz#141

…l hooks

Add a new validation utility module (src/utils/validation.ts) that wraps
StrKey from @stellar/stellar-sdk to validate Stellar public keys (G...)
and Soroban contract IDs (C...). Validators throw descriptive
ValidationError messages on invalid input.

Hooks updated with public key validation:
- useStellarAccount – validates publicKey before Horizon fetch
- useStellarOffers – validates publicKey before Horizon fetch
- useClaimableBalances – validates publicKey before Horizon fetch
- usePayment – validates destination and asset.issuer (credit assets)
- usePathPayment – validates destination, sendAsset.issuer, destAsset.issuer
- useStellarTransaction – validates feeBump.sponsor address

Hooks updated with contract ID validation:
- useSorobanContract – validates contractId in call() and simulate()
- useSorobanTokenBalance – validates contractId and accountAddress
- useContractEvents – validates contractId in fetchEvents()

Test mocks updated to expose StrKey validation functions.

Closes dark-princezz#189
believetimothy pushed a commit that referenced this pull request Jun 24, 2026
feat: implement useMultiSig() — build and collect multi-signature transactions
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.

test: add unit tests for usePathPayment - strict-send and strict-receive

1 participant