|
| 1 | +# Testing & Quality Assurance |
| 2 | + |
| 3 | +This guide documents SoroScan's testing strategy across the backend, frontend, contracts, and end-to-end workflows. |
| 4 | + |
| 5 | +## Testing Strategy Overview |
| 6 | + |
| 7 | +- Testing pyramid: unit tests for fast validation, integration tests for subsystem behavior, end-to-end tests for full workflows. |
| 8 | +- Coverage goals: use targeted coverage metrics for critical business logic and key API surfaces. |
| 9 | +- Test data management: prefer fixtures, factories, and isolated database state. |
| 10 | +- Mocking and stubbing: mock external services and blockchain RPC responses while keeping contract and integration tests realistic. |
| 11 | + |
| 12 | +## Backend Testing Guide (Django) |
| 13 | + |
| 14 | +- Unit tests for models, views, serializers, helpers, and custom validators. |
| 15 | +- Integration tests for database-backed behavior and REST/GraphQL endpoints. |
| 16 | +- Celery task testing for webhook dispatch, retry behavior, and background ingestion. |
| 17 | +- `pytest` fixtures for reusable database state, authentication, and API clients. |
| 18 | + |
| 19 | +Example `pytest` unit test: |
| 20 | + |
| 21 | +```python |
| 22 | +from django.urls import reverse |
| 23 | +from rest_framework import status |
| 24 | + |
| 25 | +from soroscan.ingest.models import Event |
| 26 | + |
| 27 | + |
| 28 | +def test_event_serializer_creates_event(api_client, event_data): |
| 29 | + url = reverse('event-list') |
| 30 | + response = api_client.post(url, event_data) |
| 31 | + |
| 32 | + assert response.status_code == status.HTTP_201_CREATED |
| 33 | + assert Event.objects.filter(tx_hash=event_data['tx_hash']).exists() |
| 34 | +``` |
| 35 | + |
| 36 | +Example fixture structure: |
| 37 | + |
| 38 | +```python |
| 39 | +import pytest |
| 40 | +from django.contrib.auth.models import User |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def api_client(client, django_user_model): |
| 44 | + user = django_user_model.objects.create_user('tester', 'tester@example.com', 'pass') |
| 45 | + client.force_login(user) |
| 46 | + return client |
| 47 | +``` |
| 48 | + |
| 49 | +## Frontend Testing Guide (Next.js / React) |
| 50 | + |
| 51 | +- Component testing with React Testing Library. |
| 52 | +- Hook testing for custom hooks and Apollo Client integration. |
| 53 | +- Page-level integration testing for component interactions and navigation. |
| 54 | +- MSW setup for mocking GraphQL and REST requests. |
| 55 | +- Jest configuration for snapshot testing and code coverage. |
| 56 | + |
| 57 | +Example component test: |
| 58 | + |
| 59 | +```tsx |
| 60 | +import { render, screen } from '@testing-library/react'; |
| 61 | +import userEvent from '@testing-library/user-event'; |
| 62 | +import EventCard from '@/components/EventCard'; |
| 63 | + |
| 64 | +it('renders event fields and responds to click', async () => { |
| 65 | + render(<EventCard event={{ id: '1', name: 'Transfer', block: 123 }} />); |
| 66 | + |
| 67 | + expect(screen.getByText('Transfer')).toBeInTheDocument(); |
| 68 | + await userEvent.click(screen.getByRole('button', { name: /details/i })); |
| 69 | + expect(screen.getByText(/block 123/i)).toBeVisible(); |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +## Contract Testing Guide (Rust) |
| 74 | + |
| 75 | +- Soroban contract unit tests for business logic and edge cases. |
| 76 | +- Contract integration tests that simulate transactions and external state. |
| 77 | +- Use the Soroban testing harness to verify emitted events and contract behavior. |
| 78 | + |
| 79 | +Example command: |
| 80 | + |
| 81 | +```bash |
| 82 | +cd soroban-contracts/soroscan_core |
| 83 | +cargo test |
| 84 | +``` |
| 85 | + |
| 86 | +## End-to-End Testing Guide |
| 87 | + |
| 88 | +- Use Playwright to validate user workflows and API interactions. |
| 89 | +- Test scenarios for event ingestion, webhook delivery, and dashboard behavior. |
| 90 | +- Run full-stack E2E tests in CI to cover critical customer journeys. |
| 91 | + |
| 92 | +Example command: |
| 93 | + |
| 94 | +```bash |
| 95 | +pnpm exec playwright test |
| 96 | +``` |
| 97 | + |
| 98 | +## Performance Testing |
| 99 | + |
| 100 | +- Load testing with `k6` or similar tools. |
| 101 | +- Baseline performance metrics for API throughput, latency, and ingestion. |
| 102 | +- Regression testing on key endpoints to detect performance drift. |
| 103 | + |
| 104 | +## Cross-Team Notes |
| 105 | + |
| 106 | +- Reference existing backend tests in `django-backend/`. |
| 107 | +- Reference frontend tests in `soroscan-frontend/__tests__/`. |
| 108 | +- Reference Soroban contract tests in `soroban-contracts/soroscan_core/`. |
0 commit comments