Skip to content

Latest commit

 

History

History
194 lines (145 loc) · 5.41 KB

File metadata and controls

194 lines (145 loc) · 5.41 KB

B-013 PR Readiness Checklist

✅ Implementation Complete

Core Changes

  • walletService.ts - Enhanced with placeholder detection and validation

    • isPlaceholderAddress() function to detect common patterns
    • ensureWalletForUser() validates before persisting
    • assertUserWalletAddress() validates on read (defense in depth)
    • setStellarAddressForUser() new safe entry point for external addresses
  • Database Migration - 20260426000000_add_stellar_address_validation

    • Pre-flight validation (fails if invalid data exists)
    • CHECK constraint enforcing valid format
    • Performance index on stellar_address
  • Validation Script - scripts/validate_stellar_addresses.sql

    • SQL script to check existing data
    • Can be run before applying migration
  • Schema Documentation - Added comments to schema.prisma

  • Documentation - B-013_FIX_SUMMARY.md with complete details


🧪 Testing Checklist

Manual Testing Required

  • Run validation script against your database:

    psql -U your_user -d your_db -f scripts/validate_stellar_addresses.sql
    • Should return 0 invalid addresses
    • If invalid addresses found, fix them before deploying
  • Test wallet creation flow:

    1. Create new user account
    2. Sign in (triggers wallet creation)
    3. Verify stellar address is valid 56-char G-address
    4. Verify address is NOT a placeholder pattern
  • Test signin with existing user:

    1. Sign in with existing user
    2. Verify stellar_address is returned correctly
    3. No validation errors should occur
  • Test transfer operations:

    1. Initiate transfer
    2. Verify assertUserWalletAddress() validates correctly
    3. No false positives or negatives

📋 Before Submitting PR

1. Validate Existing Data

# Run this against your production/staging database
psql -U your_user -d your_db -f scripts/validate_stellar_addresses.sql

Expected Output:

  • invalid_address_count = 0
  • List of invalid addresses should be EMPTY

If Invalid Addresses Found:

-- Option 1: Clear invalid addresses
UPDATE users SET stellar_address = NULL WHERE id = 'user-id';

-- Option 2: Replace with valid address (if user has real wallet)
UPDATE users SET stellar_address = 'GVALID...' WHERE id = 'user-id';

2. Test Migration Locally

# Ensure database is running
npx prisma migrate deploy

# Should succeed without errors

3. Build Check

npm run build
# or
pnpm run build

Should compile without TypeScript errors.


🚀 Deployment Steps

Step 1: Pre-Deployment

  1. Run validation script on production database
  2. Fix any invalid addresses found
  3. Confirm invalid_address_count = 0

Step 2: Deploy Migration

npx prisma migrate deploy

Step 3: Deploy Application

npm run build
npm start
# or your deployment method

Step 4: Post-Deployment Monitoring

  • Monitor logs for: "Invalid stellar address format in database"
  • Watch for wallet creation failures
  • Check transfer operations work correctly

📝 PR Description Template

## B-013: Fix Placeholder/Invalid Stellar Address Prevention

### Problem
Non-G placeholder addresses could break downstream Stellar validation and UX. No database constraint prevented invalid addresses from being stored.

### Solution
**Defense in Depth Strategy:**
1. Application-level validation with placeholder detection
2. Database CHECK constraint enforcing valid format
3. Validation on read to catch any corrupted data
4. Comprehensive logging for debugging

### Changes
- `src/services/wallet/walletService.ts` - Enhanced validation
- `prisma/migrations/20260426000000_add_stellar_address_validation/migration.sql` - DB constraint
- `scripts/validate_stellar_addresses.sql` - Pre-deployment validation
- `prisma/schema.prisma` - Documentation

### Acceptance Criteria
✅ No user row ships with invalid stellarAddress format in prod
✅ Placeholder addresses rejected at app and DB levels
✅ Existing data validated before constraint application
✅ Proper error logging for debugging

### Testing
- [ ] Validation script run on target database (0 invalid addresses)
- [ ] Wallet creation flow tested
- [ ] Signin flow tested
- [ ] Transfer operations tested

### Deployment Notes
⚠️ MUST run `scripts/validate_stellar_addresses.sql` before applying migration
⚠️ Fix any invalid addresses before deployment

⚠️ Important Notes

Can You Submit PR?

YES, the implementation is complete and ready for PR submission!

However, Before Deploying to Production:

  1. MUST run validation script on your database
  2. MUST fix any invalid addresses found
  3. SHOULD test locally with your database
  4. SHOULD run test suite (if available)

What's Working:

  • ✅ Code implementation complete
  • ✅ Database migration created
  • ✅ Validation scripts provided
  • ✅ Documentation comprehensive
  • ✅ Defense in depth implemented

What You Need to Do:

  • ⚠️ Validate your existing database has no invalid addresses
  • ⚠️ Test the changes with your specific setup
  • ⚠️ Run your test suite to ensure no regressions

🎯 Summary

Implementation Status: ✅ COMPLETE

Ready for PR: ✅ YES

Ready for Production: ⚠️ After validating existing data

The code is production-ready and follows best practices. Just ensure your existing data is clean before deploying the migration!