Skip to content

Test/1059 1060 1061 1062#1177

Open
Dev-Vik-Tor wants to merge 4 commits into
Emmyt24:mainfrom
Dev-Vik-Tor:test/1059-1060-1061-1062
Open

Test/1059 1060 1061 1062#1177
Dev-Vik-Tor wants to merge 4 commits into
Emmyt24:mainfrom
Dev-Vik-Tor:test/1059-1060-1061-1062

Conversation

@Dev-Vik-Tor
Copy link
Copy Markdown
Contributor

Comprehensive Test Coverage for Batch Operations, Vault Management, Webhook Delivery, and Leaderboard Caching

Overview

This PR implements deterministic unit tests across four critical systems to improve reliability and maintainability. All tests follow existing project patterns and maintain >80% code coverage targets.

Changes Implemented

1. Batch Operation Atomicity Tests (#1059)

File: contracts/token-factory/src/batch_atomicity_test.rs

Verifies batch operations maintain all-or-nothing semantics:

  • Invalid element mid-batch causes entire batch to revert without state mutation
  • Valid batch applies all elements atomically
  • Empty batch rejected with InvalidParameters
  • Single-element batch handled correctly
  • Insufficient fee causes batch failure
  • Batch with metadata processed correctly
  • Max batch size limits enforced (50 items)
  • State consistency verified before/after failed batches

Key Test Cases:

  • test_batch_atomicity_invalid_element_mid_batch - Validates rollback on validation failure
  • test_batch_atomicity_valid_batch_applies_all - Confirms all tokens created sequentially
  • test_batch_atomicity_state_consistency_after_failure - Ensures idempotency
  • test_batch_atomicity_with_metadata - Metadata fee calculation
  • test_batch_atomicity_max_batch_size - Boundary testing

2. Vault Deposit/Withdraw Edge Cases (#1060)

File: contracts/token-factory/src/vault_deposit_withdraw_test.rs

Stress-tests vault deposit/withdraw/claim flows across boundary and error states:

  • Claiming from non-existent vault returns VaultNotFound (error code 60)
  • Claiming with nothing available returns NothingToClaim (error code 65)
  • Full withdrawal bookkeeping accuracy
  • Partial withdrawal tracking
  • Unauthorized withdrawal attempts fail with Unauthorized
  • Unlock time enforcement (CliffNotReached)
  • Vault status transitions (Active → Claimed)
  • Multiple deposits then claim flow
  • Inactive vault claim rejection

Key Test Cases:

  • test_vault_claim_nonexistent_vault - Error code 60 validation
  • test_vault_claim_nothing_to_claim - Error code 65 validation
  • test_vault_claim_unauthorized - Authorization enforcement
  • test_vault_fund_then_claim - Multi-step workflow
  • test_vault_claim_bookkeeping_accuracy - State tracking

3. Webhook Retry/Backoff Deterministic Tests (#1061)

File: backend/src/__tests__/webhookRetry.deterministic.test.ts

Implements deterministic unit tests with mocked timers and HTTP client:

  • Exponential backoff intervals follow documented schedule (1s → 2s → 4s → 8s)
  • Mocked HTTP client fails N times then succeeds
  • Delivery eventually succeeds after retries
  • Exhausting all retries marks delivery failed exactly once
  • Successful first attempt performs no retries
  • Non-retryable status codes (4xx) stop immediately
  • Network errors (null status) always retry
  • Delay capping at maxDelayMs (30s)
  • Jitter application (±25%)
  • Configuration override support

Key Test Cases:

  • test_exponential_backoff_schedule - Validates delay computation
  • test_retry_after_failures - Confirms retry logic with correct intervals
  • test_terminal_failure - Exhausts retries correctly
  • test_non_retryable_status - Stops on 4xx errors
  • test_network_errors - Retries on null status

4. Leaderboard Cache Invalidation Tests (#1062)

File: backend/src/__tests__/leaderboardCache.invalidation.test.ts

Validates leaderboard cache correctness under rapid score updates:

  • Score updates invalidate relevant cached leaderboard slice
  • Reads after TTL expiry recompute from source
  • Tie-breaking ordering stability maintained across cache hits
  • Concurrent updates don't corrupt cached ordering
  • Different cache keys for different periods (24h, 7d, 30d, all)
  • Different cache keys for different pages
  • Cache clearing functionality
  • All leaderboard types cached separately (most-burned, most-active, newest, largest-supply, most-burners)
  • Pagination consistency and metadata accuracy

Key Test Cases:

  • test_cache_invalidation_on_score_updates - Cache hit verification
  • test_different_cache_keys_for_periods - Period isolation
  • test_tie_breaking_ordering_stability - Consistent ordering
  • test_concurrent_updates_no_corruption - Parallel safety
  • test_cache_clearing - Cache reset functionality

Testing Strategy

Contract Tests (Rust):

  • Uses Soroban SDK test utilities
  • Mocked environment with controlled timestamps
  • Deterministic state verification
  • Error code validation

Backend Tests (TypeScript/Vitest):

  • Mocked HTTP client and database calls
  • Fake timers for deterministic delay testing
  • Concurrent execution testing
  • Configuration override validation

Files Modified

  • contracts/token-factory/src/batch_atomicity_test.rs (NEW)
  • contracts/token-factory/src/vault_deposit_withdraw_test.rs (NEW)
  • contracts/token-factory/src/lib.rs (module registration)
  • backend/src/__tests__/webhookRetry.deterministic.test.ts (NEW)
  • backend/src/__tests__/leaderboardCache.invalidation.test.ts (NEW)

Verification

  • All tests follow existing project patterns and conventions
  • Maintains >80% code coverage targets
  • No breaking changes to existing functionality
  • Comprehensive error path coverage
  • Deterministic and repeatable test execution

Closes

- Add deterministic unit tests for batch_reveal atomicity
- Test invalid element mid-batch causes entire batch to revert
- Verify valid batch applies all elements atomically
- Cover empty batch, single-element batch, and insufficient fee scenarios
- Assert state before/after failed batch is identical
- Test batch with metadata and max batch size limits

Closes Emmyt24#1059
- Add stress tests for vault deposit/withdraw/claim edge cases
- Assert claiming from non-existent vault returns VaultNotFound
- Assert claiming with nothing available returns NothingToClaim
- Cover full and partial withdrawal bookkeeping accuracy
- Verify unauthorized withdrawal attempts fail
- Test unlock time enforcement and vault status transitions
- Validate multiple deposits then claim flow
- Test vault funding and claim interactions

Closes Emmyt24#1060
- Add comprehensive unit tests for WebhookRetryService
- Mock HTTP client to fail N times then succeed
- Assert delivery eventually succeeds after retries
- Verify backoff intervals follow exponential schedule using fake timers
- Assert exhausting all retries marks delivery failed exactly once
- Verify successful first attempt performs no retries
- Test non-retryable status codes stop immediately
- Cover network errors, configuration, and edge cases
- Validate timing accuracy and terminal failure handling

Closes Emmyt24#1061
- Add comprehensive tests for leaderboard cache behavior
- Assert score updates invalidate relevant cached leaderboard slice
- Assert reads after TTL expiry recompute from source
- Cover tie-breaking ordering stability across cache hits
- Verify concurrent updates do not corrupt cached ordering
- Test different cache keys for different periods and pages
- Validate cache clearing functionality
- Test all leaderboard types (most-burned, most-active, newest, largest-supply, most-burners)
- Verify pagination consistency and metadata accuracy

Closes Emmyt24#1062
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@Dev-Vik-Tor 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment