mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-02 18:12:03 +00:00
Add writeRPCResponse and writeHTTPResponse helpers, that handle the way RPC responses are written to HTTP replies. These replace the exported helpers. Visible effects: - JSON results are now marshaled without indentation. - HTTP status codes are now normalized. - Cache control headers are no longer set. Details: - When writing a response to a URL (GET) request, do not marshal the whole JSON-RPC object into the body, only encode the result or the error object. This is a user-visible change. - Do not change the HTTP status code for RPC errors. The RPC error already reports what went wrong, the HTTP status should only report problems with the HTTP transaction itself. This is a user-visible change. - Encode JSON without indentation in POST response bodies. This is mainly cosmetic but saves quite a bit of response data. Indent is still applied to GET responses to make life easier for code examples. - Remove an obsolete TODO about reporting an HTTP error on websocket upgrade. Nothing needed to change; the upgrader already reports an error. - Report an HTTP error when starting the server loop fails. - Improve logging for encoding errors. - Log less aggressively.
85 lines
1.8 KiB
Bash
Executable File
85 lines
1.8 KiB
Bash
Executable File
#! /bin/bash
|
|
set -ex
|
|
|
|
function toHex() {
|
|
echo -n $1 | hexdump -ve '1/1 "%.2X"' | awk '{print "0x" $0}'
|
|
|
|
}
|
|
|
|
#####################
|
|
# kvstore with curl
|
|
#####################
|
|
TESTNAME=$1
|
|
|
|
# store key value pair
|
|
KEY="abcd"
|
|
VALUE="dcba"
|
|
echo $(toHex $KEY=$VALUE)
|
|
curl -s 127.0.0.1:26657/broadcast_tx_commit?tx=$(toHex $KEY=$VALUE)
|
|
echo $?
|
|
echo ""
|
|
|
|
|
|
###########################
|
|
# test using the abci-cli
|
|
###########################
|
|
|
|
echo "... testing query with abci-cli"
|
|
|
|
# we should be able to look up the key
|
|
RESPONSE=`abci-cli query \"$KEY\"`
|
|
|
|
set +e
|
|
A=`echo $RESPONSE | grep "$VALUE"`
|
|
if [[ $? != 0 ]]; then
|
|
echo "Failed to find $VALUE for $KEY. Response:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
set -e
|
|
|
|
# we should not be able to look up the value
|
|
RESPONSE=`abci-cli query \"$VALUE\"`
|
|
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
|
|
set -e
|
|
|
|
#############################
|
|
# test using the /abci_query
|
|
#############################
|
|
|
|
echo "... testing query with /abci_query 2"
|
|
|
|
# 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"`
|
|
RESPONSE=`echo $RESPONSE | jq .response.log`
|
|
|
|
set +e
|
|
A=`echo $RESPONSE | grep 'exists'`
|
|
if [[ $? != 0 ]]; then
|
|
echo "Failed to find 'exists' for $KEY. Response:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
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"`
|
|
RESPONSE=`echo $RESPONSE | jq .response.log`
|
|
set +e
|
|
A=`echo $RESPONSE | grep 'exists'`
|
|
if [[ $? == 0 ]]; then
|
|
echo "Found 'exists' for $VALUE when we should not have. Response:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
set -e
|
|
|
|
|
|
echo "Passed Test: $TESTNAME"
|