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.

121 lines
2.7 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=0x"$TX")
  27. IS_ERR=$(echo "$RESPONSE" | jq 'has("error")')
  28. ERROR=$(echo "$RESPONSE" | jq '.error')
  29. ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
  30. RESPONSE=$(echo "$RESPONSE" | jq '.result')
  31. else
  32. if [ -f grpc_client ]; then
  33. rm grpc_client
  34. fi
  35. echo "... building grpc_client"
  36. go build -o grpc_client grpc_client.go
  37. RESPONSE=$(./grpc_client "$TX")
  38. IS_ERR=false
  39. ERROR=""
  40. fi
  41. echo "RESPONSE"
  42. echo "$RESPONSE"
  43. echo "$RESPONSE" | jq . &> /dev/null
  44. IS_JSON=$?
  45. if [[ "$IS_JSON" != "0" ]]; then
  46. IS_ERR=true
  47. ERROR="$RESPONSE"
  48. fi
  49. APPEND_TX_RESPONSE=$(echo "$RESPONSE" | jq '.deliver_tx')
  50. APPEND_TX_CODE=$(getCode "$APPEND_TX_RESPONSE")
  51. CHECK_TX_RESPONSE=$(echo "$RESPONSE" | jq '.check_tx')
  52. CHECK_TX_CODE=$(getCode "$CHECK_TX_RESPONSE")
  53. echo "-------"
  54. echo "TX $TX"
  55. echo "RESPONSE $RESPONSE"
  56. echo "ERROR $ERROR"
  57. echo "----"
  58. if $IS_ERR; then
  59. echo "Unexpected error sending tx ($TX): $ERROR"
  60. exit 1
  61. fi
  62. }
  63. echo "... sending tx. expect no error"
  64. # 0 should pass once and get in block, with no error
  65. TX=00
  66. sendTx $TX
  67. if [[ $APPEND_TX_CODE != 0 ]]; then
  68. echo "Got non-zero exit code for $TX. $RESPONSE"
  69. exit 1
  70. fi
  71. echo "... sending tx. expect error"
  72. # second time should get rejected by the mempool (return error and non-zero code)
  73. sendTx $TX
  74. echo "CHECKTX CODE: $CHECK_TX_CODE"
  75. if [[ "$CHECK_TX_CODE" == 0 ]]; then
  76. echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE"
  77. exit 1
  78. fi
  79. echo "... sending tx. expect no error"
  80. # now, TX=01 should pass, with no error
  81. TX=01
  82. sendTx $TX
  83. if [[ $APPEND_TX_CODE != 0 ]]; then
  84. echo "Got non-zero exit code for $TX. $RESPONSE"
  85. exit 1
  86. fi
  87. echo "... sending tx. expect no error, but invalid"
  88. # now, TX=03 should get in a block (passes CheckTx, no error), but is invalid
  89. TX=03
  90. sendTx $TX
  91. if [[ "$CHECK_TX_CODE" != 0 ]]; then
  92. echo "Got non-zero exit code for checktx on $TX. $RESPONSE"
  93. exit 1
  94. fi
  95. if [[ $APPEND_TX_CODE == 0 ]]; then
  96. echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE"
  97. exit 1
  98. fi
  99. echo "Passed Test: $TESTNAME"