From 1c3880519b287d2b58b1790f548993af410c06ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sat, 2 Jun 2018 19:06:39 +0200 Subject: [PATCH] Shell: add test for protocol propagation --- src/bin_client/test/test_injection.sh | 34 ++++++++++++++++++----- src/bin_client/test/test_lib.inc.sh | 38 ++++++++++++++++++++++++++ src/bin_client/test/test_multinode.sh | 39 --------------------------- 3 files changed, 65 insertions(+), 46 deletions(-) diff --git a/src/bin_client/test/test_injection.sh b/src/bin_client/test/test_injection.sh index 31dc853d1..00ff484bd 100755 --- a/src/bin_client/test/test_injection.sh +++ b/src/bin_client/test/test_injection.sh @@ -7,9 +7,26 @@ set -e test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" source $test_dir/test_lib.inc.sh "$@" -start_node 1 +expected_connections=2 +max_peer_id=3 +for i in $(seq 1 $max_peer_id); do + echo + echo "## Starting node $i." + echo + start_node $i + echo +done -show_logs="no" +## waiting for the node to establish connections + +for client in "${client_instances[@]}"; do + echo + echo "### $client bootstrapped" + echo + $client -w none config update + $client bootstrapped + echo +done sleep 2 @@ -18,13 +35,16 @@ protocol_version="PsgZ1PB2h82sTKznNbmZxtbsU432eKDv1W6cf1cJFhCFmGYSiJs" $admin_client inject protocol "$test_dir/demo" $admin_client list protocols -$client activate protocol $protocol_version with fitness 1 and key dictator and parameters $parameters_file -answ=$($client -p ProtoALphaALph rpc get /chains/main/blocks/head/metadata 2>/dev/null) -if ! grep "\"next_protocol\": \"$protocol_version\"" <<< $answ ; then - exit 1 -fi +$client activate protocol $protocol_version \ + with fitness 1 \ + and key dictator \ + and parameters $parameters_file + +retry 2 15 assert_protocol "$protocol_version" echo echo End of test echo + +show_logs="no" diff --git a/src/bin_client/test/test_lib.inc.sh b/src/bin_client/test/test_lib.inc.sh index dcd0756f8..28325a15b 100755 --- a/src/bin_client/test/test_lib.inc.sh +++ b/src/bin_client/test/test_lib.inc.sh @@ -225,3 +225,41 @@ assert_contract_fails() { extract_operation_hash() { grep "Operation hash is" | grep -o "'.*'" | tr -d "'" } + +assert_propagation_level() { + level=$1 + printf "\n\nAsserting all nodes have reached level %s\n" "$level" + for client in "${client_instances[@]}"; do + ( $client rpc get /chains/main/blocks/head/header/shell \ + | assert_in_output "\"level\": $level" ) \ + || exit 2 + done +} + +assert_protocol() { + proto=$1 + printf "\n\nAsserting protocol propagation\n" + for client in "${client_instances[@]}"; do + ( $client -p ProtoGenesisG rpc get /chains/main/blocks/head/metadata | assert_in_output "\"next_protocol\": \"$proto\"" ) \ + || exit 2 + done +} + +retry() { + local timeout=$1 + local attempts=$2 + shift 2 + sleep $timeout + while ! ( "$@" ) ; do + echo + echo "Will retry after $timeout seconds..." + echo + sleep $timeout + attempts=$(($attempts-1)) + if [ "$attempts" -eq 0 ] ; then + echo + echo "Failed after too many retries" 1>&2 + exit 1 + fi + done +} diff --git a/src/bin_client/test/test_multinode.sh b/src/bin_client/test/test_multinode.sh index 6e48e9d42..9ef9d5dce 100755 --- a/src/bin_client/test/test_multinode.sh +++ b/src/bin_client/test/test_multinode.sh @@ -36,48 +36,9 @@ done activate_alpha -assert_propagation_level() { - level=$1 - printf "\n\nAsserting all nodes have reached level %s\n" "$level" - for client in "${client_instances[@]}"; do - ( $client rpc get /chains/main/blocks/head/header/shell \ - | assert_in_output "\"level\": $level" ) \ - || exit 2 - done -} - - -assert_protocol() { - proto=$1 - printf "\n\nAsserting protocol propagation\n" - for client in "${client_instances[@]}"; do - ( $client rpc get /chains/main/blocks/head/metadata | assert_in_output "\"next_protocol\": \"$proto\"" ) \ - || exit 2 - done -} - printf "\n\n" -retry() { - local timeout=$1 - local attempts=$2 - shift 2 - sleep $timeout - while ! ( "$@" ) ; do - echo - echo "Will retry after $timeout seconds..." - echo - sleep $timeout - attempts=$(($attempts-1)) - if [ "$attempts" -eq 0 ] ; then - echo - echo "Failed after too many retries" 1>&2 - exit 1 - fi - done -} - retry 2 15 assert_protocol "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" $client1 bake for bootstrap1 --max-priority 512 --minimal-timestamp