2016-07-06 10:46:37 -07:00
|
|
|
#! /bin/bash
|
2018-06-12 02:25:52 -07:00
|
|
|
set -ex
|
2016-07-06 10:46:37 -07:00
|
|
|
|
|
|
|
function toHex() {
|
2018-06-12 02:25:52 -07:00
|
|
|
echo -n $1 | hexdump -ve '1/1 "%.2X"' | awk '{print "0x" $0}'
|
2017-01-12 07:58:44 -08:00
|
|
|
|
2016-07-06 10:46:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
2018-02-27 06:01:10 -08:00
|
|
|
# kvstore with curl
|
2016-07-06 10:46:37 -07:00
|
|
|
#####################
|
|
|
|
TESTNAME=$1
|
|
|
|
|
|
|
|
# store key value pair
|
|
|
|
KEY="abcd"
|
|
|
|
VALUE="dcba"
|
2017-01-12 07:58:44 -08:00
|
|
|
echo $(toHex $KEY=$VALUE)
|
2018-06-12 02:25:52 -07:00
|
|
|
curl -s 127.0.0.1:26657/broadcast_tx_commit?tx=$(toHex $KEY=$VALUE)
|
2016-07-24 11:08:47 -07:00
|
|
|
echo $?
|
2016-07-06 10:46:37 -07:00
|
|
|
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
|
|
|
|
2016-07-06 10:46:37 -07: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"`
|
2016-07-06 10:46:37 -07:00
|
|
|
if [[ $? != 0 ]]; then
|
2017-10-27 20:09:50 -07:00
|
|
|
echo "Failed to find $VALUE for $KEY. Response:"
|
|
|
|
echo "$RESPONSE"
|
|
|
|
exit 1
|
2016-07-06 10:46:37 -07:00
|
|
|
fi
|
2016-07-24 11:08:47 -07:00
|
|
|
set -e
|
2016-07-06 10:46:37 -07:00
|
|
|
|
|
|
|
# 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`
|
2016-07-06 10:46:37 -07:00
|
|
|
if [[ $? == 0 ]]; then
|
2017-10-27 20:09:50 -07:00
|
|
|
echo "Found '$VALUE' for $VALUE when we should not have. Response:"
|
|
|
|
echo "$RESPONSE"
|
|
|
|
exit 1
|
2016-07-06 10:46:37 -07:00
|
|
|
fi
|
2016-07-24 11:08:47 -07:00
|
|
|
set -e
|
2016-07-06 10:46:37 -07:00
|
|
|
|
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
|
2018-06-12 02:25:52 -07:00
|
|
|
RESPONSE=`curl -s "127.0.0.1:26657/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
|
2017-10-27 20:09:50 -07:00
|
|
|
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
|
2018-06-12 02:25:52 -07:00
|
|
|
RESPONSE=`curl -s "127.0.0.1:26657/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
|
2017-10-27 20:09:50 -07:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2016-07-06 10:46:37 -07:00
|
|
|
echo "Passed Test: $TESTNAME"
|