test: add unit tests for SorobanService and mock Stellar RPC#24
Conversation
ogazboiz
left a comment
There was a problem hiding this comment.
nice work here. this is exactly what issue #18 asked for and the suite is genuinely high quality, not box-ticking. the esm setup is done right: both jest.unstable_mockModule calls come before the dynamic await import of sorobanService, and the stellar config mock exports all three functions the service actually imports, so nothing leaks to a real rpc. the score fallback tests are the highlight, you separate missing-score, transient-retry and hard-error by asserting the simulateTransaction call count (1 vs 2) and the exact warn logs, which is the only way those branches are actually verifiable. submitSignedTx success/no-hash/non-success-poll and validateScoreConfig invalid deltas are all covered too. i ran it locally: 37/37 new tests pass, full suite stays green at 247 passing, and tsc build plus typecheck both pass.
one thing to fix before merge: the healthcheck timer cleanup is a good catch, but removing the as Promise<any> cast left the Promise.race array formatted across multiple lines, and prettier now wants it collapsed. that makes npm run format:check fail and shows up as the single lint error at sorobanService.ts:671. just run npm run format (or npm run lint:fix) and recommit. while you are there, the unused AppError import at the top of the test file can be dropped.
none of that touches the substance, the tests and the timer fix are both solid. fix the formatting and this is good to go.
if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
|
Thank you for the kind words on the test quality! It was a pleasure working on this issue. Let me know if there's anything else you'd like to work on! |
ogazboiz
left a comment
There was a problem hiding this comment.
the formatting is sorted now, npx prettier --check . is clean and the unused AppError import is gone. the test suite is the same high quality it was the first time around: the esm mocks are declared before the dynamic import of sorobanService, all three stellar config functions are mocked so nothing hits a real rpc, and the score-fallback branches are verified by asserting the simulateTransaction call counts. ran it locally, 37/37 new tests pass and the full suite stays green, tsc build and typecheck both clean. merging this, thanks for the solid work.
if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
Description
This PR introduces comprehensive unit test coverage for the core Stellar/Soroban service operations in
src/services/sorobanService.tsand configures mock tests around the Stellar network environment configuration (src/config/stellar.ts).This pr closes #18
Key Changes
New Unit Tests (
src/__tests__/sorobanService.test.ts):buildRequestLoanTx,buildRepayTx,buildDepositTx,buildWithdrawTx, andbuildApproveLoanTx) invoke the contract function simulation correctly and prepare transaction XDRs.AppError.internal.Timer Leak Resolution (
src/services/sorobanService.ts):healthCheck()to explicitly track thesetTimeoutidentifier and clear the timer in afinallyblock, resolving an open handle leak that previously caused Jest to hang.Documentation improvement (
src/config/stellar.ts):createSorobanRpcServer().Verification & Testing
npm run typecheck).npm run lint).