feat(sdk): integration tests for DistributorClient against local Soroban#266
Conversation
…l#182) Replaces the minimal stub in test-utils/mockRpcServer.ts with a fully-typed, reusable mock that covers every Soroban RPC method used by the SDK. Tests no longer depend on any network connection. Changes: - Expand mockRpcServer.ts to mock all 9 RPC methods: getAccount, simulateTransaction, sendTransaction, getTransaction, getNetwork, getLatestLedger, getLedger, getFeeStats, getEvents - Add 12 pre-canned scenario helpers (rpc.scenarios.*) for the most common test situations (success, pendingThenSuccess, simulationError, transactionFailed, accountNotFound, networkError, etc.) - Intercept both @stellar/stellar-sdk/rpc and @stellar/stellar-sdk import paths via vi.mock() so all SDK modules are covered - Add resetMockRpcServer() that clears call history and return values for clean test isolation in beforeEach - Add mockRpcServer.test.ts with 49 tests covering the mock contract - Fix missing mockTxNone helper in DistributorClient.test.ts and PaymentStreamClient.test.ts (caused ReferenceError at runtime) Closes Fundable-Protocol#182
…Fundable-Protocol#181) Enhances BalanceWatcher with the full feature set described in issue Fundable-Protocol#181: New capabilities: - watchStream(stream, callback) — subscribes to both sender and recipient of a payment stream in a single call; returns a single unsub function that tears down both subscriptions - fetchBalances(pairs) — bulk-fetches multiple address/token pairs in parallel; failures are captured per-pair instead of aborting the batch - getLastKnownBalance(address, token) — reads the cached balance from the last successful poll without making any RPC call - onError option — replaces the silent console.error with a typed callback so callers control error handling - unwatch(address, token, callback) — explicit unsubscribe method in addition to the returned unsub closure Improvements to existing behaviour: - Polling errors for one pair no longer silently swallow; they route to onError (or console.error as fallback) while other pairs keep polling - start() guards against duplicate intervals (idempotent) - stop() is idempotent — calling it when already stopped does not throw - void operator on pollBalances() call to satisfy no-floating-promises Tests (BalanceWatcher.test.ts) — expanded from 11 to 54 tests covering: - fetchBalance: happy path, zero balance, i128 max, error response, no result, non-bigint retval, network rejection, passphrase caching - fetchBalances: all pairs succeed, per-pair error capture, empty input - getLastKnownBalance: before poll, after poll, after clear, multi-poll - watch/unwatch: change detection, no-change suppression, multiple callbacks, multi-pair independence, update shape validation - watchStream: sender + recipient registration, per-party callbacks, unsubscribe clears both, correct token forwarding - onError: invocation, correct args, handler throws safely, per-pair isolation (error in one pair does not block others) - Lifecycle: isActive, start/stop/clear, idempotency, interval timing Closes Fundable-Protocol#181
…ban (Fundable-Protocol#180) Implements a complete integration test suite for DistributorClient that verifies every public method against a live contract deployed on a local Soroban node. Tests are excluded from the standard unit-test run and triggered via `pnpm test:integration`. Changes: DistributorClient.integration.test.ts (complete rewrite): - beforeAll: funds 6 accounts in parallel, deploys distributor contract, deploys SAC token, mints token supply to sender, initializes contract - suiteReady flag + skipIfUnavailable() guards every test so the suite degrades gracefully when no local node is running - initialize: verifies admin address, total distributions = 0, total distributed amount = 0 on a fresh contract - stats before distributions: getUserStats undefined for fresh address, getTokenStats undefined for unused token - distributeEqual: increments total distributions, increments total distributed amount by exact value, updates sender user stats, updates token stats, single recipient, three recipients - distributeWeighted: increments total distributions, increments total distributed amount by sum of amounts, skewed 99/1 split - getDistributionHistory: non-empty after distributions, entry shape validation, limit=1, pagination with startId, object-style overload - setProtocolFee: admin succeeds, object-style overload, non-admin rejects with error - getAdmin: returns correct admin address - getUserStats: undefined for fresh address, positive distributions_initiated, positive total_amount for active sender - getTokenStats: undefined for unused token, positive distribution_count and total_amount for used token - re-initialization guard: second initialize rejects setup.ts: - Add mintTokens() helper — calls `stellar contract invoke ... mint` via stellar-cli to give test accounts spendable token balances - Fix keypairSigner() return type: now returns { signedTxXdr } object (correct shape for AssembledTransaction.signAndSend) instead of bare string Closes Fundable-Protocol#180
|
Warning Review limit reached
More reviews will be available in 44 minutes and 30 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@mandyslovestories-sudo 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! 🚀 |
Summary
Closes #180
Implements a complete integration test suite for
DistributorClientthat exercises every public method against a live contract deployed on a local Soroban node. Tests are excluded from the standardpnpm testrun and triggered viapnpm test:integration(already configured invitest.integration.config.ts).Changes
src/__integration_tests__/DistributorClient.integration.test.ts(complete rewrite)Setup (
beforeAll):stellar-cliDIST) and mints supply to the sender accountsuiteReadyflag so individual tests skip cleanly when no local node is runningTest coverage (38 tests across 10 describe blocks):
initializestats before distributionsgetUserStatsundefined for unused address,getTokenStatsundefined for unused tokendistributeEqualdistributeWeightedgetDistributionHistorystartId, object-style overloadsetProtocolFeegetAdmingetUserStatsdistributions_initiated, positivetotal_amountgetTokenStatsdistribution_countandtotal_amountre-initialization guardinitializecall rejectssrc/__integration_tests__/setup.tsNew
mintTokens()helper:Calls
stellar contract invoke ... mintso test accounts have spendable token balances before distribution tests run.Bug fix —
keypairSigner()return type:The function previously returned a bare
string.AssembledTransaction.signAndSendexpects{ signedTxXdr: string }. This is now corrected, fixing a latent bug that would have caused all integration tests (both PaymentStream and Distributor) to fail at the signing step.How to run
Tests skip gracefully with a console warning when the local node is not reachable — the standard
pnpm testrun is unaffected.