Skip to content

feat(stellar): add Horizon mock server and fix pool sequence resync & tests. - #1890

Merged
sublime247 merged 1 commit into
sublime247:mainfrom
ShantelPeters:feat/horizon-mock-and-pool-resync
Aug 29, 2026
Merged

feat(stellar): add Horizon mock server and fix pool sequence resync & tests.#1890
sublime247 merged 1 commit into
sublime247:mainfrom
ShantelPeters:feat/horizon-mock-and-pool-resync

Conversation

@ShantelPeters

Copy link
Copy Markdown
Contributor

🚀 Summary of Changes

This PR introduces an in-memory Horizon Mock Server with configurable chaos/outage controls, adds end-to-end integration tests for Horizon node failover & outage recovery, fixes sequence resynchronization in the Stellar Channel Account Pool, and resolves test suite suite dependencies across SEP-12 KYC & trustline modules.

🛠️ Key Improvements & Features

1. 🌐 Mock Horizon Server (src/mocks/horizonMockServer.ts & scripts/horizon-mock-server.ts)

  • Full Horizon API Simulation: Implements Express handlers for core Horizon REST endpoints (/, /health, /accounts/:id, /accounts/:id/transactions, /transactions, /fee_stats, /paths/strict-receive, /ledgers).
  • Chaos Engineering & Outage Controls: Supports dynamic outage modes (503_service_unavailable, 500_internal_error, 429_rate_limit, timeout, flaky, offline), latency injection (delayMs), and Retry-After header simulations.
  • CLI Command: Added npm run horizon-mock:dev to run the standalone mock server locally for development.

2. 🛡️ Network Outage & Failover Integration (src/stellar/__tests__/horizonOutage.test.ts)

  • Added integration test coverage verifying HorizonPool automatic failover across nodes during 503 Service Unavailable, 500 Internal Error, and 429 Rate Limit conditions.
  • Updated HorizonPool (src/stellar/horizonPool.ts) to allow HTTP URLs when running tests or in development (allowHttp).

3. 🔄 Channel Account Pool Sequence Resync Fix (src/stellar/pool.ts)

  • Fixed submitWithChannel to update local account.sequence = newSeq upon detecting sequence mismatches (tx_bad_seq), ensuring retry attempts use the updated sequence number.
  • Removed redundant duplicate sequence error checks in submitTransaction.

4. 🔑 SEP-12 Rate Limiting & UserModel Integration (src/middleware/rateLimit.ts & src/stellar/sep12.ts)

  • Updated sep12RateLimiter key resolution to fallback to query/body account parameters or client IP when requests are unauthenticated.
  • Updated Express route handlers in sep12.ts to preserve AppError.statusCode for proper HTTP 400 validation error responses.
  • Mocked UserModel in sep12.test.ts to prevent database lockups during unit testing.

5. 🧪 Unit Test Normalization (src/stellar/__tests__/)

  • Fixed StellarSdk.Account mock instantiations in trustlines.test.ts and payments.test.ts.
  • Updated limit format expectations for ChangeTrust operations (1000.0000000, 0.0000000) matching StellarSdk 7-decimal string normalization.

🧪 Verification & Testing

Automated Test Results

  • All 12 Stellar Test Suites: 186 / 186 tests passed (100%)
  • Horizon Mock Tests: 15 / 15 tests passed (100%)
  • TypeScript Build: npm run build (tsc) compiled cleanly with 0 errors.
# Run Horizon Mock tests
npx jest src/mocks/tests/horizonMockServer.test.ts
# Run all Stellar test suites
npx jest src/stellar/__tests__/
# Build project
npm run build


CLOSES #1835 

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@ShantelPeters Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@sublime247
sublime247 merged commit a40b5eb into sublime247:main Aug 29, 2026
14 of 23 checks passed
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.

2 participants