From 4e5cdd6abb29fc9d2066f46cf692f8789aa9178e Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 6 Jul 2016 13:46:37 -0400 Subject: [PATCH] bash tests for broadcast_tx through rpc --- test/rpc/clean.sh | 3 ++ test/rpc/counter_test.sh | 72 ++++++++++++++++++++++++++++++++++++++++ test/rpc/dummy_test.sh | 34 +++++++++++++++++++ test/rpc/test.sh | 57 +++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 test/rpc/clean.sh create mode 100644 test/rpc/counter_test.sh create mode 100644 test/rpc/dummy_test.sh create mode 100644 test/rpc/test.sh diff --git a/test/rpc/clean.sh b/test/rpc/clean.sh new file mode 100644 index 00000000..1b34033f --- /dev/null +++ b/test/rpc/clean.sh @@ -0,0 +1,3 @@ +killall tendermint +killall dummy +killall counter diff --git a/test/rpc/counter_test.sh b/test/rpc/counter_test.sh new file mode 100644 index 00000000..bece2401 --- /dev/null +++ b/test/rpc/counter_test.sh @@ -0,0 +1,72 @@ +#! /bin/bash + +##################### +# counter over socket +##################### +TESTNAME=$1 + +# Send some txs + +function sendTx() { + TX=$1 + RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=\"$TX\"` + CODE=`echo $RESPONSE | jq .result[1].code` + ERROR=`echo $RESPONSE | jq .error` + ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes + echo "ERROR: $ERROR" + echo "CODE: $CODE" + echo "" +} + +# 0 should pass once and get in block, with no error +TX=00 +sendTx $TX +if [[ $CODE != 0 ]]; then + echo "Got non-zero exit code for $TX. $RESPONSE" + exit 1 +fi +if [[ "$ERROR" != "" ]]; then + echo "Unexpected error. Tx $TX should have been included in a block. $ERROR" + exit 1 +fi + + + +# second time should get rejected by the mempool (return error and non-zero code) +sendTx $TX +if [[ $CODE == 0 ]]; then + echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE" + exit 1 +fi +if [[ "$ERROR" == "" ]]; then + echo "Expected to get an error - tx $TX should have been rejected from mempool" + echo "$RESPONSE" + exit 1 +fi + + +# now, TX=01 should pass, with no error +TX=01 +sendTx $TX +if [[ $CODE != 0 ]]; then + echo "Got non-zero exit code for $TX. $RESPONSE" + exit 1 +fi +if [[ "$ERROR" != "" ]]; then + echo "Unexpected error. Tx $TX should have been accepted in block. $ERROR" + exit 1 +fi + +# now, TX=03 should get in a block (passes CheckTx, no error), but is invalid +TX=03 +sendTx $TX +if [[ $CODE == 0 ]]; then + echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE" + exit 1 +fi +if [[ "$ERROR" != "" ]]; then + echo "Unexpected error. Tx $TX should have been included in a block. $ERROR" + exit 1 +fi + +echo "Passed Test: $TESTNAME" diff --git a/test/rpc/dummy_test.sh b/test/rpc/dummy_test.sh new file mode 100644 index 00000000..9410c88d --- /dev/null +++ b/test/rpc/dummy_test.sh @@ -0,0 +1,34 @@ +#! /bin/bash + +function toHex() { + echo -n $1 | hexdump -ve '1/1 "%.2X"' +} + +##################### +# dummy with curl +##################### +TESTNAME=$1 + +# store key value pair +KEY="abcd" +VALUE="dcba" +curl localhost:46657/broadcast_tx_commit?tx=\"$(toHex $KEY=$VALUE)\" +echo "" + +# we should be able to look up the key +RESPONSE=`tmsp-cli query $KEY` +A=`echo $RESPONSE | grep exists=true` +if [[ $? != 0 ]]; then + echo "Failed to find 'exists=true' for $KEY. Response:" + echo "$RESPONSE" +fi + +# we should not be able to look up the value +RESPONSE=`tmsp-cli query $VALUE` +A=`echo $RESPONSE | grep exists=true` +if [[ $? == 0 ]]; then + echo "Found 'exists=true' for $VALUE when we should not have. Response:" + echo "$RESPONSE" +fi + +echo "Passed Test: $TESTNAME" diff --git a/test/rpc/test.sh b/test/rpc/test.sh new file mode 100644 index 00000000..f31b19c5 --- /dev/null +++ b/test/rpc/test.sh @@ -0,0 +1,57 @@ +#! /bin/bash +set -e + +#- dummy over socket, curl +#- counter over socket, curl +#- counter over grpc, curl +#- counter over grpc, grpc + +# TODO: install everything + +function dummy_over_socket(){ + dummy > /dev/null & + tendermint node > tendermint.log & + sleep 3 + + bash dummy_test.sh "Dummy over Socket" + + killall dummy tendermint +} + + +function counter_over_socket() { + counter --serial > /dev/null & + tendermint node > tendermint.log & + sleep 3 + + bash counter_test.sh "Counter over Socket" + + killall counter tendermint +} + +function counter_over_grpc() { + counter --serial --tmsp grpc > /dev/null & + tendermint node --tmsp grpc > tendermint.log & + sleep 3 + + bash counter_test.sh "Counter over GRPC" + + killall counter tendermint +} + +case "$1" in + "dummy_over_socket") + dummy_over_socket + ;; + "counter_over_socket") + counter_over_socket + ;; + "counter_over_grpc") + counter_over_grpc + ;; + *) + dummy_over_socket + counter_over_socket + counter_over_grpc +esac +