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.

122 lines
3.1 KiB

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