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.

136 lines
2.9 KiB

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