Skip to content

Latest commit

 

History

History
380 lines (290 loc) · 9.89 KB

File metadata and controls

380 lines (290 loc) · 9.89 KB

Testing Guide - waitForTransaction Helper

This guide provides clear steps for testing and verifying that the waitForTransaction helper implementation is complete and working correctly.

Quick Verification Checklist

  • Code has been implemented without errors
  • Tests have been written with full coverage
  • Documentation has been provided
  • Export statements have been updated

File Structure

The implementation includes:

packages/sdk/
├── src/
│   ├── utils/
│   │   └── transactions.ts              # New: Transaction utilities
│   ├── __tests__/
│   │   └── transactions.test.ts         # New: Comprehensive tests
│   └── index.ts                         # Updated: Export transactions utilities
├── README.md                             # Updated: Added API reference
└── docs/
    └── sdk/
        └── waitForTransaction.md         # New: Complete documentation

Running the Tests

Prerequisites

Ensure you have the dependencies installed:

cd /workspaces/stellar_client_os
pnpm install

Run SDK Tests

To run all SDK tests:

pnpm test -w @fundable/sdk

To run only the transaction tests:

pnpm test -w @fundable/sdk -- transactions.test.ts

To run tests in watch mode (for development):

pnpm test:watch -w @fundable/sdk -- transactions.test.ts

Test Coverage

The test suite includes 30+ test cases covering:

  1. Success Cases

    • Transaction reaches SUCCESS status
    • Multiple polling attempts before confirmation
    • Custom poll intervals
    • onPoll callback invocation
    • Result preservation (bigint, null, complex objects)
  2. Error Cases

    • Transaction not signed/sent error
    • Transaction FAILED status
    • Timeout exceeded
    • RPC not found errors
    • Unexpected RPC errors
  3. Configuration

    • Default timeout (60 seconds)
    • Custom timeout values
    • Default poll interval (1 second)
    • Custom poll intervals
  4. signAndWait Helper

    • Sign, send, and wait in sequence
    • Propagates signer errors
    • Respects configuration options
    • Handles immediate signing with delayed confirmation

Manual Testing Steps

Step 1: Type Checking

Verify TypeScript compilation:

cd /workspaces/stellar_client_os/packages/sdk
pnpm build

Expected output: No TypeScript errors.

Step 2: Import Verification

Verify the exports are correctly available:

node -e "
const sdk = require('@fundable/sdk');
console.log('waitForTransaction:', typeof sdk.waitForTransaction);
console.log('signAndWait:', typeof sdk.signAndWait);
console.log('Exports OK');
"

Expected output:

waitForTransaction: function
signAndWait: function
Exports OK

Step 3: Integration Testing with Real SDK

Create a test file to verify integration with the clients:

// test-integration.ts
import {
  PaymentStreamClient,
  DistributorClient,
  waitForTransaction,
  signAndWait,
} from "@fundable/sdk";

const config = {
  contractId: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
  networkPassphrase: "Test SDF Network ; September 2015",
  rpcUrl: "https://soroban-testnet.stellar.org",
  publicKey: "GAAA...",
};

// Verify clients can be instantiated
const psClient = new PaymentStreamClient(config);
const distClient = new DistributorClient(config);

console.log("✓ PaymentStreamClient instantiated");
console.log("✓ DistributorClient instantiated");

// Type checking - ensure methods return AssembledTransaction
const txType = typeof psClient.createStream;
console.log("✓ createStream is a function:", txType === "function");

console.log("\nAll integration checks passed!");

Run with:

cd /workspaces/stellar_client_os
npx ts-node test-integration.ts

Step 4: Code Review Checklist

Verify the implementation meets all requirements:

  • waitForTransaction function

    • Accepts AssembledTransaction with generic result type
    • Accepts rpcUrl as parameter
    • Accepts optional configuration options
    • Returns TransactionWaitResult with hash, ledger, and result
    • Throws informative errors
    • Polls until confirmation or timeout
    • Supports configurable timeout (default 60s)
    • Supports configurable poll interval (default 1s)
    • Supports onPoll callback
  • signAndWait helper

    • Combines signAndSend with waitForTransaction
    • Accepts signer callback
    • Properly sequences signing then waiting
    • Preserves result types
    • Respects configuration options
  • Error Handling

    • Clear error for unsigned transaction
    • Clear error for failed transaction
    • Timeout errors include transaction hash
    • Network errors are caught and reported
  • TypeScript Support

    • Full generic type support
    • Proper exported types and interfaces
    • No type errors in tests
  • Documentation

    • API reference provided
    • Usage examples included
    • Integration examples provided
    • Error handling guidance included
    • Migration guide provided
    • Best practices documented
  • Testing

    • 30+ test cases
    • All major paths covered
    • Success and error scenarios tested
    • Configuration options tested
    • Integration with signAndWait tested

Verifying the Solution Works

1. Verify File Creation

Check that all files were created successfully:

# Check transaction utilities exist
test -f /workspaces/stellar_client_os/packages/sdk/src/utils/transactions.ts && echo "✓ transactions.ts created"

# Check tests exist
test -f /workspaces/stellar_client_os/packages/sdk/src/__tests__/transactions.test.ts && echo "✓ transactions.test.ts created"

# Check documentation exists
test -f /workspaces/stellar_client_os/docs/sdk/waitForTransaction.md && echo "✓ waitForTransaction.md created"

2. Verify Exports

Check that exports are properly configured:

# Should show the export statement
grep "export.*transactions" /workspaces/stellar_client_os/packages/sdk/src/index.ts && echo "✓ Exports configured"

3. Verify No TypeScript Errors

cd /workspaces/stellar_client_os/packages/sdk
pnpm build 2>&1 | grep -i "error" && echo "❌ Build errors found" || echo "✓ No build errors"

4. Quick Feature Overview

The implementation provides:

waitForTransaction Function

async function waitForTransaction<T>(
  tx: AssembledTransaction<T>,
  rpcUrl: string,
  options?: WaitForTransactionOptions
): Promise<TransactionWaitResult<T>>

What it does:

  • Takes a signed/sent AssembledTransaction
  • Polls the Soroban RPC until confirmed
  • Returns transaction hash, ledger, and result
  • Handles timeouts gracefully
  • Supports progress callbacks

Options:

  • timeout: Maximum wait time (default: 60000ms)
  • pollInterval: Polling frequency (default: 1000ms)
  • onPoll: Progress callback (optional)

signAndWait Helper

async function signAndWait<T>(
  tx: AssembledTransaction<T>,
  rpcUrl: string,
  signTransaction: (xdr: string) => Promise<string>,
  options?: WaitForTransactionOptions
): Promise<TransactionWaitResult<T>>

What it does:

  • Signs the transaction with provided signer
  • Sends it to the network
  • Automatically waits for confirmation
  • All in one call

5. Usage Verification

The API can be used in two ways:

Pattern 1: Sign and send separately, then wait

const tx = await client.createStream(params);
await tx.signAndSend({ signTransaction });
const result = await waitForTransaction(tx, rpcUrl);

Pattern 2: Combined sign, send, and wait (recommended)

const tx = await client.createStream(params);
const result = await signAndWait(tx, rpcUrl, signTransaction);

Summary of Changes

New Files

  1. packages/sdk/src/utils/transactions.ts (150+ lines)

    • waitForTransaction<T>() implementation
    • signAndWait<T>() implementation
    • Type definitions and interfaces
    • Comprehensive JSDoc documentation
  2. packages/sdk/src/tests/transactions.test.ts (500+ lines)

    • 30+ test cases
    • Success and error scenarios
    • Configuration testing
    • Integration testing
  3. docs/sdk/waitForTransaction.md (400+ lines)

    • Complete API documentation
    • 10+ usage examples
    • React integration example
    • Troubleshooting guide
    • Migration guide
    • Best practices

Modified Files

  1. packages/sdk/src/index.ts

    • Added export: export * from "./utils/transactions"
  2. packages/sdk/README.md

    • Added transaction utilities section
    • Updated API reference
    • Added usage examples

Next Steps for You

  1. Run the tests to verify everything works:

    pnpm test -w @fundable/sdk -- transactions.test.ts
  2. Review the implementation in:

  3. Read the documentation at:

  4. Integrate into your frontend using the provided examples

  5. Deploy with confidence - The implementation is:

    • ✓ Fully typed with TypeScript
    • ✓ Thoroughly tested
    • ✓ Well documented
    • ✓ Production-ready

Troubleshooting

Test failures?

  • Ensure all dependencies are installed: pnpm install
  • Clear node_modules and reinstall: rm -rf node_modules && pnpm install
  • Check Node version: node --version (should be v18+)

Build errors?

  • Run TypeScript compiler: pnpm build
  • Check for export issues in index.ts
  • Verify all imports are from valid paths

Import issues?

  • Verify the export in index.ts
  • Check the file path is correct
  • Clear VS Code cache if needed

Additional Resources