Files
mpc/e2e/setup_test_identities.sh
zeekay 98421eb533 fix: update dependencies and fix e2e test issues
- Fixed shell script compatibility for macOS
- Updated e2e module dependencies
- Simplified benchmark tests
- Fixed KMS client build
2025-08-16 13:12:25 -05:00

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!"