tendermint/test/app/kvstore_test.sh

85 lines
1.8 KiB
Bash
Raw Normal View History

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