github.com/number571/tendermint@v0.34.11-gost/test/app/counter_test.sh (about)

     1  #! /bin/bash
     2  
     3  export GO111MODULE=on
     4  
     5  if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
     6  	GRPC_BROADCAST_TX=""
     7  fi
     8  
     9  set -u
    10  
    11  #####################
    12  # counter over socket
    13  #####################
    14  TESTNAME=$1
    15  
    16  # Send some txs
    17  
    18  function getCode() {
    19  	set +u
    20  	R=$1
    21  	set -u
    22  	if [[ "$R" == "" ]]; then
    23  		echo -1
    24  	fi
    25  
    26  	if [[ $(echo $R | jq 'has("code")') == "true" ]]; then
    27  		# this wont actually work if theres an error ...
    28  		echo "$R" | jq ".code"
    29  	else
    30  		# protobuf auto adds `omitempty` to everything so code OK and empty data/log
    31  		# will not even show when marshalled into json
    32  		# apparently we can use github.com/golang/protobuf/jsonpb to do the marshaling ...
    33  		echo 0
    34  	fi
    35  }
    36  
    37  # build grpc client if needed
    38  if [[ "$GRPC_BROADCAST_TX" != "" ]]; then
    39  	if [  -f test/app/grpc_client ]; then
    40  		rm test/app/grpc_client
    41  	fi
    42  	echo "... building grpc_client"
    43  	go build -mod=readonly -o test/app/grpc_client test/app/grpc_client.go
    44  fi
    45  
    46  function sendTx() {
    47  	TX=$1
    48  	set +u
    49  	SHOULD_ERR=$2
    50  	if [ "$SHOULD_ERR" == "" ]; then
    51  		SHOULD_ERR=false
    52  	fi
    53  	set -u
    54  	if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
    55  		RESPONSE=$(curl -s localhost:26657/broadcast_tx_commit?tx=0x"$TX")
    56  		IS_ERR=$(echo "$RESPONSE" | jq 'has("error")')
    57  		ERROR=$(echo "$RESPONSE" | jq '.error')
    58  		ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
    59  
    60  		RESPONSE=$(echo "$RESPONSE" | jq '.result')
    61  	else
    62  		RESPONSE=$(./test/app/grpc_client "$TX")
    63  		IS_ERR=false
    64  		ERROR=""
    65  	fi
    66  
    67  	echo "RESPONSE"
    68  	echo "$RESPONSE"
    69  
    70  	echo "$RESPONSE" | jq . &> /dev/null
    71  	IS_JSON=$?
    72  	if [[ "$IS_JSON" != "0" ]]; then
    73  		IS_ERR=true
    74  		ERROR="$RESPONSE"
    75  	fi
    76  	APPEND_TX_RESPONSE=$(echo "$RESPONSE" | jq '.deliver_tx')
    77  	APPEND_TX_CODE=$(getCode "$APPEND_TX_RESPONSE")
    78  	CHECK_TX_RESPONSE=$(echo "$RESPONSE" | jq '.check_tx')
    79  	CHECK_TX_CODE=$(getCode "$CHECK_TX_RESPONSE")
    80  
    81  	echo "-------"
    82  	echo "TX $TX"
    83  	echo "RESPONSE $RESPONSE"
    84  	echo "ERROR $ERROR"
    85  	echo "IS_ERR $IS_ERR"
    86  	echo "----"
    87  
    88  	if $SHOULD_ERR; then
    89  		if [[ "$IS_ERR" != "true" ]]; then
    90  			echo "Expected error sending tx ($TX)"
    91  			exit 1
    92  		fi
    93  	else
    94  		if [[ "$IS_ERR" == "true" ]]; then
    95  			echo "Unexpected error sending tx ($TX)"
    96  			exit 1
    97  		fi
    98  
    99  	fi
   100  }
   101  
   102  echo "... sending tx. expect no error"
   103  
   104  # 0 should pass once and get in block, with no error
   105  TX=00
   106  sendTx $TX
   107  if [[ $APPEND_TX_CODE != 0 ]]; then
   108  	echo "Got non-zero exit code for $TX. $RESPONSE"
   109  	exit 1
   110  fi
   111  
   112  echo "... sending new tx. expect no error"
   113  
   114  # now, TX=01 should pass, with no error
   115  TX=01
   116  sendTx $TX
   117  if [[ $APPEND_TX_CODE != 0 ]]; then
   118  	echo "Got non-zero exit code for $TX. $RESPONSE"
   119  	exit 1
   120  fi
   121  
   122  echo "... sending tx. expect no error, but invalid"
   123  
   124  # now, TX=03 should get in a block (passes CheckTx, no error), but is invalid
   125  TX=03
   126  sendTx $TX
   127  if [[ "$CHECK_TX_CODE" != 0 ]]; then
   128  	echo "Got non-zero exit code for checktx on $TX. $RESPONSE"
   129  	exit 1
   130  fi
   131  if [[ $APPEND_TX_CODE == 0 ]]; then
   132  	echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE"
   133  	exit 1
   134  fi
   135  
   136  echo "Passed Test: $TESTNAME"