Skip to content

Add comprehensive Vitest unit-test suite for soroban.ts (transaction building, parsing, formatting) #25

Description

@prodbycorne

Problem

src/lib/soroban.ts is the most critical file in the codebase (all contract interactions flow through it) but has zero test coverage. The parsePoolsFromXdr, parseUserPositionFromXdr, and parseCreditsFromXdr stubs, the formatCredits / formatAssetAmount utilities, and the transaction-building logic in lockAssets / unlockAssets are all untested.

Acceptance Criteria

  • __tests__/soroban.test.ts covers at minimum:
    • formatCredits: sub-1000, thousands (K), millions (M)
    • formatLockTime: past timestamp → "Unlockable now"; future timestamps at day/hour/sub-hour granularities
    • formatAssetAmount: native XLM and issued asset formatting
    • parsePoolsFromXdr: a valid ScVec → correct PoolInfo[]; empty vec → []; malformed entry → skipped with warning
    • parseUserPositionFromXdr: valid position map → full UserPosition; null ScValnull
    • parseCreditsFromXdr: i128 stroops → display string conversion
    • Transaction builder helpers: correct Operation.invokeContractFunction args for lock_assets (amount as i128, address as ScAddress)
  • Mocks for @stellar/stellar-sdk RPC methods (simulateTransaction, sendTransaction, getTransaction) are set up with vi.mock so tests run without a live RPC endpoint
  • All tests pass under pnpm vitest run
  • Coverage target: ≥ 80 % line coverage on src/lib/soroban.ts

Relevant Files

  • src/lib/soroban.ts — file under test
  • __tests__/soroban.test.ts — create this file
  • package.json — confirm vitest is already in devDependencies (if not, add it)

Metadata

Metadata

Assignees

Labels

Official CampaignCampaign: Official CampaignhardRequires deep domain knowledge — Soroban, Stellar SDK, or complex statesorobanSoroban smart-contract integration (XDR, RPC, transaction building)testingUnit, integration, or e2e test coverage

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions