laconicd-deprecated/scripts/start.sh

158 lines
4.2 KiB
Bash
Raw Normal View History

2021-04-17 10:00:07 +00:00
#!/bin/bash
# "stable" mode tests assume data is static
# "live" mode tests assume data dynamic
SCRIPT=$(basename ${BASH_SOURCE[0]})
TEST=""
QTD=1
SLEEP_TIMEOUT=5
TEST_QTD=1
#PORT AND RPC_PORT 3 initial digits, to be concat with a suffix later when node is initialized
2021-05-25 08:46:10 +00:00
RPC_PORT="854"
2021-04-17 10:00:07 +00:00
IP_ADDR="0.0.0.0"
MODE="rpc"
KEY="mykey"
2023-01-04 06:23:28 +00:00
CHAINID="laconic_9000-1"
2021-04-17 10:00:07 +00:00
MONIKER="mymoniker"
2022-10-10 10:38:33 +00:00
## default port prefixes for laconicd
2021-04-17 10:00:07 +00:00
NODE_P2P_PORT="2660"
NODE_PORT="2663"
NODE_RPC_PORT="2666"
usage() {
echo "Usage: $SCRIPT"
echo "Optional command line arguments"
echo "-t <string> -- Test to run. eg: rpc"
echo "-q <number> -- Quantity of nodes to run. eg: 3"
echo "-z <number> -- Quantity of nodes to run tests against eg: 3"
echo "-s <number> -- Sleep between operations in secs. eg: 5"
exit 1
}
while getopts "h?t:q:z:s:" args; do
case $args in
h|\?)
usage;
exit;;
t ) TEST=${OPTARG};;
q ) QTD=${OPTARG};;
z ) TEST_QTD=${OPTARG};;
s ) SLEEP_TIMEOUT=${OPTARG};;
esac
done
set -euxo pipefail
2023-01-04 06:23:28 +00:00
DATA_DIR=$(mktemp -d -t laconic_9000-datadir.XXXXX)
2021-04-17 10:00:07 +00:00
if [[ ! "$DATA_DIR" ]]; then
echo "Could not create $DATA_DIR"
exit 1
fi
2023-01-04 06:23:28 +00:00
DATA_CLI_DIR=$(mktemp -d -t laconic_9000-cli-datadir.XXXXX)
2021-04-17 10:00:07 +00:00
if [[ ! "$DATA_CLI_DIR" ]]; then
echo "Could not create $DATA_CLI_DIR"
exit 1
fi
2022-10-12 11:54:07 +00:00
# Compile laconic
echo "compiling laconic"
make build
2021-04-17 10:00:07 +00:00
# PID array declaration
arr=()
# PID arraycli declaration
arrcli=()
init_func() {
echo "create and add new keys"
"$PWD"/build/laconicd keys add $KEY"$i" --home "$DATA_DIR$i" --no-backup --chain-id $CHAINID --algo "eth_secp256k1" --keyring-backend test
2021-04-17 10:00:07 +00:00
echo "init Ethermint with moniker=$MONIKER and chain-id=$CHAINID"
"$PWD"/build/laconicd init $MONIKER --chain-id $CHAINID --home "$DATA_DIR$i"
2021-04-17 10:00:07 +00:00
echo "prepare genesis: Allocate genesis accounts"
"$PWD"/build/laconicd add-genesis-account \
"$("$PWD"/build/laconicd keys show "$KEY$i" -a --home "$DATA_DIR$i" --keyring-backend test)" 1000000000000000000aphoton,1000000000000000000stake \
2021-05-25 08:46:10 +00:00
--home "$DATA_DIR$i" --keyring-backend test
2021-04-17 10:00:07 +00:00
echo "prepare genesis: Sign genesis transaction"
"$PWD"/build/laconicd gentx $KEY"$i" 1000000000000000000stake --keyring-backend test --home "$DATA_DIR$i" --keyring-backend test --chain-id $CHAINID
2021-04-17 10:00:07 +00:00
echo "prepare genesis: Collect genesis tx"
"$PWD"/build/laconicd collect-gentxs --home "$DATA_DIR$i"
2021-04-17 10:00:07 +00:00
echo "prepare genesis: Run validate-genesis to ensure everything worked and that the genesis file is setup correctly"
"$PWD"/build/laconicd validate-genesis --home "$DATA_DIR$i"
2021-04-17 10:00:07 +00:00
}
start_func() {
2022-10-10 10:38:33 +00:00
echo "starting ethermint node $i in background ..."
"$PWD"/build/laconicd start --pruning=nothing --rpc.unsafe \
2021-04-17 10:00:07 +00:00
--p2p.laddr tcp://$IP_ADDR:$NODE_P2P_PORT"$i" --address tcp://$IP_ADDR:$NODE_PORT"$i" --rpc.laddr tcp://$IP_ADDR:$NODE_RPC_PORT"$i" \
--json-rpc.address=$IP_ADDR:$RPC_PORT"$i" \
2022-10-10 10:38:33 +00:00
--keyring-backend test --home "$DATA_DIR$i" \
2021-04-17 10:00:07 +00:00
>"$DATA_DIR"/node"$i".log 2>&1 & disown
ETHERMINT_PID=$!
2022-10-10 10:38:33 +00:00
echo "started ethermint node, pid=$ETHERMINT_PID"
2021-04-17 10:00:07 +00:00
# add PID to array
arr+=("$ETHERMINT_PID")
}
# Run node with static blockchain database
# For loop N times
for i in $(seq 1 "$QTD"); do
init_func "$i"
start_func "$i"
sleep 1
echo "sleeping $SLEEP_TIMEOUT seconds for startup"
sleep "$SLEEP_TIMEOUT"
echo "done sleeping"
done
echo "sleeping $SLEEP_TIMEOUT seconds before running tests ... "
sleep "$SLEEP_TIMEOUT"
echo "done sleeping"
set +e
if [[ -z $TEST || $TEST == "rpc" ]]; then
for i in $(seq 1 "$TEST_QTD"); do
HOST_RPC=http://$IP_ADDR:$RPC_PORT"$i"
2022-10-10 10:38:33 +00:00
echo "going to test ethermint node $HOST_RPC ..."
MODE=$MODE HOST=$HOST_RPC go test ./tests/e2e/... -timeout=300s -v -short
MODE=$MODE HOST=$HOST_RPC go test ./tests/rpc/... -timeout=300s -v -short
TEST_FAIL=$?
2021-04-17 10:00:07 +00:00
done
fi
stop_func() {
ETHERMINT_PID=$i
echo "shutting down node, pid=$ETHERMINT_PID ..."
2022-10-10 10:38:33 +00:00
# Shutdown ethermint node
2021-04-17 10:00:07 +00:00
kill -9 "$ETHERMINT_PID"
wait "$ETHERMINT_PID"
}
for i in "${arrcli[@]}"; do
stop_func "$i"
done
for i in "${arr[@]}"; do
stop_func "$i"
done
if [[ (-z $TEST || $TEST == "rpc") && $TEST_FAIL -ne 0 ]]; then
exit $TEST_FAIL
2021-04-17 10:00:07 +00:00
else
exit 0
fi