github.com/number571/tendermint@v0.34.11-gost/rpc/jsonrpc/test/integration_test.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 # Get the directory of where this script is. 5 SOURCE="${BASH_SOURCE[0]}" 6 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 7 DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 8 9 # Change into that dir because we expect that. 10 pushd "$DIR" 11 12 echo "==> Building the server" 13 go build -o rpcserver main.go 14 15 echo "==> (Re)starting the server" 16 PID=$(pgrep rpcserver || echo "") 17 if [[ $PID != "" ]]; then 18 kill -9 "$PID" 19 fi 20 ./rpcserver & 21 PID=$! 22 sleep 2 23 24 echo "==> simple request" 25 R1=$(curl -s 'http://localhost:8008/hello_world?name="my_world"&num=5') 26 R2=$(curl -s --data @data.json http://localhost:8008) 27 if [[ "$R1" != "$R2" ]]; then 28 echo "responses are not identical:" 29 echo "R1: $R1" 30 echo "R2: $R2" 31 echo "FAIL" 32 exit 1 33 else 34 echo "OK" 35 fi 36 37 echo "==> request with 0x-prefixed hex string arg" 38 R1=$(curl -s 'http://localhost:8008/hello_world?name=0x41424344&num=123') 39 R2='{"jsonrpc":"2.0","id":"","result":{"Result":"hi ABCD 123"},"error":""}' 40 if [[ "$R1" != "$R2" ]]; then 41 echo "responses are not identical:" 42 echo "R1: $R1" 43 echo "R2: $R2" 44 echo "FAIL" 45 exit 1 46 else 47 echo "OK" 48 fi 49 50 echo "==> request with missing params" 51 R1=$(curl -s 'http://localhost:8008/hello_world') 52 R2='{"jsonrpc":"2.0","id":"","result":{"Result":"hi 0"},"error":""}' 53 if [[ "$R1" != "$R2" ]]; then 54 echo "responses are not identical:" 55 echo "R1: $R1" 56 echo "R2: $R2" 57 echo "FAIL" 58 exit 1 59 else 60 echo "OK" 61 fi 62 63 echo "==> request with unquoted string arg" 64 R1=$(curl -s 'http://localhost:8008/hello_world?name=abcd&num=123') 65 R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: invalid character 'a' looking for beginning of value\"}" 66 if [[ "$R1" != "$R2" ]]; then 67 echo "responses are not identical:" 68 echo "R1: $R1" 69 echo "R2: $R2" 70 echo "FAIL" 71 exit 1 72 else 73 echo "OK" 74 fi 75 76 echo "==> request with string type when expecting number arg" 77 R1=$(curl -s 'http://localhost:8008/hello_world?name="abcd"&num=0xabcd') 78 R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: Got a hex string arg, but expected 'int'\"}" 79 if [[ "$R1" != "$R2" ]]; then 80 echo "responses are not identical:" 81 echo "R1: $R1" 82 echo "R2: $R2" 83 echo "FAIL" 84 exit 1 85 else 86 echo "OK" 87 fi 88 89 echo "==> Stopping the server" 90 kill -9 $PID 91 92 rm -f rpcserver 93 94 popd 95 exit 0