81 lines
2.9 KiB
Bash
Executable File
81 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
num_nodes=${1:-4}
|
|
script_dir=$(dirname "$0")
|
|
cd "${script_dir}/.."
|
|
|
|
function build_mint_sol() {
|
|
command -v cargo >/dev/null 2>&1 || { echo >&2 "cargo not found, run 'curl https://sh.rustup.rs -sSf | sh'"; exit 1; }
|
|
command -v gcc >/dev/null 2>&1 || { echo >&2 "cc not found, run 'apt update && apt install build-essential'"; exit 1; }
|
|
command -v protoc >/dev/null 2>&1 || { echo >&2 "protoc not found, run 'apt update && apt install protobuf-compiler'"; exit 1; }
|
|
|
|
echo "Building the mint_sol tool for testing"
|
|
cd mint_sol && cargo build --release && cd ..
|
|
cp mint_sol/target/release/mint_sol "${script_dir}/mint_sol"
|
|
}
|
|
|
|
eval "sudo rm -rf /tmp/dthc{0..$num_nodes}"
|
|
TEST=1 ./${script_dir}/build-container.sh
|
|
[ -e "${script_dir}/mint_sol" ] || build_mint_sol
|
|
|
|
# Cleanup old containers and the network
|
|
echo "Creating the network and the root node"
|
|
eval "docker rm -f dthc{0..$num_nodes}" 2>&1 /dev/null
|
|
docker network inspect dthc >/dev/null 2>&1 \
|
|
|| docker network create --subnet=172.18.0.0/24 dthc \
|
|
|| true
|
|
|
|
echo "Waiting for the root node to start"
|
|
# 172.18.0.1 is for the network gateway
|
|
docker run --name dthc0 \
|
|
--network dthc -d \
|
|
--ip 172.18.0.2 \
|
|
--env NODE_IP="172.18.0.2" \
|
|
--volume /tmp/dthc0:/challenge/main \
|
|
--publish 31300:31372 \
|
|
--device /dev/sgx/provision \
|
|
--device /dev/sgx/enclave \
|
|
detee/hacker-challenge:test
|
|
while true; do
|
|
echo -n "." && sleep 1
|
|
docker logs dthc0 | grep -q "SOL" && echo && break
|
|
done
|
|
|
|
echo "Sending SOL to the root and waiting for the mint"
|
|
address=$(docker logs dthc0 | grep 'SOL' | awk '{ print $NF }')
|
|
"${script_dir}"/mint_sol "${address}"
|
|
while true; do
|
|
echo -n "." && sleep 1
|
|
docker logs dthc0 | grep -q "Heartbeat..." && echo && break
|
|
done
|
|
|
|
echo "Creating a cluster with ${num_nodes} nodes"
|
|
for n in $(seq 1 $num_nodes); do
|
|
node_ip="172.18.0.$((2 + n))"
|
|
node_port=$((31300 + n))
|
|
node_volume="/tmp/dthc${n}"
|
|
|
|
docker run --name dthc${n} \
|
|
--network dthc -d \
|
|
--ip ${node_ip} \
|
|
--env NODE_IP="${node_ip}" \
|
|
--env INIT_NODES="172.18.0.2 172.18.0.3 172.18.0.4" \
|
|
--volume ${node_volume}:/challenge/main \
|
|
--publish ${node_port}:31372 \
|
|
--device /dev/sgx/provision \
|
|
--device /dev/sgx/enclave \
|
|
detee/hacker-challenge:test
|
|
done
|
|
|
|
echo "Initialing test.."
|
|
sleep 4;
|
|
|
|
echo "Running the test mint"
|
|
for n in {1..20}; do
|
|
node_port=$((31300 + n))
|
|
curl -X POST "127.0.0.1:${node_port}/mint?address=EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR" --connect-timeout 5 2> /dev/null
|
|
done
|
|
|
|
# docker run --name dthc0 --network dthc -d --ip 172.18.0.2 --env NODE_IP="172.18.0.2" --env INIT_NODES="172.18.0.5 172.18.0.3 172.18.0.4" --volume /tmp/dthc0:/challenge/main --publish 31300:31372 --device /dev/sgx/provision --device /dev/sgx/enclave detee/hacker-challenge:test
|