From d6348c009a211abd5fecaea8a6a229a5e982fc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 28 Aug 2017 18:34:36 +0200 Subject: [PATCH] Scripts/Test: more shared scripts... - introduced `test/utils/test_lib.inc.sh` to simplify usage of sandboxed node/client in the testsuite - it reuses code from `./script/{node,client}_lib.inc.sh` - use `wait_for_the_node_to_be_ready` to properly wait for the node to be launched rather to use a fexed delay - `test_multinode.sh` now launch 8 nodes. --- scripts/Dockerfile.build.in | 1 + scripts/client_lib.inc.sh | 36 ++++++- scripts/init-sandboxed-client.sh | 11 +- scripts/launch-sandboxed-node.sh | 27 ++--- scripts/node_lib.inc.sh | 44 ++++++++ test/lib/test_lib.inc.sh | 177 +++++++++++++++++++++++++++++++ test/test_basic.sh | 79 ++++++++------ test/test_contracts.sh | 73 +++++++------ test/test_multinode.sh | 134 +++++++++-------------- 9 files changed, 401 insertions(+), 181 deletions(-) create mode 100644 scripts/node_lib.inc.sh create mode 100755 test/lib/test_lib.inc.sh diff --git a/scripts/Dockerfile.build.in b/scripts/Dockerfile.build.in index b36eaf91c..d97f0a245 100644 --- a/scripts/Dockerfile.build.in +++ b/scripts/Dockerfile.build.in @@ -2,6 +2,7 @@ FROM $base_image COPY src /home/opam/tezos/src COPY test /home/opam/tezos/test +COPY scripts /home/opam/tezos/scripts RUN sudo chown -R opam /home/opam/tezos && \ echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \ diff --git a/scripts/client_lib.inc.sh b/scripts/client_lib.inc.sh index 798e65100..95681f05d 100644 --- a/scripts/client_lib.inc.sh +++ b/scripts/client_lib.inc.sh @@ -1,8 +1,27 @@ -#! /bin/sh +#! /usr/bin/env bash client_dir="${client_dir:=$HOME/.tezos-client}" client="${client:=tezos-client -base-dir $client_dir}" +client_dirs=() + +init_sandboxed_client() { + + id="$1" + shift 1 + + rpc=$((18730 + id)) + client_dir="$(mktemp -d -t tezos-client.XXXXXXXX)" + client_dirs+=("$client_dir") + client="$src_dir/tezos-client -base-dir $client_dir -addr 127.0.0.1 -port $rpc" + +} + +cleanup_clients() { + rm -rf "${client_dirs[@]}" +} + + ## Waiter ################################################################## wait_for_the_node_to_be_ready() { @@ -138,18 +157,23 @@ log_endorser() { # key pairs from $src_dir/test/sandbox.json +BOOTSTRAP1_IDENTITY="tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" BOOTSTRAP1_PUBLIC="edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" BOOTSTRAP1_SECRET="edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi" +BOOTSTRAP2_IDENTITY="tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" BOOTSTRAP2_PUBLIC="edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9" BOOTSTRAP2_SECRET="edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDbym9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc" +BOOTSTRAP3_IDENTITY="tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU" BOOTSTRAP3_PUBLIC="edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV" BOOTSTRAP3_SECRET="edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWBypUSbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC" +BOOTSTRAP4_IDENTITY="tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv" BOOTSTRAP4_PUBLIC="edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU" BOOTSTRAP4_SECRET="edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyPJdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL" +BOOTSTRAP5_IDENTITY="tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv" BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n" BOOTSTRAP5_SECRET="edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcCyM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ" @@ -175,3 +199,13 @@ add_sandboxed_bootstrap_identities() { ${client} add secret key dictator ${DICTATOR_SECRET} } + +activate_alpha() { + + ${client} \ + -block genesis \ + activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK \ + with fitness 1 \ + and key dictator + +} diff --git a/scripts/init-sandboxed-client.sh b/scripts/init-sandboxed-client.sh index 860df10a5..e01e8535d 100755 --- a/scripts/init-sandboxed-client.sh +++ b/scripts/init-sandboxed-client.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /usr/bin/env bash set -e @@ -18,15 +18,10 @@ if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then exit 1 fi -id="$1" -shift 1 - -rpc=$((18730 + id)) -client_dir="$(mktemp -td tezos-client-XXXXX)" -client="./tezos-client -base-dir $client_dir -addr 127.0.0.1 -port $rpc" - . "$script_dir/client_lib.inc.sh" +init_sandboxed_client "$1" + add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2 cat < LOG.$id 2>&1 + register_log LOG.$id + init_sandboxed_client $id + wait_for_the_node_to_be_ready + add_sandboxed_bootstrap_identities + client_instances+=("$client") + export "client$id=$client" +} + +cleanup() { + set -e + display_logs + cleanup_nodes + cleanup_clients +} +trap cleanup EXIT INT + +### Various helpers + +run_contract_file () { + local contract=$1 + local storage=$2 + local input=$3 + $client run program "$contract" on storage "$storage" and input "$input" +} + +assert_output () { + local contract=$1; + local input=$2; + local storage=$3; + local expected=$4; + echo "Testing [$contract]" + local output=$(run_contract_file "$contract" "$input" "$storage" | sed '1,/output/d' | + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' || + { printf '\nTest failed with error at line %s\n' "$(caller)" 1>&2; + exit 1; }); + if [ "$expected" != "$output" ]; then + echo "Test at " `caller` failed 1>&2 ; + printf "Expected %s but got %s" "$expected" "$output" 1>&2 ; + exit 1; + fi +} + +assert_balance () { + local KEY="$1" + local EXPECTED_BALANCE="$2" + local RESULT=$($client get balance for ${KEY}) + if [ "${RESULT}" != "${EXPECTED_BALANCE}" ]; then + printf "Balance assertion failed for ${KEY} on line '%s'. Expected %s but got %s.\n" \ + "$(caller)" "${EXPECTED_BALANCE}" "${RESULT}" + exit 2 + fi +} + +contract_name_of_file () { + basename "$1" ".tz" +} + +init_contract_from_file () { + local FILE="$1" + local NAME=$(contract_name_of_file "${FILE}") + $client remember program "${NAME}" "file:${FILE}" +} + +init_with_transfer () { + local FILE="$1" + local NAME=$(contract_name_of_file "${FILE}") + local KEY="$2" + local INITIAL_STORAGE="$3" + local TRANSFER_AMT="$4" + local TRANSFER_SRC=${5-bootstrap1} + echo "Originating [$NAME]" + $client originate contract ${NAME} \ + for ${KEY} transferring "${TRANSFER_AMT}" \ + from ${TRANSFER_SRC} running "${FILE}" -init "${INITIAL_STORAGE}" +} + +# Takes a grep regexp and fails with an error message if command does not include +# the regexp +assert_in_output () { + local MATCHING="$1" + local INPUT="$2" + if ! grep -q "${MATCHING}" ${INPUT}; then + printf "\nFailure on line %s. Expected to find %s in output." \ + "$(caller)" "${MATCHING}" + exit 1 + else + echo "[Assertion succeeded]" + fi +} + +get_contract_addr () { + local CONTRACT_NAME="$1" + $client show known contract "${CONTRACT_NAME}" +} + +contract_storage () { + local CONTRACT_NAME="$1" # Can be either an alias or hash + $client get storage for ${CONTRACT_NAME} +} + +assert_storage_contains () { + local CONTRACT_NAME="$1" + local EXPECTED_STORAGE="$2" + contract_storage ${CONTRACT_NAME} | assert_in_output ${EXPECTED_STORAGE} +} + +assert() { + local expected="$1" + local result="$(cat)" + if [ "${result}" != "${expected}" ]; then + echo "Unexpected result: \"${result}\"" + echo "Expected: \"${expected}\"" + exit 2 + fi +} + +assert_fails() { + printf "[Asserting failure]\n" + if "$@" 2> /dev/null; then + printf "Expected command line to fail, but succeeded:\n" + echo "$@" + exit 1 + else + return 0 + fi +} + +extract_operation_hash() { + grep "Operation hash is" | grep -o "'.*'" | tr -d "'" +} diff --git a/test/test_basic.sh b/test/test_basic.sh index 465e6bbfd..f0cec55aa 100755 --- a/test/test_basic.sh +++ b/test/test_basic.sh @@ -1,57 +1,66 @@ -#!/bin/bash +#! /usr/bin/env bash set -e -source test_utils.sh +test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" +source $test_dir/lib/test_lib.inc.sh -start_sandboxed_node -sleep 3 +start_node 1 activate_alpha -add_bootstrap_identities +key1=foo +key2=bar -${TZCLIENT} list known identities +$client gen keys $key1 +$client gen keys $key2 -${TZCLIENT} transfer 1000 from bootstrap1 to ${KEY1} -${TZCLIENT} transfer 2000 from bootstrap1 to ${KEY2} +$client list known identities -${TZCLIENT} get balance for ${KEY1} | assert "1,000.00 ꜩ" -${TZCLIENT} get balance for ${KEY2} | assert "2,000.00 ꜩ" +$client transfer 1000 from bootstrap1 to $key1 +$client transfer 2000 from bootstrap1 to $key2 -${TZCLIENT} transfer 1000 from ${KEY2} to ${KEY1} +$client get balance for $key1 | assert "1,000.00 ꜩ" +$client get balance for $key2 | assert "2,000.00 ꜩ" -${TZCLIENT} get balance for ${KEY1} | assert "2,000.00 ꜩ" -${TZCLIENT} get balance for ${KEY2} | assert "999.95 ꜩ" +$client transfer 1000 from $key2 to $key1 + +$client get balance for $key1 | assert "2,000.00 ꜩ" +$client get balance for $key2 | assert "999.95 ꜩ" # Should fail -# ${TZCLIENT} transfer 999.95 from ${KEY2} to ${KEY1} +# $client transfer 999.95 from $key2 to $key1 -${TZCLIENT} mine for bootstrap1 +# wait for the delay between two block +sleep 1 -${TZCLIENT} remember program noop file:contracts/noop.tz -${TZCLIENT} typecheck program noop -${TZCLIENT} originate contract noop \ - for ${KEY1} transferring 1000 from bootstrap1 \ - running noop -${TZCLIENT} transfer 10 from bootstrap1 to noop -arg "Unit" +$client mine for bootstrap1 -${TZCLIENT} originate contract hardlimit \ - for ${KEY1} transferring 1000 from bootstrap1 \ - running file:contracts/hardlimit.tz -init "3" -${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit" -${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit" -# ${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail +$client remember program noop file:contracts/noop.tz +$client typecheck program noop +$client originate contract noop \ + for $key1 transferring 1000 from bootstrap1 \ + running noop +$client transfer 10 from bootstrap1 to noop -arg "Unit" -${TZCLIENT} originate free account free_account for ${KEY1} -${TZCLIENT} get delegate for free_account -${TZCLIENT} set delegate for free_account to ${KEY2} -${TZCLIENT} get delegate for free_account +$client originate contract hardlimit \ + for $key1 transferring 1000 from bootstrap1 \ + running file:contracts/hardlimit.tz -init "3" +$client transfer 10 from bootstrap1 to hardlimit -arg "Unit" +$client transfer 10 from bootstrap1 to hardlimit -arg "Unit" +# $client transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail -${TZCLIENT} get balance for bootstrap5 | assert "4,000,000.00 ꜩ" -${TZCLIENT} transfer 4000000.00 from bootstrap5 to bootstrap1 -fee 0 -${TZCLIENT} transfer 4000000.00 from bootstrap1 to bootstrap5 -fee 0 -${TZCLIENT} get balance for bootstrap5 | assert "4,000,000.00 ꜩ" +$client originate free account free_account for $key1 +$client get delegate for free_account +$client set delegate for free_account to $key2 +$client get delegate for free_account + +$client get balance for bootstrap5 | assert "4,000,000.00 ꜩ" +$client transfer 4000000.00 from bootstrap5 to bootstrap1 -fee 0 +$client transfer 4000000.00 from bootstrap1 to bootstrap5 -fee 0 +$client get balance for bootstrap5 | assert "4,000,000.00 ꜩ" echo echo End of test echo + +show_logs="no" diff --git a/test/test_contracts.sh b/test/test_contracts.sh index 85597b49f..426a3260e 100755 --- a/test/test_contracts.sh +++ b/test/test_contracts.sh @@ -1,17 +1,19 @@ #!/bin/bash set -e - set -o pipefail -source test_utils.sh - -start_sandboxed_node -sleep 3 +test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" +source $test_dir/lib/test_lib.inc.sh +start_node 1 activate_alpha -add_bootstrap_identities +key1=foo +key2=bar + +$client gen keys $key1 +$client gen keys $key2 printf "\n\n" @@ -203,67 +205,68 @@ assert_output $CONTRACT_PATH/check_signature.tz \ '(Pair "26981d372a7b3866621bf79713d249197fe6d518ef702fa65738e1715bde9da54df04fefbcc84287ecaa9f74ad9296462731aa24bbcece63c6bf73a8f5752309" "abcd")' \ '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' False +$client transfer 1000 from bootstrap1 to $key1 +$client transfer 2000 from bootstrap1 to $key2 -${TZCLIENT} transfer 1000 from bootstrap1 to ${KEY1} -${TZCLIENT} transfer 2000 from bootstrap1 to ${KEY2} - -assert_balance ${KEY1} "1,000.00 ꜩ" -assert_balance ${KEY2} "2,000.00 ꜩ" +assert_balance $key1 "1,000.00 ꜩ" +assert_balance $key2 "2,000.00 ꜩ" # Create a contract and transfer 100 ꜩ to it -init_with_transfer $CONTRACT_PATH/store_input.tz ${KEY1} '""' 100 bootstrap1 -${TZCLIENT} transfer 100 from bootstrap1 to store_input -arg '"abcdefg"' +init_with_transfer $CONTRACT_PATH/store_input.tz $key1 '""' 100 bootstrap1 +$client transfer 100 from bootstrap1 to store_input -arg '"abcdefg"' assert_balance store_input "200.00 ꜩ" assert_storage_contains store_input '"abcdefg"' -${TZCLIENT} transfer 100 from bootstrap1 to store_input -arg '"xyz"' +$client transfer 100 from bootstrap1 to store_input -arg '"xyz"' assert_storage_contains store_input '"xyz"' -init_with_transfer $CONTRACT_PATH/transfer_amount.tz ${KEY1} '"0"' "100" bootstrap1 -${TZCLIENT} transfer 500 from bootstrap1 to transfer_amount -arg Unit +init_with_transfer $CONTRACT_PATH/transfer_amount.tz $key1 '"0"' "100" bootstrap1 +$client transfer 500 from bootstrap1 to transfer_amount -arg Unit assert_storage_contains transfer_amount 500 # This tests the `NOW` instruction. # This test may fail if timings are marginal, though I have not yet seen this happen -init_with_transfer $CONTRACT_PATH/store_now.tz ${KEY1} '"2017-07-13T09:19:01Z"' "100" bootstrap1 -${TZCLIENT} transfer 500 from bootstrap1 to store_now -arg Unit -assert_storage_contains store_now "$(${TZCLIENT} get timestamp)" +init_with_transfer $CONTRACT_PATH/store_now.tz $key1 '"2017-07-13T09:19:01Z"' "100" bootstrap1 +$client transfer 500 from bootstrap1 to store_now -arg Unit +assert_storage_contains store_now "$($client get timestamp)" # Tests TRANSFER_TO -${TZCLIENT} originate account "test_transfer_account1" for ${KEY1} transferring 100 from bootstrap1 -${TZCLIENT} originate account "test_transfer_account2" for ${KEY1} transferring 20 from bootstrap1 -init_with_transfer $CONTRACT_PATH/transfer_to.tz ${KEY2} Unit 1000 bootstrap1 +$client originate account "test_transfer_account1" for $key1 transferring 100 from bootstrap1 +$client originate account "test_transfer_account2" for $key1 transferring 20 from bootstrap1 +init_with_transfer $CONTRACT_PATH/transfer_to.tz $key2 Unit 1000 bootstrap1 assert_balance test_transfer_account1 "100.00 ꜩ" -${TZCLIENT} transfer 100 from bootstrap1 to transfer_to \ +$client transfer 100 from bootstrap1 to transfer_to \ -arg "\"$(get_contract_addr test_transfer_account1)\"" assert_balance test_transfer_account1 "200.00 ꜩ" # Why isn't this 200 ꜩ? Mining fee? -${TZCLIENT} transfer 100 from bootstrap1 to transfer_to \ +$client transfer 100 from bootstrap1 to transfer_to \ -arg "\"$(get_contract_addr test_transfer_account2)\"" assert_balance test_transfer_account2 "120.00 ꜩ" # Why isn't this 120 ꜩ? Mining fee? # Tests create_account -init_with_transfer $CONTRACT_PATH/create_account.tz ${KEY2} \ +init_with_transfer $CONTRACT_PATH/create_account.tz $key2 \ "\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1 -${TZCLIENT} transfer 100 from bootstrap1 to create_account \ +$client transfer 100 from bootstrap1 to create_account \ -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' | assert_in_output "New contract" # Creates a contract, transfers data to it and stores the data -init_with_transfer $CONTRACT_PATH/create_contract.tz ${KEY2} \ +init_with_transfer $CONTRACT_PATH/create_contract.tz $key2 \ "\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1 -${TZCLIENT} transfer 0.00 from bootstrap1 to create_contract -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' +$client transfer 0.00 from bootstrap1 to create_contract -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' assert_storage_contains create_contract '"abcdefg"' # Test DEFAULT_ACCOUNT -init_with_transfer $CONTRACT_PATH/default_account.tz ${KEY1} \ +init_with_transfer $CONTRACT_PATH/default_account.tz $key1 \ Unit 1000 bootstrap1 -${TZCLIENT} transfer 0.00 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\"" +$client transfer 0.00 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\"" assert_balance $BOOTSTRAP4_IDENTITY "4,000,100.00 ꜩ" account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5 -${TZCLIENT} transfer 0.00 from bootstrap1 to default_account -arg "\"$account\"" +$client transfer 0.00 from bootstrap1 to default_account -arg "\"$account\"" assert_balance $account "100.00 ꜩ" -assert_fails ${TZCLIENT} typecheck data '(Map (Item 0 1) (Item 0 1))' against type '(map nat nat)' -assert_fails ${TZCLIENT} typecheck data '(Map (Item 0 1) (Item 10 1) (Item 5 1))' against type '(map nat nat)' -assert_fails ${TZCLIENT} typecheck data '(Set "A" "C" "B")' against type '(set string)' -assert_fails ${TZCLIENT} typecheck data '(Set "A" "B" "B")' against type '(set string)' +assert_fails $client typecheck data '(Map (Item 0 1) (Item 0 1))' against type '(map nat nat)' +assert_fails $client typecheck data '(Map (Item 0 1) (Item 10 1) (Item 5 1))' against type '(map nat nat)' +assert_fails $client typecheck data '(Set "A" "C" "B")' against type '(set string)' +assert_fails $client typecheck data '(Set "A" "B" "B")' against type '(set string)' printf "\nEnd of test\n" + +show_logs="no" diff --git a/test/test_multinode.sh b/test/test_multinode.sh index 15f35df0e..f3037dd29 100755 --- a/test/test_multinode.sh +++ b/test/test_multinode.sh @@ -1,116 +1,88 @@ #!/usr/bin/env bash -source test_utils.sh +set -e -export LWT_ASYNC_METHOD="none" +test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" +source $test_dir/lib/test_lib.inc.sh -node1_rpcs=3000 -node1_addr=[::1]:3001 -node2_rpcs=3002 -node2_addr=[::1]:3003 -node3_rpcs=3004 -node3_addr=[::1]:3005 -node4_rpcs=3006 -node4_addr=[::1]:3007 - -CLIENT_1="$(make_client) -addr [::1] -port $node1_rpcs" -CLIENT_2="$(make_client) -addr [::1] -port $node2_rpcs" -CLIENT_3="$(make_client) -addr [::1] -port $node3_rpcs" -CLIENT_4="$(make_client) -addr [::1] -port $node4_rpcs" +expected_connections=3 +max_peer_id=8 +for i in $(seq 1 $max_peer_id); do + echo + echo "## Starting node $i." + echo + start_node $i + echo +done +## waiting for the node to establich connections +sleep 2 +for client in "${client_instances[@]}"; do + echo + echo "### $client network stat" + echo + $client network stat + echo +done +activate_alpha +sleep 5 assert_propagation_level() { level=$1 printf "\n\nAsserting all nodes have reached level %s\n" "$level" - ${CLIENT_1} rpc call /blocks/head/proto/context/level \ - | assert_in_output "\"level\": $level" - ${CLIENT_2} rpc call /blocks/head/proto/context/level \ - | assert_in_output "\"level\": $level" - ${CLIENT_3} rpc call /blocks/head/proto/context/level \ - | assert_in_output "\"level\": $level" - ${CLIENT_4} rpc call /blocks/head/proto/context/level \ - | assert_in_output "\"level\": $level" + for client in "${client_instances[@]}"; do + $client rpc call /blocks/head/proto/context/level \ + | assert_in_output "\"level\": $level" + done } -start_sandboxed_node --rpc-addr=[::1]:$node1_rpcs --net-addr=$node1_addr --peer=$node2_addr --no-bootstrap-peers -start_sandboxed_node --rpc-addr=[::1]:$node2_rpcs --net-addr=$node2_addr --peer=$node1_addr --no-bootstrap-peers -start_sandboxed_node --rpc-addr=[::1]:$node3_rpcs --net-addr=$node3_addr --peer=$node1_addr --no-bootstrap-peers -start_sandboxed_node --rpc-addr=[::1]:$node4_rpcs --net-addr=$node4_addr --peer=$node1_addr --no-bootstrap-peers - -sleep 3 - -printf "\n\n" - -activate_alpha [::1] $node1_rpcs - -sleep 3 - printf "\n\nAsserting protocol propagation\n" -${CLIENT_1} rpc call /blocks/head/protocol \ - | assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" -${CLIENT_2} rpc call /blocks/head/protocol \ - | assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" -${CLIENT_3} rpc call /blocks/head/protocol \ - | assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" -${CLIENT_4} rpc call /blocks/head/protocol \ - | assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" +for client in "${client_instances[@]}"; do + $client rpc call /blocks/head/protocol \ + | assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" +done printf "\n\n" -add_bootstrap_identities "${CLIENT_1}" -add_bootstrap_identities "${CLIENT_2}" -add_bootstrap_identities "${CLIENT_3}" -add_bootstrap_identities "${CLIENT_4}" - -printf "\n\n" - -${CLIENT_1} mine for bootstrap1 - -sleep 3 - +$client1 mine for bootstrap1 +sleep 5 assert_propagation_level 2 -${CLIENT_2} mine for bootstrap2 - -sleep 3 +$client2 mine for bootstrap2 +sleep 5 assert_propagation_level 3 -${CLIENT_3} mine for bootstrap3 - -sleep 3 +$client3 mine for bootstrap3 +sleep 5 assert_propagation_level 4 -${CLIENT_4} mine for bootstrap4 - -sleep 3 +$client4 mine for bootstrap4 +sleep 5 assert_propagation_level 5 -endorse_hash=$(${CLIENT_3} endorse for bootstrap3 | extract_operation_hash) +endorse_hash=$($client3 endorse for bootstrap3 | extract_operation_hash) +transfer_hash=$($client4 transfer 500 from bootstrap1 to bootstrap3 | extract_operation_hash) +sleep 5 -transfer_hash=$(${CLIENT_4} transfer 500 from bootstrap1 to bootstrap3 | extract_operation_hash) - -sleep 3 - -${CLIENT_4} mine for bootstrap4 - -sleep 3 +$client4 mine for bootstrap4 +sleep 5 assert_contains_operation() { hash="$1" printf "Asserting operations list contains '$hash'\n" - ${CLIENT_1} rpc call /blocks/head/operations with {} \ - | assert_in_output $hash - ${CLIENT_2} rpc call /blocks/head/operations with {} \ - | assert_in_output $hash - ${CLIENT_3} rpc call /blocks/head/operations with {} \ - | assert_in_output $hash - ${CLIENT_4} rpc call /blocks/head/operations with {} \ - | assert_in_output $hash + for client in "${client_instances[@]}"; do + $client rpc call /blocks/head/operations with {} \ + | assert_in_output $hash + done } assert_contains_operation $endorse_hash assert_contains_operation $transfer_hash -# printf "\nEnd of test" +echo +echo End of test +echo + +show_logs="no"