Confidential AI Network Documentation
# Integration Testing Guide
This guide explains how to run integration tests with real Keycloak, blockchain, and database services.## Overview
Integration tests use real services instead of mocks to test the complete application flow:## Prerequisites
* Docker and Docker Compose: Must be installed and running## Quick Start
### 1. Start the Integration Test Environment
# Start all required servicesnpm run test:integration:setup
# Or manually:
./scripts/start-integration-test-env.sh
This will start:
### 2. Run Integration Tests
# Run integration testsnpm run test:integration
# Or manually:
npx jest tests/integration.test.js --verbose --timeout=60000
### 3. Stop the Environment
# Stop all servicesnpm run test:integration:teardown
# Or manually:
./scripts/stop-integration-test-env.sh
### 4. Run Complete Integration Test Suite
# Start environment, run tests, and stop environmentnpm run test:integration:full
## Service Configuration
### Database (PostgreSQL)
postgresql://testuser:testpass@localhost:5433/contract_management_testcontract_management_testtestusertestpass### Keycloak
http://localhost:8081adminadmin123contract-management-testbackend-test### Blockchain (Ganache)
http://localhost:8546test test test test test test test test test test test junk### Blockchain (Hardhat)
http://localhost:8547## Test Accounts
The integration tests use these pre-funded accounts:### Private Keys
TDP: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
TDC: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'
CCRP: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a'
ADMIN: '0x7c852118eafd6e862e4eaa3b37b6c7b1e6b6b6b6b6b6b6b6b6b6b6b6b6b6b6b'
### Addresses
TDP: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
TDC: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'
CCRP: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'
ADMIN: '0x90F79bf6EB2c4f870365E785982E1f101E93b906'
## Test Structure
### Integration Test Categories
* Service Health Checks- Database connection - Keycloak connection - Blockchain connection - Block number verification
- Realm creation - Client creation - User creation - Authentication
- Party registration - Contract creation - Contract signing - Contract retrieval
- User creation - Dataset creation - AI model creation - Contract creation
- AI models endpoint - Datasets endpoint - Contracts endpoint
- Complete contract lifecycle - Status transitions - Data persistence
## Environment Variables
The integration tests use these environment variables (configured intests/integration-env.js):DATABASE_URL: 'postgresql://testuser:testpass@localhost:5433/contract_management_test'
KEYCLOAK_URL: 'http://localhost:8081'
BLOCKCHAIN_URL: 'http://localhost:8546' // or 8547 for Hardhat
BLOCKCHAIN_ENABLED: 'true'
JWT_SECRET: 'integration-test-secret-key-for-jwt-signing'
## Troubleshooting
### Common Issues
* Docker not running
# Start Docker Desktop
# Then run the setup script
# Check if ports are in use
lsof -i :5433
lsof -i :8081
lsof -i :8546
lsof -i :8547
# Stop conflicting services
# Check service status
docker-compose -f docker-compose.test.yml ps
# Check service logs
docker-compose -f docker-compose.test.yml logs
# Test database connection
psql postgresql://testuser:testpass@localhost:5433/contract_management_test
# Test Keycloak health
curl http://localhost:8081/health/ready
# Test Ganache
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://localhost:8546
### Debug Mode
Run tests with verbose output:npm run test:integration -- --verbose
### Manual Service Checks
# Check PostgreSQLdocker-compose -f docker-compose.test.yml exec postgres-test pg_isready -U testuser -d contract_management_test
# Check Keycloak
curl -f http://localhost:8081/health/ready
# Check Ganache
curl -f -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://localhost:8546
## Advanced Configuration
### Using Different Blockchain Networks
Edittests/integration-env.js to switch between Ganache and Hardhat:// For Ganache
BLOCKCHAIN_URL: 'http://localhost:8546'// For Hardhat
BLOCKCHAIN_URL: 'http://localhost:8547'
### Custom Test Data
Modify the test data intests/integration.test.js:const testUsers = [
{
email: 'custom-tdp@example.com',
username: 'custom-tdp',
password: 'CustomPassword123',
role: 'TDP'
}
// ... more users
];
### Adding New Test Cases
* Create a new test file:tests/new-integration.test.jsrequire('./integration-env')## CI/CD Integration
For continuous integration, add to your CI pipeline:# Example GitHub Actionsname: Start Integration Environment run: npm run test:integration:setup
* name: Wait for Services run: sleep 60
name: Run Integration Tests run: npm run test:integration
name: Stop Integration Environment if: always()
run: npm run test:integration:teardown
## Performance Considerations
* Integration tests are slower than unit tests## Security Notes
* Test environment uses weak passwords## Next Steps