hacker-challenge-sgx-general/scripts/testnet.sh
jakubDoka 09a84a15f3 rewrite (#2)
running clippy fix
separating homepage to a file
adding summary of network security
removing the rewrite structure
removing catch unwind
adding sealing to persistence
redirectng to the upstream
fixing some startup endgecases

Co-authored-by: Jakub Doka <jakub.doka2@gmail.com>
Reviewed-on: SGX/hacker-challenge-sgx#2
2024-11-08 14:33:42 +00:00

91 lines
2.5 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 build_challenge_image() {
echo "Building the hacker-challenge docker image"
if ! command -v docker 2>&1 >/dev/null
then
echo "docker not found, please install docker"
exit 1
fi
if [ ! -e challenge_instance/challenge.tar.gz ]; then
echo "Please build the challenge first, see README.md"
exit 1
fi
cd docker
cp ../challenge_instance/challenge.tar.gz challenge.tar.gz
docker build -f challenge.Dockerfile -t hacker-challenge:latest .
cd ..
}
build_challenge_image
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" \
--name "hacker-challenge${p}" -p "${p}:31372" \
-d hacker-challenge:latest
done
sleep 5 # 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"}'
done