tendermint/test/app/kvstore_test.sh

85 lines
1.8 KiB
Bash
Raw Permalink Normal View History

#! /bin/bash
set -ex
function toHex() {
echo -n $1 | hexdump -ve '1/1 "%.2X"' | awk '{print "0x" $0}'
2017-01-12 10:58:44 -05:00
}
#####################
# kvstore with curl
#####################
TESTNAME=$1
# store key value pair
KEY="abcd"
VALUE="dcba"
2017-01-12 10:58:44 -05:00
echo $(toHex $KEY=$VALUE)
curl -s 127.0.0.1:26657/broadcast_tx_commit?tx=$(toHex $KEY=$VALUE)
2016-07-24 14:08:47 -04:00
echo $?
echo ""
2016-09-10 17:42:12 -04:00
###########################
2017-01-12 15:53:32 -05:00
# test using the abci-cli
2016-09-10 17:42:12 -04:00
###########################
2017-01-12 15:53:32 -05:00
echo "... testing query with abci-cli"
2017-01-12 10:58:44 -05:00
# we should be able to look up the key
2017-01-12 15:53:32 -05:00
RESPONSE=`abci-cli query \"$KEY\"`
2016-07-24 14:08:47 -04:00
set +e
2017-03-05 20:39:52 -05:00
A=`echo $RESPONSE | grep "$VALUE"`
if [[ $? != 0 ]]; then
echo "Failed to find $VALUE for $KEY. Response:"
echo "$RESPONSE"
exit 1
fi
2016-07-24 14:08:47 -04:00
set -e
# we should not be able to look up the value
2017-01-12 15:53:32 -05:00
RESPONSE=`abci-cli query \"$VALUE\"`
2016-07-24 14:08:47 -04:00
set +e
A=`echo $RESPONSE | grep \"value: $VALUE\"`
if [[ $? == 0 ]]; then
echo "Found '$VALUE' for $VALUE when we should not have. Response:"
echo "$RESPONSE"
exit 1
fi
2016-07-24 14:08:47 -04:00
set -e
2016-09-10 17:42:12 -04:00
#############################
2017-01-12 15:53:32 -05:00
# test using the /abci_query
2016-09-10 17:42:12 -04:00
#############################
2017-01-28 09:11:31 -08:00
echo "... testing query with /abci_query 2"
2017-01-12 10:58:44 -05:00
2016-09-10 17:42:12 -04:00
# we should be able to look up the key
RESPONSE=`curl -s "127.0.0.1:26657/abci_query?path=\"\"&data=$(toHex $KEY)&prove=false"`
2017-04-28 22:31:30 -04:00
RESPONSE=`echo $RESPONSE | jq .result.response.log`
2016-09-10 17:42:12 -04:00
set +e
2017-01-28 09:11:31 -08:00
A=`echo $RESPONSE | grep 'exists'`
2016-09-10 17:42:12 -04:00
if [[ $? != 0 ]]; then
echo "Failed to find 'exists' for $KEY. Response:"
echo "$RESPONSE"
exit 1
2016-09-10 17:42:12 -04:00
fi
set -e
# we should not be able to look up the value
RESPONSE=`curl -s "127.0.0.1:26657/abci_query?path=\"\"&data=$(toHex $VALUE)&prove=false"`
2017-04-28 22:31:30 -04:00
RESPONSE=`echo $RESPONSE | jq .result.response.log`
2016-09-10 17:42:12 -04:00
set +e
2017-01-28 09:11:31 -08:00
A=`echo $RESPONSE | grep 'exists'`
2016-09-10 17:42:12 -04:00
if [[ $? == 0 ]]; then
echo "Found 'exists' for $VALUE when we should not have. Response:"
echo "$RESPONSE"
exit 1
2016-09-10 17:42:12 -04:00
fi
set -e
echo "Passed Test: $TESTNAME"