You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.6 KiB

  1. #! /bin/bash
  2. if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
  3. GRPC_BROADCAST_TX=""
  4. fi
  5. set -u
  6. #####################
  7. # counter over socket
  8. #####################
  9. TESTNAME=$1
  10. # Send some txs
  11. function getCode() {
  12. R=$1
  13. if [[ "$R" == "{}" ]]; then
  14. # protobuf auto adds `omitempty` to everything so code OK and empty data/log
  15. # will not even show when marshalled into json
  16. # apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
  17. echo 0
  18. else
  19. # this wont actually work if theres an error ...
  20. echo "$R" | jq .code
  21. fi
  22. }
  23. function sendTx() {
  24. TX=$1
  25. if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
  26. RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=\"$TX\"`
  27. ERROR=`echo $RESPONSE | jq .error`
  28. ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
  29. RESPONSE=`echo $RESPONSE | jq .result[1]`
  30. else
  31. if [ ! -f grpc_client ]; then
  32. go build -o grpc_client grpc_client.go
  33. fi
  34. RESPONSE=`./grpc_client $TX`
  35. ERROR=""
  36. fi
  37. echo "RESPONSE"
  38. echo $RESPONSE
  39. echo $RESPONSE | jq . &> /dev/null
  40. IS_JSON=$?
  41. if [[ "$IS_JSON" != "0" ]]; then
  42. ERROR="$RESPONSE"
  43. fi
  44. APPEND_TX_RESPONSE=`echo $RESPONSE | jq .append_tx`
  45. APPEND_TX_CODE=`getCode "$APPEND_TX_RESPONSE"`
  46. CHECK_TX_RESPONSE=`echo $RESPONSE | jq .check_tx`
  47. CHECK_TX_CODE=`getCode "$CHECK_TX_RESPONSE"`
  48. echo "-------"
  49. echo "TX $TX"
  50. echo "RESPONSE $RESPONSE"
  51. echo "ERROR $ERROR"
  52. echo "----"
  53. if [[ "$ERROR" != "" ]]; then
  54. echo "Unexpected error sending tx ($TX): $ERROR"
  55. exit 1
  56. fi
  57. }
  58. echo "... sending tx. expect no error"
  59. # 0 should pass once and get in block, with no error
  60. TX=00
  61. sendTx $TX
  62. if [[ $APPEND_TX_CODE != 0 ]]; then
  63. echo "Got non-zero exit code for $TX. $RESPONSE"
  64. exit 1
  65. fi
  66. echo "... sending tx. expect error"
  67. # second time should get rejected by the mempool (return error and non-zero code)
  68. sendTx $TX
  69. echo "CHECKTX CODE: $CHECK_TX_CODE"
  70. if [[ "$CHECK_TX_CODE" == 0 ]]; then
  71. echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE"
  72. exit 1
  73. fi
  74. echo "... sending tx. expect no error"
  75. # now, TX=01 should pass, with no error
  76. TX=01
  77. sendTx $TX
  78. if [[ $APPEND_TX_CODE != 0 ]]; then
  79. echo "Got non-zero exit code for $TX. $RESPONSE"
  80. exit 1
  81. fi
  82. echo "... sending tx. expect no error, but invalid"
  83. # now, TX=03 should get in a block (passes CheckTx, no error), but is invalid
  84. TX=03
  85. sendTx $TX
  86. if [[ "$CHECK_TX_CODE" != 0 ]]; then
  87. echo "Got non-zero exit code for checktx on $TX. $RESPONSE"
  88. exit 1
  89. fi
  90. if [[ $APPEND_TX_CODE == 0 ]]; then
  91. echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE"
  92. exit 1
  93. fi
  94. echo "Passed Test: $TESTNAME"