Overview
Salud uses a multi-layered testing approach to ensure reliability and security across the frontend, backend, and smart contracts.Testing Philosophy
Quality Standards
- Smart Contracts: Comprehensive test coverage (security-critical)
- Backend: API endpoint validation and error handling
- Frontend: Build verification and linting
- Integration: Manual end-to-end testing
Test Pyramid
Smart Contract Testing
The Leo smart contract has the most comprehensive test suite with 17 automated tests.Running Contract Tests
Test Coverage
The contract test suite (tests/test_salud_health_records.leo) covers:
Record Creation Tests
test_create_record
test_create_record
Verifies basic record creation with valid inputs.Tests:
- Record is created successfully
- Owner is set to caller
- Data fields are stored correctly
- Record type is valid
test_record_types
test_record_types
Validates all 10 record type categories.Record Types Tested:
- General Health
- Laboratory Results
- Prescriptions
- Imaging/Radiology
- Vaccination Records
- Surgical Records
- Mental Health
- Dental Records
- Vision/Ophthalmology
- Other/Miscellaneous
test_invalid_record_type
test_invalid_record_type
Ensures invalid record types (0, 11+) are rejected.Expects: Assertion failure for out-of-range types
Record ID Tests
test_record_id_uniqueness
test_record_id_uniqueness
Verifies that different inputs produce unique record IDs.Tests:
- Different data → different IDs
- Different nonces → different IDs
- Different patients → different IDs
test_record_id_determinism
test_record_id_determinism
Confirms same inputs always produce same ID.Tests:
- Same patient + data + nonce = same ID
- Useful for client-side ID computation
Access Grant Tests
test_grant_access
test_grant_access
Tests basic access grant creation.Verifies:
- Access token is generated
- Grant is stored in mapping
- Patient retains record ownership
test_access_token_generation
test_access_token_generation
Validates access token uniqueness.Tests:
- Different doctors → different tokens
- Different nonces → different tokens
- Same inputs → same token (deterministic)
test_duration_bounds
test_duration_bounds
Checks duration clamping to valid ranges.Tests:
- Minimum: 240 blocks (~1 hour)
- Maximum: 40,320 blocks (~7 days)
- Out-of-range values are clamped
Access Verification Tests
test_verify_valid_access
test_verify_valid_access
Tests successful verification with valid token.Flow:
- Create record
- Grant access to doctor
- Verify access succeeds
test_verify_invalid_token
test_verify_invalid_token
Ensures fake tokens are rejected.Tests:
- Random token → verification fails
- Wrong token for record → fails
test_verify_wrong_doctor
test_verify_wrong_doctor
Prevents access by unauthorized doctors.Scenario:
- Grant to Doctor A
- Doctor B tries to access
- Verification fails
test_verify_wrong_record
test_verify_wrong_record
Ensures tokens are record-specific.Scenario:
- Token for Record A
- Used on Record B
- Verification fails
Revocation Tests
test_revoke_access
test_revoke_access
Tests immediate access revocation.Flow:
- Grant access
- Revoke access
- Verification fails
- Access info shows
is_revoked: true
test_full_flow
test_full_flow
End-to-end integration test.Complete Flow:
- Patient creates record
- Patient grants access to doctor
- Doctor verifies access (succeeds)
- Patient revokes access
- Doctor verification fails
Helper Function Tests
test_compute_record_id
test_compute_record_id
Validates client-side ID computation helper.Purpose: Allows frontend to predict record IDs
test_get_access_info
test_get_access_info
Tests public access info retrieval.Returns:
- Patient address
- Doctor address
- Record ID
- Expiration time
- Revocation status
Writing New Contract Tests
Example test structure:- Test one thing per test function
- Use descriptive function names
- Add comments explaining what’s being tested
- Test both success and failure cases
- Verify security constraints
Backend Testing
The backend uses manual testing and verification.Running Backend Tests
Backend Test Checklist
Manual API Testing with Postman
Collection Setup:- Base URL:
http://localhost:3001 - Headers:
Content-Type: application/json
- Health Check
- Generate Wallet
- Create Record
Frontend Testing
The frontend focuses on build verification and code quality.Running Frontend Tests
Frontend Test Checklist
Manual UI Testing
Test on Multiple Browsers:- Chrome/Edge
- Safari
- Firefox
- Mobile Safari
- Mobile Chrome
- Wallet connection
- QR code camera access
- LocalStorage persistence
- Console errors
Integration Testing
End-to-End User Flows
Patient Creates Record
Test Flow:
- Open app at
http://localhost:5173 - Connect wallet (or generate new)
- Click “New Record” button
- Enter medical data
- Submit record
- Verify success message
- See record in list
Patient Shares Record
Test Flow:
- Click “Share” on a record
- Enter doctor address (or use default duration)
- QR code displays
- Verify expiration countdown shows
- Screenshot QR code for doctor test
Doctor Scans and Views
Test Flow:
- Navigate to
/doctorroute - Connect doctor wallet
- Click “Scan QR Code”
- Grant camera permission
- Scan patient’s QR code
- View decrypted record
- Verify expiration timer
Cross-Platform Testing
Device Matrix:| Device | OS | Browser | Priority |
|---|---|---|---|
| iPhone 12+ | iOS 15+ | Safari | High |
| iPhone 12+ | iOS 15+ | Chrome | Medium |
| Android | 11+ | Chrome | High |
| Desktop | macOS | Chrome/Safari | High |
| Desktop | Windows | Chrome/Edge | High |
| Desktop | Linux | Firefox | Medium |
Testing Best Practices
Before Committing
Manual Testing
- Test the feature you changed
- Test related features
- Check for console errors
- Verify mobile responsive (if UI change)
Before Pull Request
Continuous Testing
During Development
Frontend (with HMR):Test Data
Demo Mode Test Data
Sample Private Keys (Testnet Only):Debugging Tests
Contract Test Failures
Backend Issues
Frontend Issues
Next Steps
Contributing Guide
Learn how to submit tested contributions
Local Setup
Set up your testing environment
Architecture
Understand what you’re testing
API Reference
Test API endpoints comprehensively