tendermint/tests/test_dummy.sh

62 lines
1.2 KiB
Bash
Raw Normal View History

2015-11-30 22:49:54 -08:00
#! /bin/bash
function finish {
echo "Cleaning up..."
ps -p $PID > /dev/null
if [[ "$?" == "0" ]]; then
kill -9 $PID
fi
}
trap finish EXIT
2015-11-30 22:49:54 -08:00
# Make sure the tmsp cli can connect to the dummy
echo "Dummy test ..."
dummy &> /dev/null &
PID=`echo $!`
sleep 1
2016-01-08 13:06:33 -08:00
RESULT_HASH=`tmsp-cli get_hash`
2015-11-30 22:49:54 -08:00
if [[ "$RESULT_HASH" != "" ]]; then
echo "Expected nothing but got: $RESULT_HASH"
exit 1
fi
echo "... Pass!"
echo ""
# Add a tx, get hash, get hash
2015-11-30 22:49:54 -08:00
# hashes should be non-empty and identical
echo "Dummy batch test ..."
2016-01-08 13:06:33 -08:00
OUTPUT=`(tmsp-cli batch) <<STDIN
2015-11-30 22:49:54 -08:00
append_tx abc
get_hash
get_hash
STDIN`
HASH1=`echo "$OUTPUT" | tail -n 2 | head -n 1`
2015-11-30 22:49:54 -08:00
HASH2=`echo "$OUTPUT" | tail -n 1`
if [[ "$HASH1" == "" ]]; then
echo "Expected non empty hash!"
exit 1
fi
2016-01-08 13:06:33 -08:00
if [[ "$HASH1" == "EOF" ]]; then
echo "Expected hash not broken connection!"
exit 1
fi
2015-11-30 22:49:54 -08:00
if [[ "$HASH1" != "$HASH2" ]]; then
echo "Expected first and second hashes to match: $HASH1, $HASH2"
2015-11-30 22:49:54 -08:00
exit 1
fi
echo "... Pass!"
echo ""
# Start a new connection and ensure the hash is the same
echo "New connection test ..."
2016-01-08 13:06:33 -08:00
RESULT_HASH=`tmsp-cli get_hash`
2015-11-30 22:49:54 -08:00
if [[ "$HASH1" != "$RESULT_HASH" ]]; then
echo "Expected hash to persist as $HASH1 for new connection. Got $RESULT_HASH"
exit 1
fi
echo "... Pass!"
echo ""