Shell: add test for protocol propagation

This commit is contained in:
Grégoire Henry 2018-06-02 19:06:39 +02:00 committed by Benjamin Canou
parent 5fd5c1c5f7
commit 1c3880519b
3 changed files with 65 additions and 46 deletions

View File

@ -7,9 +7,26 @@ set -e
test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")" test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")"
source $test_dir/test_lib.inc.sh "$@" 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 sleep 2
@ -18,13 +35,16 @@ protocol_version="PsgZ1PB2h82sTKznNbmZxtbsU432eKDv1W6cf1cJFhCFmGYSiJs"
$admin_client inject protocol "$test_dir/demo" $admin_client inject protocol "$test_dir/demo"
$admin_client list protocols $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 $client activate protocol $protocol_version \
exit 1 with fitness 1 \
fi and key dictator \
and parameters $parameters_file
retry 2 15 assert_protocol "$protocol_version"
echo echo
echo End of test echo End of test
echo echo
show_logs="no"

View File

@ -225,3 +225,41 @@ assert_contract_fails() {
extract_operation_hash() { extract_operation_hash() {
grep "Operation hash is" | grep -o "'.*'" | tr -d "'" 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
}

View File

@ -36,48 +36,9 @@ done
activate_alpha 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" 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" retry 2 15 assert_protocol "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
$client1 bake for bootstrap1 --max-priority 512 --minimal-timestamp $client1 bake for bootstrap1 --max-priority 512 --minimal-timestamp