mirror of
https://github.com/luxfi/mpc.git
synced 2026-09-24 00:26:24 +00:00
- Fixed shell script compatibility for macOS - Updated e2e module dependencies - Simplified benchmark tests - Fixed KMS client build
136 lines
4.6 KiB
Bash
Executable File
136 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# E2E Test Identity Setup Script
|
|
# This script sets up identities for testing with separate test database paths
|
|
|
|
set -e
|
|
|
|
# Number of test nodes
|
|
NUM_NODES=3
|
|
BASE_DIR="$(pwd)"
|
|
TEST_DB_PATH="$BASE_DIR/test_db"
|
|
|
|
echo "๐ Setting up E2E Test Node Identities..."
|
|
|
|
# Generate random password for badger encryption
|
|
echo "๐ Generating random password for badger encryption..."
|
|
BADGER_PASSWORD=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 32)
|
|
echo "โ
Generated password: $BADGER_PASSWORD"
|
|
|
|
# Generate config.test.yaml from template
|
|
echo "๐ Generating config.test.yaml from template..."
|
|
if [ ! -f "config.test.yaml.template" ]; then
|
|
echo "โ Template file config.test.yaml.template not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Create a temporary config with placeholder values (will be updated later with real pubkey)
|
|
TEMP_PUBKEY="0000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
# Escape special characters in password for sed
|
|
ESCAPED_PASSWORD=$(printf '%s\n' "$BADGER_PASSWORD" | sed 's/[[\.*^$()+?{|]/\\&/g')
|
|
|
|
sed -e "s/{{\.BadgerPassword}}/$ESCAPED_PASSWORD/g" \
|
|
-e "s/{{\.EventInitiatorPubkey}}/$TEMP_PUBKEY/g" \
|
|
config.test.yaml.template > config.test.yaml
|
|
|
|
echo "โ
Generated config.test.yaml from template"
|
|
|
|
# Clean up any existing test data
|
|
echo "๐งน Cleaning up existing test data..."
|
|
rm -rf "$TEST_DB_PATH"
|
|
rm -rf "$BASE_DIR"/test_node*
|
|
|
|
# Create test node directories
|
|
echo "๐ Creating test node directories..."
|
|
# Generate UUIDs for the nodes
|
|
NODE0_UUID=$(uuidgen)
|
|
NODE1_UUID=$(uuidgen)
|
|
NODE2_UUID=$(uuidgen)
|
|
|
|
for i in $(seq 0 $((NUM_NODES-1))); do
|
|
mkdir -p "$BASE_DIR/test_node$i/identity"
|
|
cp "$BASE_DIR/config.test.yaml" "$BASE_DIR/test_node$i/config.yaml"
|
|
|
|
# Create peers.json with proper UUIDs
|
|
cat > "$BASE_DIR/test_node$i/peers.json" << EOF
|
|
{
|
|
"test_node0": "$NODE0_UUID",
|
|
"test_node1": "$NODE1_UUID",
|
|
"test_node2": "$NODE2_UUID"
|
|
}
|
|
EOF
|
|
done
|
|
|
|
# Generate identity for each test node
|
|
echo "๐ Generating identities for each test node..."
|
|
for i in $(seq 0 $((NUM_NODES-1))); do
|
|
echo "๐ Generating identity for test_node$i..."
|
|
cd "$BASE_DIR/test_node$i"
|
|
|
|
# Generate identity using lux-mpc-cli
|
|
lux-mpc-cli generate-identity --node "test_node$i"
|
|
|
|
cd - > /dev/null
|
|
done
|
|
|
|
# Distribute identity files to all test nodes
|
|
echo "๐ Distributing identity files across test nodes..."
|
|
for i in $(seq 0 $((NUM_NODES-1))); do
|
|
for j in $(seq 0 $((NUM_NODES-1))); do
|
|
if [ $i != $j ]; then
|
|
echo "๐ Copying test_node${i}_identity.json to test_node$j..."
|
|
cp "$BASE_DIR/test_node$i/identity/test_node${i}_identity.json" "$BASE_DIR/test_node$j/identity/"
|
|
fi
|
|
done
|
|
done
|
|
|
|
# Generate test event initiator
|
|
echo "๐ Generating test event initiator..."
|
|
cd "$BASE_DIR"
|
|
lux-mpc-cli generate-initiator --node-name test_event_initiator --output-dir . --overwrite
|
|
|
|
# Extract the public key from the generated identity
|
|
if [ -f "test_event_initiator.identity.json" ]; then
|
|
PUBKEY=$(cat test_event_initiator.identity.json | jq -r '.public_key')
|
|
echo "๐ Updating config files with event initiator public key and password..."
|
|
|
|
# Update all test node config files with the actual public key and password
|
|
for i in $(seq 0 $((NUM_NODES-1))); do
|
|
# Update public key using sed with | as delimiter (safer than /)
|
|
sed -i '' "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/test_node$i/config.yaml"
|
|
# Update password using sed with | as delimiter and escaped password
|
|
sed -i '' "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/test_node$i/config.yaml"
|
|
done
|
|
|
|
# Also update the main config.test.yaml
|
|
sed -i '' "s|event_initiator_pubkey:.*|event_initiator_pubkey: $PUBKEY|g" "$BASE_DIR/config.test.yaml"
|
|
sed -i '' "s|badger_password:.*|badger_password: $ESCAPED_PASSWORD|g" "$BASE_DIR/config.test.yaml"
|
|
|
|
echo "โ
Event initiator public key updated: $PUBKEY"
|
|
echo "โ
Badger password updated: $BADGER_PASSWORD"
|
|
else
|
|
echo "โ Failed to generate event initiator identity"
|
|
exit 1
|
|
fi
|
|
|
|
cd - > /dev/null
|
|
|
|
echo "โจ E2E Test identities setup complete!"
|
|
echo
|
|
echo "๐ Created test folder structure:"
|
|
echo "โโโ test_node0"
|
|
echo "โ โโโ config.yaml"
|
|
echo "โ โโโ identity/"
|
|
echo "โ โโโ peers.json"
|
|
echo "โโโ test_node1"
|
|
echo "โ โโโ config.yaml"
|
|
echo "โ โโโ identity/"
|
|
echo "โ โโโ peers.json"
|
|
echo "โโโ test_node2"
|
|
echo " โโโ config.yaml"
|
|
echo " โโโ identity/"
|
|
echo " โโโ peers.json"
|
|
echo
|
|
echo "โ
Test nodes are ready for E2E testing!"
|