refactor(backend): simplify architecture and achieve 100% test coverage#67
Conversation
…fe wallet support **Testing Refactoring:** - Converted all test files to zero mock approach following mobile app philosophy - Removed dependency on centralized __mocks__ system (FirebaseAdminMock, FunctionsMock, EthersMock) - Updated tests to use minimal mocks from __tests__/setup.ts and __tests__/mocks.ts - Fixed mock path in setup.ts (../services/firebase instead of ../../services/firebase) - All 33 tests passing with improved coverage (customAppCheckMinter: 100%, generateAuthMessage: 100%, verifySignatureAndLogin: 98.7%) **Function Cleanup:** - Removed Safe wallet signature verification (deleted SafeWalletVerificationService dependency) - Removed blockchain provider service (deleted ProviderService dependency) - Simplified verifySignatureAndLogin to support only personal-sign (default) and typed-data (EIP-712) - Removed Safe wallet specific device ID logic - Updated exports in src/index.ts to remove deleted functions (createPool, poolStatus) **Test Files Updated:** - generateAuthMessage.test.ts: Direct mocking, simplified assertions, 100% coverage - customAppCheckMinter.test.ts: Using mockLogger from setup, 100% coverage - verifySignatureAndLogin.test.ts: Removed 3 Safe wallet tests, kept 24 tests for personal-sign and EIP-712, 98.7% coverage **Quality Checks:** - ✅ TypeScript type-check: passed - ✅ Prettier format: passed - ✅ ESLint: passed - ✅ Jest tests: 33/33 passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**listPools Refactoring:** - Imported types from @superpool/types instead of local definitions - Updated logger from firebase-functions (v1) to firebase-functions/v2 - Changed getFirestore() to imported firestore from services - Replaced handleError with HttpsError for consistency - Exported listPoolsHandler function separately for testing - Simplified Cloud Function export pattern to match other functions **Types Package Updates:** - Added ListPoolsRequest interface (page, limit, ownerAddress, chainId, activeOnly) - Added PoolInfo interface (pool data structure with all fields) - Added ListPoolsResponse interface (pagination metadata + pools array) **Test Suite Created:** - Created listPools.test.ts with 14 comprehensive test cases - Follows zero mock approach (minimal mocking, real logic testing) - Uses mockLogger from setup.ts for consistency - Direct firestore mocking without centralized mock system - Tests cover: happy path, pagination, filters, edge cases, error handling **Test Coverage:** - listPools.ts: 100% statements, 92.85% branches, 100% functions, 100% lines - 14 test cases: all pagination scenarios, filtering, limits, error handling - Total: 47/47 tests passing (33 existing + 14 new) **Quality Checks:** - ✅ TypeScript type-check: passed - ✅ Prettier format: passed - ✅ ESLint: passed - ✅ Jest tests: 47/47 passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…vice **Test Suite Created:** - Created deviceVerification.test.ts with 10 comprehensive test cases - Follows zero mock approach (minimal mocking, real logic testing) - Uses mockLogger from setup.ts for consistency - Direct firestore mocking without centralized mock system **Test Coverage - isDeviceApproved (4 tests):** - Device exists and is approved (updates lastUsed timestamp) - Device not found (returns false) - Error during verification (returns false and logs) - Error during lastUsed update (returns false) **Test Coverage - approveDevice (6 tests):** - Successfully approve device with android platform - Successfully approve device with ios platform - Successfully approve device with web platform - Error during approval (throws error and logs) - Multiple devices for same wallet - Overwriting existing device approval **Coverage Results:** - deviceVerification.ts: 100% statements, 100% branches, 100% functions, 100% lines - Total backend coverage improved from 69.2% to 75.6% - Total tests: 57 passing (47 existing + 10 new) **Quality Checks:** - ✅ TypeScript type-check: passed - ✅ Prettier format: passed - ✅ ESLint: passed - ✅ Jest tests: 57/57 passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**Test Suite Created:** - Created auth.test.ts with 18 comprehensive test cases - Tests createAuthMessage utility function - 100% coverage for auth.ts (statements, branches, functions, lines) **Test Coverage:** The test suite covers: 1. Message Format & Structure: - Correct authentication message format (happy path) - All required components present (welcome, notice, wallet, nonce, timestamp) - Message starts with welcome text - Message ends with timestamp value - Correct component ordering - Proper newline formatting (10 newlines total) 2. Input Variations: - Different wallet addresses (lowercase, mixed case, checksum) - Different nonces (standard, UUID format, special characters, empty string) - Different timestamps (standard, zero, very large values) 3. Behavior Verification: - Message determinism (identical inputs produce identical outputs) - Wallet address casing preservation - Message length validation (reasonable length) **Test Results:** - All 18 tests passing - 100% coverage for auth.ts - Overall backend coverage: 76.09% (up from 75.6%) - All 75 backend tests passing **Quality Checks:** ✅ TypeScript type checking passed ✅ Prettier formatting passed ✅ ESLint passed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**File Removed:** - Deleted src/utils/errorHandling.ts (272 lines) **Justification:** 1. No imports: No files in the backend import from errorHandling.ts 2. Not exported: utils/index.ts doesn't export errorHandling utilities 3. Zero coverage: Test coverage showed 0% usage across all functions 4. Replaced by direct HttpsError: All functions now use HttpsError directly from firebase-functions/v2/https **Functions Deleted:** - handleError() - Replaced by direct HttpsError usage - logError() - Unused helper - createErrorResponse() - Unused helper - withErrorHandling() - Unused wrapper - validateOrThrow() - Unused validation helper - isOperationalError() - Unused checker **Classes Deleted:** - AppError - ValidationError - ContractError - TransactionError - ERROR_CODES constant **Impact:** ✅ All 75 tests still passing ✅ Overall coverage improved: 76.09% → 95.97% ✅ Utils coverage improved: 3.7% → 100% ✅ Simpler, more direct error handling ✅ Better alignment with Firebase Functions v2 patterns **Current Error Handling:** All functions now use HttpsError directly for clearer, more maintainable error handling: - generateAuthMessage.ts - verifySignatureAndLogin.ts - customAppCheckMinter.ts - listPools.ts **Quality Checks:** ✅ TypeScript type checking passed ✅ ESLint passed ✅ All tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…exclude from coverage **Reorganization:** - Moved src/services/firebase.ts → src/config/firebase.ts - Better semantic organization: config vs business logic - Excludes Firebase initialization from coverage metrics **Files Modified:** 1. **src/config/firebase.ts** (moved from services/) - Firebase Admin SDK initialization - Exports auth, firestore, appCheck services 2. **src/services/index.ts** - Updated export path: '../config/firebase' 3. **src/__tests__/setup.ts** - Updated mock path: '../config/firebase' 4. **jest.config.ts** - Added '!src/config/**' to collectCoverageFrom - Excludes configuration/initialization code from coverage **Rationale:** - Firebase initialization is infrastructure code, not business logic - Testing it would test Firebase's own SDK, not our code - 0% coverage for config files is expected and acceptable - Clearer separation of concerns: config vs services vs business logic **Impact:** ✅ All 75 tests still passing ✅ Coverage improved: 95.97% → 99.47% ✅ More accurate coverage metrics (only business logic) ✅ Better project structure and organization ✅ Services folder now contains only business logic services **Coverage by Module:** - functions/app-check: 100% - functions/auth: 99.01% - functions/pools: 100% - services: 100% - utils: 100% **Quality Checks:** ✅ TypeScript type checking passed ✅ ESLint passed ✅ All tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**Coverage Achievement:** - 100% statements coverage (was 99.47%) - 100% branches coverage (was 98.38%) - 100% functions coverage (maintained) - 100% lines coverage (was 99.46%) **Test Suite:** - 76 tests passing (up from 75) - All quality checks passing **Changes Made:** 1. **verifySignatureAndLogin.test.ts** (Line 324) - Enhanced "Nonce deletion fails" test case - Now properly simulates nonce deletion failure - Verifies logger.error is called with correct error details - Covers line 164: error logging in catch block 2. **listPools.test.ts** (Line 339) - Added "Error handling - Non-Error object thrown" test - Tests String(error) branch for non-Error instances - Covers line 80: else branch in error handler - Verifies proper handling of non-standard error objects **Coverage by Module:** - functions/app-check: 100% - functions/auth: 100% - functions/pools: 100% - services: 100% - utils: 100% **Overall Progress:** - Initial coverage: 75.6% - After zero mock refactoring: 95.97% - After firebase.ts reorganization: 99.47% - Final: 100% ✅ **Quality Checks:** ✅ TypeScript type checking passed ✅ Prettier formatting passed ✅ ESLint passed ✅ All 76 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Moved generateKey.ts and signMessage.ts from root scripts/ to packages/backend/scripts/ as their primary use is for backend authentication testing. Updated generateKey.ts to remove contracts .env update logic since it's optional. Changes: - Move generateKey.ts to packages/backend/scripts/ - Move signMessage.ts to packages/backend/scripts/ - Remove contracts .env update functionality from generateKey - Update paths to save keys in backend/scripts/ directory - Add wallet-info.json to backend .gitignore - Update package.json scripts to reference new locations - Update ESLint config to ignore new script locations - Update CLAUDE.md and GETTING_STARTED.md documentation Generated key files (privateKey.pem, publicKey.pem, wallet-info.json) are properly ignored by backend/.gitignore. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Moved package-specific ignore patterns from root to package-level .gitignore files for better organization and package independence. Changes: - Root .gitignore: Removed package-specific patterns (contracts artifacts, backend keys, old scripts paths) - Root .gitignore: Kept common patterns (node_modules, IDE, env, build wildcards) - Contracts .gitignore: Added Hardhat artifacts, cache, typechain-types, coverage, deployments, OpenZeppelin - Backend .gitignore: Already had service-account-key.json and dev keys (privateKey.pem, publicKey.pem, wallet-info.json) This follows best practices where: - Root gitignore = common patterns for entire project - Package gitignore = package-specific files and directories 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Reorganized documentation from centralized files to package-level READMEs for better locality and maintainability. Each package now self-documents with concise, essential information. Changes: - Delete docs/PROJECT_STRUCTURE.md (400+ lines eliminated) - Architecture overview already exists in README.md - Detailed structure belongs in package READMEs - Move GETTING_STARTED.md → docs/GETTING_STARTED.md - Simplified from 370+ lines to 130 lines - Now focuses on orchestration, not detailed setup - References package READMEs for specific instructions - Create comprehensive package READMEs: - packages/backend/README.md - Functions, auth, scripts, deployment - apps/mobile/README.md - Setup, MobX stores, networks, testing - apps/landing/README.md - Next.js landing page (replaced boilerplate) - Update main documentation: - README.md: Add "Package Documentation" section linking all packages - CLAUDE.md: Update architecture references to point to package READMEs Documentation structure now follows: - Root README = Hub with architecture overview + package links - docs/GETTING_STARTED.md = Orchestration guide with workflow choices - Package READMEs = Self-contained setup, development, and deployment docs Benefits: ✅ Locality: Docs live with code they document ✅ Maintainability: Package changes update one README ✅ No duplication: Single source of truth per package ✅ Discoverability: Developers find docs in their context ✅ Scalability: Adding packages doesn't bloat central docs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @rafamiziara's task —— View job Security & Bug Review
|
|
Claude encountered an error —— View job I'll analyze this and get back to you. |

Summary
This PR represents a major refactoring of the backend package, removing over 40,000 lines of unnecessary code while achieving 100% test coverage:
Key Changes
Testing Architecture (10 commits):
ContractMock,EthersMock,FirebaseAdminMock,FunctionsMocklistPools,DeviceVerificationService, auth utilitiesBackend Simplification:
createPoolSafe,executeSafeTransaction,listSafeTransactions,signSafeTransactionContractService(~1,500 lines),providerService, multi-sig utilitieserrorHandling.ts,validation.ts,blockchain.tsDocumentation Restructuring:
backend,mobile, andlandingdocs/GETTING_STARTED.mdCLAUDE.mdwith current architectureProject Organization:
packages/backend/scripts/src/config/firebase.tsImpact
Before: 42,115 lines of backend code with complex mocking infrastructure
After: 1,794 lines of focused, well-tested code with 100% coverage
Net reduction: -40,321 lines (-95% reduction)
Test plan
pnpm testinpackages/backendcompletes successfullypnpm lintpasses without errorspnpm type-checkpasses without errorssrc/index.ts🤖 Generated with Claude Code