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.

84 lines
1.8 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #! /bin/bash
  2. set -ex
  3. function toHex() {
  4. echo -n $1 | hexdump -ve '1/1 "%.2X"' | awk '{print "0x" $0}'
  5. }
  6. #####################
  7. # kvstore with curl
  8. #####################
  9. TESTNAME=$1
  10. # store key value pair
  11. KEY="abcd"
  12. VALUE="dcba"
  13. echo $(toHex $KEY=$VALUE)
  14. curl -s 127.0.0.1:26657/broadcast_tx_commit?tx=$(toHex $KEY=$VALUE)
  15. echo $?
  16. echo ""
  17. ###########################
  18. # test using the abci-cli
  19. ###########################
  20. echo "... testing query with abci-cli"
  21. # we should be able to look up the key
  22. RESPONSE=`abci-cli query \"$KEY\"`
  23. set +e
  24. A=`echo $RESPONSE | grep "$VALUE"`
  25. if [[ $? != 0 ]]; then
  26. echo "Failed to find $VALUE for $KEY. Response:"
  27. echo "$RESPONSE"
  28. exit 1
  29. fi
  30. set -e
  31. # we should not be able to look up the value
  32. RESPONSE=`abci-cli query \"$VALUE\"`
  33. set +e
  34. A=`echo $RESPONSE | grep \"value: $VALUE\"`
  35. if [[ $? == 0 ]]; then
  36. echo "Found '$VALUE' for $VALUE when we should not have. Response:"
  37. echo "$RESPONSE"
  38. exit 1
  39. fi
  40. set -e
  41. #############################
  42. # test using the /abci_query
  43. #############################
  44. echo "... testing query with /abci_query 2"
  45. # we should be able to look up the key
  46. RESPONSE=`curl -s "127.0.0.1:26657/abci_query?path=\"\"&data=$(toHex $KEY)&prove=false"`
  47. RESPONSE=`echo $RESPONSE | jq .result.response.log`
  48. set +e
  49. A=`echo $RESPONSE | grep 'exists'`
  50. if [[ $? != 0 ]]; then
  51. echo "Failed to find 'exists' for $KEY. Response:"
  52. echo "$RESPONSE"
  53. exit 1
  54. fi
  55. set -e
  56. # we should not be able to look up the value
  57. RESPONSE=`curl -s "127.0.0.1:26657/abci_query?path=\"\"&data=$(toHex $VALUE)&prove=false"`
  58. RESPONSE=`echo $RESPONSE | jq .result.response.log`
  59. set +e
  60. A=`echo $RESPONSE | grep 'exists'`
  61. if [[ $? == 0 ]]; then
  62. echo "Found 'exists' for $VALUE when we should not have. Response:"
  63. echo "$RESPONSE"
  64. exit 1
  65. fi
  66. set -e
  67. echo "Passed Test: $TESTNAME"