Skip to content

Add Stellar DEX source integration tests with mocked Horizon#60

Open
Jennylila wants to merge 1 commit into
SmartDropLabs:mainfrom
Jennylila:fix/stellar-dex-tests
Open

Add Stellar DEX source integration tests with mocked Horizon#60
Jennylila wants to merge 1 commit into
SmartDropLabs:mainfrom
Jennylila:fix/stellar-dex-tests

Conversation

@Jennylila

Copy link
Copy Markdown
Contributor

Overview

This PR adds integration tests for src/services/sources/stellarDex.js with a mocked Horizon client so orderbook price derivation can be verified without real network calls. It also updates the Stellar DEX source to use midpoint pricing and propagate Horizon errors as required by the test scenarios.

Related Issue

Closes #33

Changes

📈 Stellar DEX Price Derivation

  • [MODIFY] src/services/sources/stellarDex.js
  • Added derivePriceFromOrderbook() to compute prices from Horizon orderbook data.
  • Returns the midpoint of best ask and best bid when both sides are present.
  • Falls back to best bid only when asks are empty, or best ask only when bids are empty.
  • Returns null gracefully when both sides are empty.
  • Propagates Horizon non-200 and timeout errors instead of swallowing them.
  • Uses the correct native XLM orderbook pair when no issuer is provided.

🧪 Stellar DEX Integration Tests

  • [ADD] test/stellarDex.test.js
  • Mocks stellar-sdk Server with Jest (no real Horizon calls).
  • Covers all seven scenarios from the issue:
    • Normal orderbook (asks + bids)
    • Empty asks array
    • Empty bids array
    • Both empty
    • Horizon non-200 response
    • Horizon timeout
    • XLM/native asset (no issuer)
  • Asserts midpoint calculation precisely (0.115 from ask 0.12 and bid 0.11).
  • Verifies mocked requests complete in under 100ms.

Verification Results

npm test -- test/stellarDex.test.js --coverage --collectCoverageFrom='src/services/sources/stellarDex.js' ✅ passed (8/8)
Acceptance Criteria Status
All 7 scenarios have passing tests
Midpoint calculation asserted precisely (not just truthy)
Empty orderbook returns null gracefully
Horizon mock used — no real network calls
Tests run in < 100ms
Code coverage for stellarDex.js ≥ 90% ✅ (100% statements/lines/functions)

Implement midpoint orderbook price derivation and cover all seven Horizon scenarios with Jest mocks so regressions in price logic are caught without network calls.
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.

Add Stellar DEX source integration tests with mocked Horizon

1 participant