Files
asle/TESTING.md
defiQUG 507d9a35b1 Add initial project structure and documentation files
- Created .gitignore to exclude sensitive files and directories.
- Added API documentation in API_DOCUMENTATION.md.
- Included deployment instructions in DEPLOYMENT.md.
- Established project structure documentation in PROJECT_STRUCTURE.md.
- Updated README.md with project status and team information.
- Added recommendations and status tracking documents.
- Introduced testing guidelines in TESTING.md.
- Set up CI workflow in .github/workflows/ci.yml.
- Created Dockerfile for backend and frontend setups.
- Added various service and utility files for backend functionality.
- Implemented frontend components and pages for user interface.
- Included mobile app structure and services.
- Established scripts for deployment across multiple chains.
2025-12-03 21:22:31 -08:00

242 lines
4.5 KiB
Markdown

# ASLE Testing Guide
## Overview
This document outlines the testing strategy and test structure for the ASLE project.
## Smart Contract Testing
### Foundry Tests
All smart contract tests are written in Solidity using Foundry.
**Location:** `contracts/test/`
### Running Tests
```bash
cd contracts
forge test # Run all tests
forge test -vvv # Verbose output
forge test --match-path test/LiquidityFacet.t.sol # Specific test file
forge test --match-test testCreatePool # Specific test
```
### Test Coverage
Run coverage:
```bash
forge coverage
```
### Test Files Structure
- `Diamond.t.sol` - Diamond deployment and facet management
- `LiquidityFacet.t.sol` - PMM pool creation and operations
- `VaultFacet.t.sol` - ERC-4626 and ERC-1155 vault tests
- `ComplianceFacet.t.sol` - Compliance mode and KYC/AML tests
- `CCIPFacet.t.sol` - Cross-chain messaging tests
- `GovernanceFacet.t.sol` - Proposal and voting tests
- `SecurityFacet.t.sol` - Pause and circuit breaker tests
- `RWAFacet.t.sol` - RWA tokenization tests
- `Integration.t.sol` - Multi-facet interaction tests
- `mocks/` - Mock contracts for testing
### Writing Tests
Example test structure:
```solidity
contract MyFacetTest is Test {
Diamond public diamond;
MyFacet public facet;
function setUp() public {
// Setup diamond and facets
}
function testMyFunction() public {
// Test implementation
assertEq(result, expected);
}
}
```
## Backend Testing
### Unit Tests
**Location:** `backend/src/__tests__/`
Run tests:
```bash
cd backend
npm test
npm test -- --coverage
```
### Test Structure
- `services/` - Service unit tests
- `api/` - API route tests
- `middleware/` - Middleware tests
- `utils/` - Utility function tests
### Example Test
```typescript
import { ComplianceService } from '../services/compliance';
describe('ComplianceService', () => {
it('should verify KYC', async () => {
const service = new ComplianceService(provider, diamondAddress);
const result = await service.verifyKYC(userAddress);
expect(result.verified).toBe(true);
});
});
```
### Integration Tests
Test API endpoints:
```bash
npm run test:integration
```
## Frontend Testing
### Component Tests
**Location:** `frontend/__tests__/`
Run tests:
```bash
cd frontend
npm test
npm test -- --coverage
```
### Testing Stack
- Jest for unit tests
- React Testing Library for component tests
- Playwright for E2E tests
### Example Component Test
```typescript
import { render, screen } from '@testing-library/react';
import { PoolCreator } from '../components/PoolCreator';
describe('PoolCreator', () => {
it('renders form fields', () => {
render(<PoolCreator />);
expect(screen.getByLabelText('Base Token Address')).toBeInTheDocument();
});
});
```
### E2E Tests
Run E2E tests:
```bash
npm run test:e2e
```
E2E tests cover complete user workflows:
- Wallet connection
- Pool creation
- Vault deposit
- Governance voting
## Test Data
### Mock Data
- Contract mocks in `contracts/test/mocks/`
- API mocks in `backend/src/__tests__/mocks/`
- Frontend mocks in `frontend/__tests__/mocks/`
### Fixtures
Test fixtures and sample data are organized by domain:
- Pool fixtures
- Vault fixtures
- Compliance fixtures
- Transaction fixtures
## Continuous Integration
All tests run automatically on:
- Pull requests
- Pushes to main/develop branches
- Scheduled daily runs
See `.github/workflows/ci.yml` for CI configuration.
## Test Coverage Goals
- Smart Contracts: >90%
- Backend Services: >80%
- Backend API: >70%
- Frontend Components: >70%
- E2E: Critical paths 100%
## Debugging Tests
### Foundry
```bash
forge test --debug testMyFunction
forge test -vvvv # Maximum verbosity
```
### Backend
```bash
npm test -- --verbose
npm test -- --grep "pattern"
```
### Frontend
```bash
npm test -- --verbose
npm test -- --watch
```
## Performance Testing
Load testing for API:
```bash
cd backend
npm run test:load
```
Contract gas optimization tests:
```bash
cd contracts
forge snapshot
```
## Security Testing
Run security checks:
```bash
# Smart contracts
cd contracts
slither . # If installed
# Dependencies
npm audit
```
## Best Practices
1. **Isolation**: Each test should be independent
2. **Cleanup**: Reset state between tests
3. **Naming**: Clear, descriptive test names
4. **Coverage**: Aim for high coverage but focus on critical paths
5. **Speed**: Keep tests fast, use mocks where appropriate
6. **Maintainability**: Keep tests simple and readable