Skip to content

Commit 80b8134

Browse files
committed
Add e2e testing pipeline
1 parent fb31234 commit 80b8134

10 files changed

Lines changed: 1910 additions & 1 deletion

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ event_initiator.key
77
event_initiator.key.age
88
coverage.out
99
coverage.html
10+
11+
# E2E test artifacts
12+
e2e/test_db/
13+
e2e/test_node*/
14+
e2e/test_event_initiator.*
15+
e2e/coverage.out
16+
e2e/coverage.html
17+
e2e/logs/

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build clean mpcium mpc test test-verbose test-coverage
1+
.PHONY: all build clean mpcium mpc test test-verbose test-coverage e2e-test e2e-clean
22

33
BIN_DIR := bin
44

@@ -29,7 +29,28 @@ test-coverage:
2929
go test -v -coverprofile=coverage.out ./...
3030
go tool cover -html=coverage.out -o coverage.html
3131

32+
# Run E2E integration tests
33+
e2e-test: build
34+
@echo "Running E2E integration tests..."
35+
cd e2e && make test
36+
37+
# Run E2E tests with coverage
38+
e2e-test-coverage: build
39+
@echo "Running E2E integration tests with coverage..."
40+
cd e2e && make test-coverage
41+
42+
# Clean up E2E test artifacts
43+
e2e-clean:
44+
@echo "Cleaning up E2E test artifacts..."
45+
cd e2e && make clean
46+
47+
# Run all tests (unit + E2E)
48+
test-all: test e2e-test
49+
3250
# Wipe out manually built binaries if needed (not required by go install)
3351
clean:
3452
rm -rf $(BIN_DIR)
3553
rm -f coverage.out coverage.html
54+
55+
# Full clean (including E2E artifacts)
56+
clean-all: clean e2e-clean

e2e/Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.PHONY: test setup clean deps
2+
3+
# Default target
4+
test: deps setup
5+
@echo "Running E2E tests..."
6+
go test -v -timeout=10m ./...
7+
8+
# Setup test environment
9+
setup:
10+
@echo "🔧 Setting up test environment..."
11+
@if ! command -v mpcium >/dev/null 2>&1; then \
12+
echo "❌ mpcium binary not found in PATH. Please run 'make' in the root directory first."; \
13+
exit 1; \
14+
fi
15+
@if ! command -v mpcium-cli >/dev/null 2>&1; then \
16+
echo "❌ mpcium-cli binary not found in PATH. Please run 'make' in the root directory first."; \
17+
exit 1; \
18+
fi
19+
@echo "✅ Binaries found"
20+
21+
# Install dependencies
22+
deps:
23+
@echo "📦 Installing dependencies..."
24+
go mod tidy
25+
go mod download
26+
27+
# Clean up test artifacts
28+
clean:
29+
@echo "🧹 Cleaning up test artifacts..."
30+
rm -rf test_db/
31+
rm -rf test_node*/
32+
rm -f test_event_initiator.*
33+
rm -rf logs
34+
rm -rf coverage.*
35+
docker compose -f docker-compose.test.yaml down --remove-orphans 2>/dev/null || true
36+
37+
# Run tests with coverage
38+
test-coverage: deps setup
39+
@echo "🚀 Running E2E tests with coverage..."
40+
go test -v -timeout=10m -coverprofile=coverage.out ./...
41+
go tool cover -html=coverage.out -o coverage.html
42+
@echo "📊 Coverage report generated: coverage.html"
43+
44+
# Quick test (skip setup)
45+
test-quick:
46+
@echo "⚡ Running quick E2E tests..."
47+
go test -v -timeout=10m ./...
48+
49+
# Help
50+
help:
51+
@echo "Available targets:"
52+
@echo " test - Run E2E tests with full setup"
53+
@echo " test-quick - Run E2E tests without setup"
54+
@echo " test-coverage- Run E2E tests with coverage report"
55+
@echo " setup - Setup test environment"
56+
@echo " deps - Install dependencies"
57+
@echo " clean - Clean up test artifacts"
58+
@echo " help - Show this help message"

e2e/README.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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

e2e/config.test.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
badger_password: yx,qYwu*h!RZ{Q7f;70gU/VT.9kBOFCM
2+
consul:
3+
address: localhost:8501
4+
db_path: ./test_db
5+
environment: development
6+
event_initiator_pubkey: bc2e465f11317616b3ac5ae1a91473224b9b00b97ebf921928ac6478df608a00
7+
max_concurrent_keygen: 2
8+
mpc_threshold: 2
9+
mpcium_version: 1.0.0
10+
nats:
11+
url: nats://127.0.0.1:4223

e2e/docker-compose.test.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3"
2+
3+
services:
4+
nats-server-test:
5+
image: nats:latest
6+
container_name: nats-server-test
7+
command: -js --http_port 8223
8+
ports:
9+
- "4223:4222"
10+
- "8223:8223"
11+
- "6223:6222"
12+
tty: true
13+
restart: always
14+
15+
consul-test:
16+
image: consul:1.15.4
17+
container_name: consul-test
18+
ports:
19+
- "8501:8500"
20+
- "8602:8600/udp"
21+
command: "agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0"
22+
restart: always

0 commit comments

Comments
 (0)