This directory contains end-to-end integration tests for the MPCium multi-party computation system.
The E2E tests verify that the complete MPC system works correctly by:
- Infrastructure Setup: Using testcontainers to spin up isolated NATS and Consul instances
- Node Setup: Creating 3 test nodes with separate identities and configurations
- Key Generation: Testing concurrent key generation for multiple wallets
- Consistency Verification: Ensuring all generated keys are properly stored across all nodes
- Cleanup: Removing all test artifacts and containers
Before running the tests, ensure you have:
- Docker installed and running
- Go 1.23+ installed
- mpcium and mpcium-cli binaries built (run
makein the root directory)
# Run all E2E tests
make test
# Clean up test artifacts
make clean-
Build the binaries (from root directory):
make
-
Run the E2E tests:
cd e2e make test
keygen_test.go- Main test file with the E2E test suitedocker-compose.test.yaml- Test infrastructure configurationconfig.test.yaml- Test node configuration templatesetup_test_identities.sh- Script to set up test node identitiesMakefile- Build and test automation
-
Setup Infrastructure
- Starts NATS (port 4223) and Consul (port 8501) containers
- Creates service clients for test coordination
-
Setup Test Nodes
- Creates 3 test nodes (
test_node0,test_node1,test_node2) - Generates unique identities for each node
- Configures separate database paths (
./test_db/) - Registers peers in Consul
- Creates 3 test nodes (
-
Start MPC Nodes
- Launches 3 mpcium processes in parallel
- Each node uses its own configuration and identity
-
Test Key Generation
- Generates 3 random wallet IDs
- Triggers key generation for all wallets simultaneously
- Waits for completion (2 minute timeout)
-
Verify Consistency
- Stops all nodes safely
- Opens each node's database in read-only mode
- Verifies both ECDSA and EdDSA keys exist for each wallet
- Ensures all nodes have identical key data
-
Cleanup
- Stops all processes
- Removes Docker containers
- Deletes test databases and temporary files
The tests use different ports to avoid conflicts with running services:
- NATS: 4223 (vs 4222 for main)
- Consul: 8501 (vs 8500 for main)
Test nodes use a separate database path: ./test_db/ instead of ./db/
- Badger Password:
test_password_123 - Node Names:
test_node0,test_node1,test_node2
-
Binary not found
❌ mpcium binary not found. Please run 'make' in the root directory first.Solution: Run
makein the root directory to build the binaries. -
Port conflicts
Error: port 4223 already in useSolution: Run
make cleanto stop any existing test containers. -
Permission errors
Error: cannot create test_db directorySolution: Ensure you have write permissions in the e2e directory.
To debug test failures:
-
Check container logs:
docker logs nats-server-test docker logs consul-test
-
Run with verbose output:
go test -v -timeout=10m ./... -
Keep test artifacts (comment out cleanup in the test):
# Inspect test databases ls -la test_db/ # Check test node configurations cat test_node0/config.yaml
A successful test run should show:
🚀 Setting up test infrastructure...
🐳 Starting docker-compose stack...
⏳ Waiting for services to be ready...
🔌 Setting up service clients...
✅ Consul client connected
✅ NATS client connected
🔧 Setting up test nodes...
✅ Test nodes setup complete
📋 Registering peers in Consul...
✅ Registered peer test_node0 with ID xxx
✅ Registered peer test_node1 with ID xxx
✅ Registered peer test_node2 with ID xxx
🚀 Starting MPC nodes...
✅ Started node test_node0 (PID: xxx)
✅ Started node test_node1 (PID: xxx)
✅ Started node test_node2 (PID: xxx)
🔑 Testing key generation...
📝 Generated wallet IDs: [xxx, xxx, xxx]
🔐 Triggering key generation for wallet xxx
⏳ Waiting for key generation to complete...
✅ Key generation test completed
🔍 Verifying key consistency across nodes...
🛑 Stopping MPC nodes...
🔍 Checking wallet xxx
✅ Found ECDSA key for wallet xxx in node test_node0 (xxx bytes)
✅ Found ECDSA key for wallet xxx in node test_node1 (xxx bytes)
✅ Found ECDSA key for wallet xxx in node test_node2 (xxx bytes)
✅ Found EdDSA key for wallet xxx in node test_node0 (xxx bytes)
✅ Found EdDSA key for wallet xxx in node test_node1 (xxx bytes)
✅ Found EdDSA key for wallet xxx in node test_node2 (xxx bytes)
✅ Key consistency verification completed
🧹 Cleaning up test environment...
✅ Cleanup completed
To integrate with CI/CD pipelines:
# Example GitHub Actions step
- name: Run E2E Tests
run: |
make
cd e2e
make testThe tests are designed to be:
- Isolated: No dependencies on external services
- Deterministic: Consistent results across runs
- Self-contained: All setup and cleanup handled automatically
- Fast: Complete in under 10 minutes
E2E tests can sometimes leave behind running processes that interfere with subsequent test runs. This can cause signature verification errors and other unexpected failures.
The test suite now includes automatic cleanup mechanisms to prevent process interference:
- Pre-test cleanup: Every test run starts with
CleanupTestEnvironment()which:- Kills any existing MPC processes
- Stops Docker containers
- Removes test artifacts
- Post-test cleanup: Tests use
deferto ensure cleanup happens even if tests fail
If you need to manually clean up the test environment:
# Option 1: Use the cleanup script directly
cd e2e
./cleanup_test_env.sh
# Option 2: Use the Makefile target
make cleanup-test-env
# Option 3: Manual cleanup commands
cd e2e
# Kill MPC processes
pgrep -f "mpcium" | xargs kill -TERM
# Stop Docker containers
docker compose -f docker-compose.test.yaml down -v --remove-orphans
# Remove test artifacts
rm -rf test_node* *.logIf you encounter signature verification errors or other mysterious test failures:
-
Check for running processes:
ps aux | grep mpcium -
Kill any found processes:
pkill -f mpcium
-
Clean up completely:
make cleanup-test-env
-
Run tests again:
go test -v -run TestKeyGeneration
- Always clean up before running tests - The test suite does this automatically
- Use the cleanup script if you interrupt tests manually (Ctrl+C)
- Check for leftover processes if you see unexpected errors
- Don't run multiple test instances simultaneously in the same directory
base_test.go- Core test infrastructure and cleanup functionskeygen_test.go- Key generation testscleanup_test_env.sh- Standalone cleanup scriptdocker-compose.test.yaml- Test infrastructure (NATS, Consul)
| Issue | Cause | Solution |
|---|---|---|
| "Failed to verify initiator message" | Multiple MPC instances running | Run cleanup script |
| "Port already in use" | Docker containers still running | docker compose down -v |
| "Database locked" | Previous test didn't clean up | Remove test_node* directories |
| Test hangs during setup | Leftover processes interfering | Kill all mpcium processes |