github.com/vipernet-xyz/tm@v0.34.24/test/app/kvstore_test.sh (about)

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