feat: add mock Horizon and Soroban RPC server for tests - #77
Open
Anichris-koded wants to merge 2 commits into
Open
feat: add mock Horizon and Soroban RPC server for tests#77Anichris-koded wants to merge 2 commits into
Anichris-koded wants to merge 2 commits into
Conversation
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
approved these changes
Aug 24, 2026
|
This has gone into conflict with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Closes #34
Summary
Adds
src/testing/mock-server.ts, a reusable fake Horizon + Soroban RPC server, so tests stop hand-rollingfetchmocks with invented response shapes that drift from what the real servers return.Changes made
src/testing/mock-server.ts—createMockServer()returns a drop-infetchimplementation that serves:GET /accounts/:id→ a realistic Horizon account record (the shape the account loader consumes)POST /(JSON-RPC) →getHealth,getNetwork,getLatestLedger,getEventswith the three Vero contract events (reg,wt_vote,resolved) whose topic XDR decodes through the SDK's own event decoderfailNext(): timeouts (rejects withAbortErrorwhen the caller's signal fires, mirroringRpcClienttimeouts), network rejections, 5xx, and 200s with malformed bodies. Custom routes viahandle(), plus a request log for call-count assertions.horizonAccountFixture,sorobanContractEvent,sorobanEventsResult,scValSymbol, …) based on real Horizon/Soroban response shapes.@vero-protocol/sdk/testingsubpath export inpackage.json; the mock is deliberately not re-exported fromsrc/index.ts, so it never enters the main bundle (npm run size: 2.5 kB, unchanged budget 5 kB).src/__tests__/rpc.test.tsandsrc/account/__tests__/loader.test.tsonto the mock server with no behaviour change, demonstrating the acceptance criterion.src/testing/__tests__/mock-server.test.tsand 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%+ linesnpm run typecheck— no errorsnpm run lint— no errorsnpm run build— CJS + ESM + declarationsnpm run test:package— main entry + testing subpath resolve in both formatsnpm run size— 2.5 kB, within the 5 kB budgetnpm run docs— TypeDoc generates without errorsChecklist
npm testpassesnpm run typecheckreports no errorsnpm run lintreports no errorsCloses #<issue-number>