|
| 1 | +# E2E Integration Tests |
| 2 | + |
| 3 | +This directory contains end-to-end integration tests for the MPCIUM multi-party computation system. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The E2E tests verify that the complete MPC system works correctly by: |
| 8 | + |
| 9 | +1. **Infrastructure Setup**: Using testcontainers to spin up isolated NATS and Consul instances |
| 10 | +2. **Node Setup**: Creating 3 test nodes with separate identities and configurations |
| 11 | +3. **Key Generation**: Testing concurrent key generation for multiple wallets |
| 12 | +4. **Consistency Verification**: Ensuring all generated keys are properly stored across all nodes |
| 13 | +5. **Cleanup**: Removing all test artifacts and containers |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Before running the tests, ensure you have: |
| 18 | + |
| 19 | +- **Docker** installed and running |
| 20 | +- **Go** 1.23+ installed |
| 21 | +- **mpcium** and **mpcium-cli** binaries built (run `make` in the root directory) |
| 22 | + |
| 23 | +## Running Tests |
| 24 | + |
| 25 | +### Quick Start |
| 26 | + |
| 27 | +```bash |
| 28 | +# Run all E2E tests |
| 29 | +make test |
| 30 | + |
| 31 | +# Run tests with coverage report |
| 32 | +make test-coverage |
| 33 | + |
| 34 | +# Clean up test artifacts |
| 35 | +make clean |
| 36 | +``` |
| 37 | + |
| 38 | +### Manual Steps |
| 39 | + |
| 40 | +1. **Build the binaries** (from root directory): |
| 41 | + ```bash |
| 42 | + make |
| 43 | + ``` |
| 44 | + |
| 45 | +2. **Run the E2E tests**: |
| 46 | + ```bash |
| 47 | + cd e2e |
| 48 | + make test |
| 49 | + ``` |
| 50 | + |
| 51 | +## Test Structure |
| 52 | + |
| 53 | +### Files |
| 54 | + |
| 55 | +- `keygen_test.go` - Main test file with the E2E test suite |
| 56 | +- `docker-compose.test.yaml` - Test infrastructure configuration |
| 57 | +- `config.test.yaml` - Test node configuration template |
| 58 | +- `setup_test_identities.sh` - Script to set up test node identities |
| 59 | +- `Makefile` - Build and test automation |
| 60 | + |
| 61 | +### Test Flow |
| 62 | + |
| 63 | +1. **Setup Infrastructure** |
| 64 | + - Starts NATS (port 4223) and Consul (port 8501) containers |
| 65 | + - Creates service clients for test coordination |
| 66 | + |
| 67 | +2. **Setup Test Nodes** |
| 68 | + - Creates 3 test nodes (`test_node0`, `test_node1`, `test_node2`) |
| 69 | + - Generates unique identities for each node |
| 70 | + - Configures separate database paths (`./test_db/`) |
| 71 | + - Registers peers in Consul |
| 72 | + |
| 73 | +3. **Start MPC Nodes** |
| 74 | + - Launches 3 mpcium processes in parallel |
| 75 | + - Each node uses its own configuration and identity |
| 76 | + |
| 77 | +4. **Test Key Generation** |
| 78 | + - Generates 3 random wallet IDs |
| 79 | + - Triggers key generation for all wallets simultaneously |
| 80 | + - Waits for completion (2 minute timeout) |
| 81 | + |
| 82 | +5. **Verify Consistency** |
| 83 | + - Stops all nodes safely |
| 84 | + - Opens each node's database in read-only mode |
| 85 | + - Verifies both ECDSA and EdDSA keys exist for each wallet |
| 86 | + - Ensures all nodes have identical key data |
| 87 | + |
| 88 | +6. **Cleanup** |
| 89 | + - Stops all processes |
| 90 | + - Removes Docker containers |
| 91 | + - Deletes test databases and temporary files |
| 92 | + |
| 93 | +## Configuration |
| 94 | + |
| 95 | +### Test Ports |
| 96 | + |
| 97 | +The tests use different ports to avoid conflicts with running services: |
| 98 | + |
| 99 | +- **NATS**: 4223 (vs 4222 for main) |
| 100 | +- **Consul**: 8501 (vs 8500 for main) |
| 101 | + |
| 102 | +### Database Path |
| 103 | + |
| 104 | +Test nodes use a separate database path: `./test_db/` instead of `./db/` |
| 105 | + |
| 106 | +### Test Credentials |
| 107 | + |
| 108 | +- **Badger Password**: `test_password_123` |
| 109 | +- **Node Names**: `test_node0`, `test_node1`, `test_node2` |
| 110 | + |
| 111 | +## Troubleshooting |
| 112 | + |
| 113 | +### Common Issues |
| 114 | + |
| 115 | +1. **Binary not found** |
| 116 | + ``` |
| 117 | + ❌ mpcium binary not found. Please run 'make' in the root directory first. |
| 118 | + ``` |
| 119 | + **Solution**: Run `make` in the root directory to build the binaries. |
| 120 | + |
| 121 | +2. **Port conflicts** |
| 122 | + ``` |
| 123 | + Error: port 4223 already in use |
| 124 | + ``` |
| 125 | + **Solution**: Run `make clean` to stop any existing test containers. |
| 126 | + |
| 127 | +3. **Permission errors** |
| 128 | + ``` |
| 129 | + Error: cannot create test_db directory |
| 130 | + ``` |
| 131 | + **Solution**: Ensure you have write permissions in the e2e directory. |
| 132 | + |
| 133 | +### Debugging |
| 134 | + |
| 135 | +To debug test failures: |
| 136 | + |
| 137 | +1. **Check container logs**: |
| 138 | + ```bash |
| 139 | + docker logs nats-server-test |
| 140 | + docker logs consul-test |
| 141 | + ``` |
| 142 | + |
| 143 | +2. **Run with verbose output**: |
| 144 | + ```bash |
| 145 | + go test -v -timeout=10m ./... |
| 146 | + ``` |
| 147 | + |
| 148 | +3. **Keep test artifacts** (comment out cleanup in the test): |
| 149 | + ```bash |
| 150 | + # Inspect test databases |
| 151 | + ls -la test_db/ |
| 152 | + |
| 153 | + # Check test node configurations |
| 154 | + cat test_node0/config.yaml |
| 155 | + ``` |
| 156 | + |
| 157 | +## Expected Output |
| 158 | + |
| 159 | +A successful test run should show: |
| 160 | + |
| 161 | +``` |
| 162 | +🚀 Setting up test infrastructure... |
| 163 | +🐳 Starting docker-compose stack... |
| 164 | +⏳ Waiting for services to be ready... |
| 165 | +🔌 Setting up service clients... |
| 166 | +✅ Consul client connected |
| 167 | +✅ NATS client connected |
| 168 | +🔧 Setting up test nodes... |
| 169 | +✅ Test nodes setup complete |
| 170 | +📋 Registering peers in Consul... |
| 171 | +✅ Registered peer test_node0 with ID xxx |
| 172 | +✅ Registered peer test_node1 with ID xxx |
| 173 | +✅ Registered peer test_node2 with ID xxx |
| 174 | +🚀 Starting MPC nodes... |
| 175 | +✅ Started node test_node0 (PID: xxx) |
| 176 | +✅ Started node test_node1 (PID: xxx) |
| 177 | +✅ Started node test_node2 (PID: xxx) |
| 178 | +🔑 Testing key generation... |
| 179 | +📝 Generated wallet IDs: [xxx, xxx, xxx] |
| 180 | +🔐 Triggering key generation for wallet xxx |
| 181 | +⏳ Waiting for key generation to complete... |
| 182 | +✅ Key generation test completed |
| 183 | +🔍 Verifying key consistency across nodes... |
| 184 | +🛑 Stopping MPC nodes... |
| 185 | +🔍 Checking wallet xxx |
| 186 | +✅ Found ECDSA key for wallet xxx in node test_node0 (xxx bytes) |
| 187 | +✅ Found ECDSA key for wallet xxx in node test_node1 (xxx bytes) |
| 188 | +✅ Found ECDSA key for wallet xxx in node test_node2 (xxx bytes) |
| 189 | +✅ Found EdDSA key for wallet xxx in node test_node0 (xxx bytes) |
| 190 | +✅ Found EdDSA key for wallet xxx in node test_node1 (xxx bytes) |
| 191 | +✅ Found EdDSA key for wallet xxx in node test_node2 (xxx bytes) |
| 192 | +✅ Key consistency verification completed |
| 193 | +🧹 Cleaning up test environment... |
| 194 | +✅ Cleanup completed |
| 195 | +``` |
| 196 | + |
| 197 | +## Integration with CI/CD |
| 198 | + |
| 199 | +To integrate with CI/CD pipelines: |
| 200 | + |
| 201 | +```yaml |
| 202 | +# Example GitHub Actions step |
| 203 | +- name: Run E2E Tests |
| 204 | + run: | |
| 205 | + make |
| 206 | + cd e2e |
| 207 | + make test |
| 208 | +``` |
| 209 | +
|
| 210 | +The tests are designed to be: |
| 211 | +- **Isolated**: No dependencies on external services |
| 212 | +- **Deterministic**: Consistent results across runs |
| 213 | +- **Self-contained**: All setup and cleanup handled automatically |
| 214 | +- **Fast**: Complete in under 10 minutes |
0 commit comments