postmerge

This commit is contained in:
Ethan Buchman
2017-04-21 18:09:47 -04:00
parent 93c58d0b24
commit 5da9b3a803
88 changed files with 0 additions and 0 deletions

4
test/app/clean.sh Normal file
View File

@@ -0,0 +1,4 @@
killall tendermint
killall dummy
killall counter
rm -rf ~/.tendermint_app

118
test/app/counter_test.sh Normal file
View File

@@ -0,0 +1,118 @@
#! /bin/bash
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
GRPC_BROADCAST_TX=""
fi
set -u
#####################
# counter over socket
#####################
TESTNAME=$1
# Send some txs
function getCode() {
R=$1
if [[ "$R" == "{}" ]]; then
# protobuf auto adds `omitempty` to everything so code OK and empty data/log
# will not even show when marshalled into json
# apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
echo 0
else
# this wont actually work if theres an error ...
echo "$R" | jq .code
fi
}
function sendTx() {
TX=$1
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=0x$TX`
ERROR=`echo $RESPONSE | jq .error`
ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
RESPONSE=`echo $RESPONSE | jq .result[1]`
else
if [ -f grpc_client ]; then
rm grpc_client
fi
echo "... building grpc_client"
go build -o grpc_client grpc_client.go
RESPONSE=`./grpc_client $TX`
ERROR=""
fi
echo "RESPONSE"
echo $RESPONSE
echo $RESPONSE | jq . &> /dev/null
IS_JSON=$?
if [[ "$IS_JSON" != "0" ]]; then
ERROR="$RESPONSE"
fi
APPEND_TX_RESPONSE=`echo $RESPONSE | jq .deliver_tx`
APPEND_TX_CODE=`getCode "$APPEND_TX_RESPONSE"`
CHECK_TX_RESPONSE=`echo $RESPONSE | jq .check_tx`
CHECK_TX_CODE=`getCode "$CHECK_TX_RESPONSE"`
echo "-------"
echo "TX $TX"
echo "RESPONSE $RESPONSE"
echo "ERROR $ERROR"
echo "----"
if [[ "$ERROR" != "" ]]; then
echo "Unexpected error sending tx ($TX): $ERROR"
exit 1
fi
}
echo "... sending tx. expect no error"
# 0 should pass once and get in block, with no error
TX=00
sendTx $TX
if [[ $APPEND_TX_CODE != 0 ]]; then
echo "Got non-zero exit code for $TX. $RESPONSE"
exit 1
fi
echo "... sending tx. expect error"
# second time should get rejected by the mempool (return error and non-zero code)
sendTx $TX
echo "CHECKTX CODE: $CHECK_TX_CODE"
if [[ "$CHECK_TX_CODE" == 0 ]]; then
echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE"
exit 1
fi
echo "... sending tx. expect no error"
# now, TX=01 should pass, with no error
TX=01
sendTx $TX
if [[ $APPEND_TX_CODE != 0 ]]; then
echo "Got non-zero exit code for $TX. $RESPONSE"
exit 1
fi
echo "... sending tx. expect no error, but invalid"
# now, TX=03 should get in a block (passes CheckTx, no error), but is invalid
TX=03
sendTx $TX
if [[ "$CHECK_TX_CODE" != 0 ]]; then
echo "Got non-zero exit code for checktx on $TX. $RESPONSE"
exit 1
fi
if [[ $APPEND_TX_CODE == 0 ]]; then
echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE"
exit 1
fi
echo "Passed Test: $TESTNAME"

84
test/app/dummy_test.sh Normal file
View File

@@ -0,0 +1,84 @@
#! /bin/bash
set -e
function toHex() {
echo -n $1 | hexdump -ve '1/1 "%.2X"' | awk '{print "0x" $0}'
}
#####################
# dummy with curl
#####################
TESTNAME=$1
# store key value pair
KEY="abcd"
VALUE="dcba"
echo $(toHex $KEY=$VALUE)
curl -s 127.0.0.1:46657/broadcast_tx_commit?tx=$(toHex $KEY=$VALUE)
echo $?
echo ""
###########################
# test using the abci-cli
###########################
echo "... testing query with abci-cli"
# we should be able to look up the key
RESPONSE=`abci-cli query \"$KEY\"`
set +e
A=`echo $RESPONSE | grep "$VALUE"`
if [[ $? != 0 ]]; then
echo "Failed to find $VALUE for $KEY. Response:"
echo "$RESPONSE"
exit 1
fi
set -e
# we should not be able to look up the value
RESPONSE=`abci-cli query \"$VALUE\"`
set +e
A=`echo $RESPONSE | grep $VALUE`
if [[ $? == 0 ]]; then
echo "Found '$VALUE' for $VALUE when we should not have. Response:"
echo "$RESPONSE"
exit 1
fi
set -e
#############################
# test using the /abci_query
#############################
echo "... testing query with /abci_query 2"
# we should be able to look up the key
RESPONSE=`curl -s "127.0.0.1:46657/abci_query?path=\"\"&data=$(toHex $KEY)&prove=false"`
RESPONSE=`echo $RESPONSE | jq .result[1].response.log`
set +e
A=`echo $RESPONSE | grep 'exists'`
if [[ $? != 0 ]]; then
echo "Failed to find 'exists' for $KEY. Response:"
echo "$RESPONSE"
exit 1
fi
set -e
# we should not be able to look up the value
RESPONSE=`curl -s "127.0.0.1:46657/abci_query?path=\"\"&data=$(toHex $VALUE)&prove=false"`
RESPONSE=`echo $RESPONSE | jq .result[1].response.log`
set +e
A=`echo $RESPONSE | grep 'exists'`
if [[ $? == 0 ]]; then
echo "Found 'exists' for $VALUE when we should not have. Response:"
echo "$RESPONSE"
exit 1
fi
set -e
echo "Passed Test: $TESTNAME"

36
test/app/grpc_client.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"encoding/hex"
"fmt"
"os"
"golang.org/x/net/context"
"github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/rpc/grpc"
)
var grpcAddr = "tcp://localhost:36656"
func main() {
args := os.Args
if len(args) == 1 {
fmt.Println("Must enter a transaction to send (hex)")
os.Exit(1)
}
tx := args[1]
txBytes, err := hex.DecodeString(tx)
if err != nil {
fmt.Println("Invalid hex", err)
os.Exit(1)
}
clientGRPC := core_grpc.StartGRPCClient(grpcAddr)
res, err := clientGRPC.BroadcastTx(context.Background(), &core_grpc.RequestBroadcastTx{txBytes})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(string(wire.JSONBytes(res)))
}

128
test/app/test.sh Normal file
View File

@@ -0,0 +1,128 @@
#! /bin/bash
set -e
#- dummy over socket, curl
#- counter over socket, curl
#- counter over grpc, curl
#- counter over grpc, grpc
# TODO: install everything
export TMHOME=$HOME/.tendermint_app
function dummy_over_socket(){
rm -rf $TMHOME
tendermint init
echo "Starting dummy_over_socket"
dummy > /dev/null &
pid_dummy=$!
tendermint node > tendermint.log &
pid_tendermint=$!
sleep 5
echo "running test"
bash dummy_test.sh "Dummy over Socket"
kill -9 $pid_dummy $pid_tendermint
}
# start tendermint first
function dummy_over_socket_reorder(){
rm -rf $TMHOME
tendermint init
echo "Starting dummy_over_socket_reorder (ie. start tendermint first)"
tendermint node > tendermint.log &
pid_tendermint=$!
sleep 2
dummy > /dev/null &
pid_dummy=$!
sleep 5
echo "running test"
bash dummy_test.sh "Dummy over Socket"
kill -9 $pid_dummy $pid_tendermint
}
function counter_over_socket() {
rm -rf $TMHOME
tendermint init
echo "Starting counter_over_socket"
counter --serial > /dev/null &
pid_counter=$!
tendermint node > tendermint.log &
pid_tendermint=$!
sleep 5
echo "running test"
bash counter_test.sh "Counter over Socket"
kill -9 $pid_counter $pid_tendermint
}
function counter_over_grpc() {
rm -rf $TMHOME
tendermint init
echo "Starting counter_over_grpc"
counter --serial --abci grpc > /dev/null &
pid_counter=$!
tendermint node --abci grpc > tendermint.log &
pid_tendermint=$!
sleep 5
echo "running test"
bash counter_test.sh "Counter over GRPC"
kill -9 $pid_counter $pid_tendermint
}
function counter_over_grpc_grpc() {
rm -rf $TMHOME
tendermint init
echo "Starting counter_over_grpc_grpc (ie. with grpc broadcast_tx)"
counter --serial --abci grpc > /dev/null &
pid_counter=$!
sleep 1
GRPC_PORT=36656
tendermint node --abci grpc --grpc_laddr tcp://localhost:$GRPC_PORT > tendermint.log &
pid_tendermint=$!
sleep 5
echo "running test"
GRPC_BROADCAST_TX=true bash counter_test.sh "Counter over GRPC via GRPC BroadcastTx"
kill -9 $pid_counter $pid_tendermint
}
cd $GOPATH/src/github.com/tendermint/tendermint/test/app
case "$1" in
"dummy_over_socket")
dummy_over_socket
;;
"dummy_over_socket_reorder")
dummy_over_socket_reorder
;;
"counter_over_socket")
counter_over_socket
;;
"counter_over_grpc")
counter_over_grpc
;;
"counter_over_grpc_grpc")
counter_over_grpc_grpc
;;
*)
echo "Running all"
dummy_over_socket
echo ""
dummy_over_socket_reorder
echo ""
counter_over_socket
echo ""
counter_over_grpc
echo ""
counter_over_grpc_grpc
esac