98 lines
3.2 KiB
Bash
Executable File
98 lines
3.2 KiB
Bash
Executable File
#!/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 ..
|
|
}
|
|
|
|
TEST=1 ./${script_dir}/build-container.sh
|
|
[ -e "${script_dir}/mint_sol" ] || build_mint_sol_tool
|
|
|
|
# Cleanup old containers and the network
|
|
echo "Creating the network and the root node"
|
|
docker ps -a | grep 'dthc' | awk '{ print $NF }' | xargs docker rm -f || true
|
|
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 dthc-root \
|
|
--network dthc -d \
|
|
--ip 172.18.0.2 \
|
|
--env NODE_IP="172.18.0.2" \
|
|
--device /dev/sgx/provision \
|
|
--device /dev/sgx/enclave \
|
|
detee/hacker-challenge:test
|
|
while true; do
|
|
echo -n "." && sleep 1
|
|
docker logs dthc-root | grep -q "SOL" && echo && break
|
|
done
|
|
|
|
echo "Sending SOL to the root and waiting for the mint"
|
|
address=$(docker logs dthc-root | grep 'SOL' | awk '{ print $NF }')
|
|
"${script_dir}"/mint_sol "${address}"
|
|
while true; do
|
|
echo -n "." && sleep 1
|
|
docker logs dthc-root | grep -q "Mint created" && echo && break
|
|
done
|
|
|
|
echo "Creating the cluster"
|
|
for n in {1..20}; do
|
|
#init_nodes=$(docker inspect dthc-root --format '{{ .NetworkSettings.Networks.dthc.IPAddress }}')
|
|
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
|
|
sleep 15 # Wait for the cluster to start
|
|
|
|
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" \
|
|
--json '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' \
|
|
--connect-timeout 5 2> /dev/null
|
|
echo ""
|
|
done
|
|
|
|
# curl 127.0.0.1:31303/metrics
|
|
# curl -X POST 127.0.0.1:31303/mint -d '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' -H 'Content-Type: application/json'
|
|
# docker run --network dthc -d --name dthc-3 --ip 172.18.0.3 --env NODE_IP='172.18.0.3' --env INIT_NODES='172.18.0.2' -v /tmp/dthc3:/challenge/main -p 31303:31372 --device /dev/sgx/provision --device /dev/sgx/enclave detee/hacker-challenge:test
|