Skip to content

test: add comprehensive test suites for batch operations atomicity, timeout/error handling, currency conversion accuracy, and webhook signature verification (#1042-#1045) - #1149

Merged
Kingsman-99 merged 1 commit into
Stellar-split:mainfrom
hartz0:test/batch-timeout-currency-webhook-1042-1045
Oct 19, 2026

Conversation

@hartz0

@hartz0 hartz0 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

What this fixes

This PR adds comprehensive test coverage for four critical SDK core systems:

  1. Test batch operations atomicity #1045 - Test batch operations atomicity: There was missing dedicated test coverage verifying that batch operations guarantee atomicity across successful transactions, partial failures, rollback coordination, and consistency invariants.
  2. Test timeout and error handling #1044 - Test timeout and error handling: There was missing comprehensive test coverage for request timeout enforcement, per-method overrides, network error classification/recovery with exponential backoff, XDR/JSON parse errors, and input validation with recovery.
  3. Test currency conversion accuracy #1043 - Test currency conversion accuracy: There was missing test validation for oracle price conversion accuracy (fixed-point 18-decimal scaling), multi-asset precision preservation across custom decimals, largest-remainder split rounding calculations, and numerical edge cases.
  4. Test webhook signature verification #1042 - Test webhook signature verification: There was missing end-to-end test verification for HMAC-SHA256 signature verification, rejection of tampered/mismatched payloads, timestamp tolerance replay protection, and LRU nonce tracking deduplication.

What changed

  • Batch Operations Atomicity (Test batch operations atomicity #1045):

    • Added dedicated test suite test/batchOperationsAtomicity.test.ts (13 tests) covering:
      • Multi-leg split payment coordination when all legs succeed.
      • Concurrency-limited invoice batch processing via InvoiceBatchProcessor.
      • Partial failure isolation where failed legs are identified without aborting remaining operations.
      • Rollback snapshot initiation with RollbackCoordinator emitting splitRollbackInitiated and splitRollbackCompleted events.
      • Rollback timeout cleanup ensuring no orphaned state remains on execution timeout.
      • LIFO rollback order and idempotent rollback in OptimisticCache.
      • Exact split amount balance conservation (zero stroops created or lost).
    • Initialized eventHandlers and expiries in OptimisticCache (src/cache/OptimisticCache.ts) to ensure clean cache lifecycle event dispatch during rollback.
  • Timeout and Error Handling (Test timeout and error handling #1044):

    • Added dedicated test suite test/timeoutAndErrorHandling.test.ts (17 tests) covering:
      • withTimeout and withTimeoutOrThrow triggering RequestTimeoutError with method context and cancellation via AbortSignal.
      • TimeoutManager per-method timeout overrides and default fallback configuration.
      • Pre-deadline escalation warning dispatch via EscalationManager.
      • Error classification with isRetryable (transient 503, 429, ECONNREFUSED vs non-retryable 400, 404, InvoiceNotFoundError).
      • Transient network failure retry recovery via executeWithRetry.
      • Secondary RPC recovery via FallbackChain.
      • Malformed base64 XDR envelope parse failure handling via parseEnvelope.
      • JSON and hex decoding validation with descriptive error context.
      • Parameter validation recovery on ValidationError.
  • Currency Conversion Accuracy (Test currency conversion accuracy #1043):

    • Added dedicated test suite test/currencyConversionAccuracy.test.ts (19 tests) covering:
      • Accurate 18-decimal fixed-point oracle rate conversions (rate > 1.0, fractional rate < 1.0, and 1:1 parity).
      • convertFiatToAsset fiat-to-token conversions and rejection of non-positive exchange rates with OraclePriceError.
      • Lossless 7-decimal XLM stroop precision in normalizeAmount and toOnChainAmount.
      • Custom token precisions (6 decimals for USDC, 2 for fiat, 0 for integer units).
      • Rejection of fractional values exceeding asset precision with PrecisionError.
      • Hamilton-Hare largest-remainder method in auditSplitRounding ensuring exact sum preservation.
      • Detection of invalid ratio divergence via RoundingOverflowError.
      • Extreme numerical edge cases: 0 amounts, 1 stroop, and 100-billion-token BigInts.
  • Webhook Signature Verification (Test webhook signature verification #1042):

    • Added dedicated test suite test/webhookSignatureVerification.test.ts (22 tests) covering:
      • Valid HMAC-SHA256 signature computation and verification across string and Buffer bodies.
      • Signature prefix handling (sha256= and hmac-sha256=).
      • Event emission on verification (webhook.validated and webhook.rejected).
      • Raw verification via webhooks/verify.ts and webhookValidator.ts.
      • Constant-time comparison via safeCompare preventing timing attacks.
      • Rejection of mismatched secrets, tampered bodies, tampered signature bytes, and malformed hex.
      • Replay protection with timestamp tolerance windows and clock skew tolerance.
      • Replay attack detection via nonce tracking and deduplication.
      • LRU capacity eviction and retrieval in RingBufferStore for webhook replay.

Testing

Ran all newly created and default test suites using Vitest:

  • test/batchOperationsAtomicity.test.ts (13 passed)
  • test/timeoutAndErrorHandling.test.ts (17 passed)
  • test/currencyConversionAccuracy.test.ts (19 passed)
  • test/webhookSignatureVerification.test.ts (22 passed)
  • npm test (test/client.test.ts, test/retryPolicy.test.ts, test/network-environment.test.ts) (110 passed)
    Total: 7 test files, 181 tests passed, 0 failures.

Issues

closes #1045
closes #1044
closes #1043
closes #1042

…rrency conversion, and webhook verification (Stellar-split#1042-Stellar-split#1045)

- Add batch operations atomicity test suite covering success batch, partial failure, rollback coordination, and consistency invariants (Stellar-split#1045)
- Add timeout and error handling test suite covering request timeouts, network error classification/recovery, XDR/JSON parse errors, and validation (Stellar-split#1044)
- Add currency conversion accuracy test suite covering oracle price calculations, multi-asset precision preservation, split rounding auditor, and numerical edge cases (Stellar-split#1043)
- Add webhook signature verification test suite covering HMAC-SHA256 digests, invalid signature rejection, replay protection, and nonce tracking (Stellar-split#1042)
- Initialize eventHandlers and expiries in OptimisticCache to support cache lifecycle events during rollback
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@hartz0 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

@Kingsman-99
Kingsman-99 merged commit 24cdb81 into Stellar-split:main Oct 19, 2026
@grantfox-oss grantfox-oss Bot mentioned this pull request Oct 19, 2026
5 tasks
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.

Test batch operations atomicity Test timeout and error handling Test currency conversion accuracy Test webhook signature verification

2 participants