#!/bin/bash set -e script_dir=$(dirname "$0") cd "${script_dir}/.." # Go to the root of the project function build_mint_sol_tool() { echo "Building the mint_sol tool for testing" if ! command -v cargo 2>&1 >/dev/null then echo "cargo not found, run 'curl https://sh.rustup.rs -sSf | sh'" exit 1 fi if ! command -v gcc 2>&1 >/dev/null then echo "cc not found, run 'apt update && apt install build-essential'" exit 1 fi if ! command -v protoc 2>&1 >/dev/null then echo "protoc not found, run 'apt update && apt install protobuf-compiler'" exit 1 fi cd mint_sol cargo build --release cp target/release/mint_sol "../${script_dir}/mint_sol" cd .. } source "${script_dir}/build-container.sh" build_mint_sol_tool # Cleanup old containers and run the network root docker ps -a | grep 'hacker-challenge' | awk '{ print $NF }' | xargs docker rm -f || true echo "Waiting for the network root to start" docker run --device /dev/sgx/enclave \ --device /dev/sgx/provision \ --name "hacker-challenge" \ -d hacker-challenge:latest while true; do echo -n "." && sleep 1 docker logs hacker-challenge | grep "SOL" && echo && break done echo "Sending SOL to the root and waiting for the mint" address=$(docker logs hacker-challenge | grep 'SOL' | awk '{ print $NF }') "${script_dir}"/mint_sol "${address}" while true; do echo -n "." && sleep 1 docker logs hacker-challenge | grep "Mint created" && echo && break done echo "Creating the cluster" for p in {31311..31320}; do docker run --device /dev/sgx/enclave \ --device /dev/sgx/provision \ --env INIT_NODES="172.17.0.2 172.17.0.3 172.17.0.4" \ -v "/tmp/hacker-challenge${p}:/challenge/main" \ --name "hacker-challenge${p}" -p "${p}:31372" \ -d hacker-challenge:latest done sleep 15 # Wait for the cluster to start echo "Running the test mint" for p in {31311..31320}; do curl -X POST "127.0.0.1:${p}/mint" --json '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' >2 /dev/null done