hacker-challenge/scripts/testnet.sh
Valentyn Faychuk 89ad4ad92f
testnet upgrade
Signed-off-by: Valentyn Faychuk <valy@detee.ltd>
2024-12-22 21:10:27 +02:00

97 lines
2.8 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 ..
}
function run_node() {
custom_flags=$1
docker run --network dthc -d $custom_flags \
--device /dev/sgx/provision \
--device /dev/sgx/enclave \
detee/hacker-challenge:test
}
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
# 172.18.0.1 is for the network gateway
root_ip="172.18.0.2"
echo "Waiting for the root node to start"
run_node "--name dthc-root --ip ${root_ip} \
--env NODE_IP='${root_ip}'"
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 {2..20}; do
#init_nodes=$(docker inspect dthc-root --format '{{ .NetworkSettings.Networks.dthc.IPAddress }}')
node_ip="172.18.0.${n}"
node_port=$((31300 + n))
node_volume="/tmp/dthc${node_port}"
run_node "--name dthc-${n} --ip ${node_ip} \
--env NODE_IP='${node_ip}' \
--env INIT_NODES='${root_ip}' \
-v ${node_volume}:/challenge/main \
-p ${node_port}:31372"
done
sleep 15 # Wait for the cluster to start
echo "Running the test mint"
for n in {2..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 <ip>/metrics
# curl -X POST <ip>/mint -d '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' -H 'Content-Type: application/json'