Enhanced the Mock Stellar Service to better simulate real Stellar network behavior, improving test reliability and realism.
Network Delays
- Configurable network delay simulation (
networkDelayoption) - Simulates real-world API latency
- Useful for testing loading states and timeouts
Rate Limiting
- Configurable rate limiting (
rateLimitoption) - Tracks requests per second
- Throws realistic rate limit errors
Random Failures
- Configurable failure rate (
failureRateoption) - Simulates various Stellar network errors:
tx_bad_seq: Sequence number mismatchtx_insufficient_balance: Balance errorstx_failed: Network congestiontimeout: Request timeouts
Public Key Validation
- Validates Stellar public key format (G + 55 base32 characters)
- Checks for valid base32 alphabet (A-Z, 2-7)
- Provides clear error messages
Secret Key Validation
- Validates Stellar secret key format (S + 55 base32 characters)
- Checks for valid base32 alphabet
- Prevents invalid key usage
Amount Validation
- Enforces 7 decimal place precision (Stellar standard)
- Validates maximum amount (922337203685.4775807 XLM)
- Checks for positive values
- Provides specific error messages
Business Logic Validation
- Enforces base reserve requirement (1 XLM minimum)
- Prevents same-account transactions
- Validates destination account funding
- Prevents duplicate Friendbot funding
Keypair Generation
- Uses proper base32 alphabet (A-Z, 2-7) instead of hex
- Generates 56-character keys matching Stellar format
- More realistic key appearance
Transaction Details
- Added sequence number tracking
- Added transaction fees (0.0000100 XLM)
- Added confirmation timestamps
- Consistent 7-decimal formatting for amounts
- Status field: "confirmed" (instead of mixed "success"/"confirmed")
Error Messages
- More descriptive and Stellar-specific
- Include context and suggestions
- Match real Horizon API error patterns
new MockStellarService({
networkDelay: 100, // ms delay per operation
failureRate: 0.05, // 5% random failure rate
rateLimit: 10, // 10 requests per second max
minAccountBalance: '1.0000000', // Minimum funded balance
baseReserve: '1.0000000', // Base reserve requirement
strictValidation: true, // Enable/disable validation
})MOCK_STELLAR_GUIDE.md
- Complete feature overview
- Configuration examples
- Usage patterns
- Limitations clearly documented
- Troubleshooting guide
- Best practices for dev/test/CI
- Transition guide to real Stellar
New Test Suites
- Realistic Error Simulation (4 tests)
- Stellar-Specific Validation (7 tests)
- Transaction Details (3 tests)
- Configuration Options (3 tests)
Test Scenarios
- Network delay simulation
- Rate limiting enforcement
- Random failure handling
- Duplicate funding prevention
- Key format validation
- Amount precision validation
- Base reserve enforcement
- Sequence number tracking
- Fee inclusion
- Custom configuration
-
src/services/MockStellarService.js- Added configuration system
- Implemented validation methods
- Enhanced error simulation
- Improved keypair generation
- Added sequence number tracking
-
tests/MockStellarService.test.js- Added 17 new test cases
- Covers all new features
- Tests error scenarios
- Validates configuration options
-
MOCK_STELLAR_GUIDE.md(new)- Comprehensive documentation
- Usage examples
- Limitations clearly stated
- Best practices guide
- Faster iteration with realistic behavior
- Better error handling testing
- Loading state testing with delays
- More confidence before testnet deployment
- Catches edge cases earlier
- Tests realistic failure scenarios
- Validates Stellar-specific requirements
- Improves test coverage
- Code handles real Stellar errors
- Proper validation in place
- Reserve requirements understood
- Smooth transition to real network
✅ Mock behaves closer to real network
- Realistic key generation (base32)
- Proper error messages
- Sequence number tracking
- Fee simulation
- Reserve requirements
✅ Tests catch realistic failures
- Rate limiting
- Network timeouts
- Invalid formats
- Insufficient balance
- Unfunded accounts
- Duplicate operations
✅ Mock limitations documented
- Comprehensive guide created
- Limitations clearly listed
- Transition guide provided
- Best practices documented
const service = new MockStellarService({ networkDelay: 500 });
// All operations now have 500ms delayconst service = new MockStellarService({ failureRate: 0.1 });
// 10% of operations will fail randomlyconst service = new MockStellarService({ rateLimit: 5 });
// Max 5 requests per second- Run full test suite to verify all tests pass
- Update integration tests to use new configuration options
- Consider adding more realistic scenarios:
- Transaction pending states
- Ledger close timing
- Memo validation
- Multi-operation transactions
Run the enhanced tests:
npm test -- MockStellarService.test.jsAll existing tests remain compatible. New tests validate enhanced behavior.