tendermint/tests/test_counter.sh

79 lines
1.3 KiB
Bash
Raw Normal View History

#! /bin/bash
function finish {
echo "Cleaning up..."
ps -p $PID > /dev/null
if [[ "$?" == "0" ]]; then
kill -9 $PID
fi
}
trap finish EXIT
2015-12-14 15:00:18 -08:00
# so we can test other languages
if [[ "$COUNTER_APP" == "" ]]; then
COUNTER_APP="counter"
fi
echo "Testing counter app for: $COUNTER_APP"
# run the counter app
$COUNTER_APP &> /dev/null &
PID=`echo $!`
if [[ "$?" != 0 ]]; then
2015-12-18 17:44:48 -08:00
echo "Error running tmsp app"
2015-12-14 15:00:18 -08:00
echo $OUTPUT
exit 1
fi
sleep 1
2016-01-08 13:06:33 -08:00
OUTPUT=`(tmsp-cli batch) <<STDIN
2015-12-14 15:00:18 -08:00
set_option serial on
get_hash
append_tx abc
STDIN`
if [[ "$?" != 0 ]]; then
2015-12-18 17:44:48 -08:00
echo "Error running tmsp batch command"
2015-12-14 15:00:18 -08:00
echo $OUTPUT
exit 1
fi
# why can't we pick up the non-zero exit code here?
# echo $?
HASH1=`echo "$OUTPUT" | tail -n +2 | head -n 1`
if [[ "${HASH1}" != "" ]]; then
echo "Expected opening hash to be empty. Got $HASH1"
exit 1
fi
2016-01-08 13:06:33 -08:00
OUTPUT=`(tmsp-cli batch) <<STDIN
2015-12-14 15:00:18 -08:00
set_option serial on
append_tx 0x00
get_hash
append_tx 0x01
get_hash
STDIN`
if [[ "$?" != 0 ]]; then
echo "Error running tmsp command"
echo $OUTPUT
exit 1
fi
HASH1=`echo "$OUTPUT" | tail -n +3 | head -n 1`
HASH2=`echo "$OUTPUT" | tail -n +5 | head -n 1`
if [[ "${HASH1: -2}" != "01" ]]; then
2015-12-14 15:00:18 -08:00
echo "Expected hash to lead with 01. Got $HASH1"
exit 1
fi
if [[ "${HASH2: -2}" != "02" ]]; then
2015-12-14 15:00:18 -08:00
echo "Expected hash to lead with 02. Got $HASH2"
exit 1
fi
echo "... Pass!"
echo ""