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.

118 lines
2.6 KiB

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