Skip to content

feat: add mock Horizon and Soroban RPC server for tests - #77

Open
Anichris-koded wants to merge 2 commits into
Vero-protocol:mainfrom
Anichris-koded:test/issue-34-mock-rpc-server
Open

feat: add mock Horizon and Soroban RPC server for tests#77
Anichris-koded wants to merge 2 commits into
Vero-protocol:mainfrom
Anichris-koded:test/issue-34-mock-rpc-server

Conversation

@Anichris-koded

Copy link
Copy Markdown

Related issue

Closes #34

Summary

Adds src/testing/mock-server.ts, a reusable fake Horizon + Soroban RPC server, so tests stop hand-rolling fetch mocks with invented response shapes that drift from what the real servers return.

Changes made

  • src/testing/mock-server.tscreateMockServer() returns a drop-in fetch implementation that serves:
    • GET /accounts/:id → a realistic Horizon account record (the shape the account loader consumes)
    • POST / (JSON-RPC) → getHealth, getNetwork, getLatestLedger, getEvents with the three Vero contract events (reg, wt_vote, resolved) whose topic XDR decodes through the SDK's own event decoder
    • anything else → a Horizon problem-details 404
  • Scriptable failures via failNext(): timeouts (rejects with AbortError when the caller's signal fires, mirroring RpcClient timeouts), network rejections, 5xx, and 200s with malformed bodies. Custom routes via handle(), plus a request log for call-count assertions.
  • Fixtures (horizonAccountFixture, sorobanContractEvent, sorobanEventsResult, scValSymbol, …) based on real Horizon/Soroban response shapes.
  • @vero-protocol/sdk/testing subpath export in package.json; the mock is deliberately not re-exported from src/index.ts, so it never enters the main bundle (npm run size: 2.5 kB, unchanged budget 5 kB).
  • Migrated src/__tests__/rpc.test.ts and src/account/__tests__/loader.test.ts onto the mock server with no behaviour change, demonstrating the acceptance criterion.
  • Added src/testing/__tests__/mock-server.test.ts and extended the package smoke test to verify the testing subpath resolves in both CJS and ESM.

Testing performed

  • npm test — 186 tests pass (12 suites)
  • npm run test:coverage — thresholds met; mock-server.ts at 95%+ lines
  • npm run typecheck — no errors
  • npm run lint — no errors
  • npm run build — CJS + ESM + declarations
  • npm run test:package — main entry + testing subpath resolve in both formats
  • npm run size — 2.5 kB, within the 5 kB budget
  • npm run docs — TypeDoc generates without errors

Checklist

  • npm test passes
  • npm run typecheck reports no errors
  • npm run lint reports no errors
  • PR description links the resolved issue with Closes #<issue-number>

Tests hand-rolled fetch mocks per file, and each module reinvented the
same Horizon account body and Soroban JSON-RPC envelope with shapes that
drifted from what the real servers return. Add src/testing/mock-server.ts
as the single place that produces realistic responses:

- GET /accounts/:id returns a real-shaped Horizon account record
- POST / (JSON-RPC) answers getHealth, getNetwork, getLatestLedger,
  getEvents with decodable Vero contract events
- failures are scriptable per request: timeouts (abort-based), network
  rejections, 5xx, and 200s with malformed bodies
- fixtures are based on real response shapes and align with the SDK's
  own event decoder

Exported under the @vero-protocol/sdk/testing subpath so consumers can
use it too, and deliberately excluded from the main entry point (the
bundle-size check confirms the main build is unaffected). The RPC and
account-loader tests now use it instead of hand-rolled mocks.

Closes Vero-protocol#34
@N-i-xx

N-i-xx commented Aug 24, 2026

Copy link
Copy Markdown

This has gone into conflict with main since it was opened — could you rebase onto main and resolve? Checks were green otherwise.

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 a mock Horizon and Soroban RPC server for tests

2 participants