From 609600d322025ff656fe73bd60c570cb2b958ad0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Oct 2017 19:53:45 +0200 Subject: [PATCH] Fixed height handling in rest queries --- examples/basecoin/tests/cli/rest.sh | 16 ++++++++++------ modules/coin/rest/handlers.go | 2 +- modules/nonce/rest/handlers.go | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/basecoin/tests/cli/rest.sh b/examples/basecoin/tests/cli/rest.sh index e840cbb91..076e08e3e 100755 --- a/examples/basecoin/tests/cli/rest.sh +++ b/examples/basecoin/tests/cli/rest.sh @@ -15,9 +15,9 @@ oneTimeSetUp() { exit 1; fi baseserver serve --port $BPORT >/dev/null & + sleep 0.1 # for startup PID_PROXY=$! disown - sleep 0.1 # for startup } oneTimeTearDown() { @@ -35,12 +35,16 @@ restAddr() { echo $ADDR } -# XXX Ex Usage: restAccount $ADDR $AMOUNT +# XXX Ex Usage: restAccount $ADDR $AMOUNT [$HEIGHT] # Desc: Assumes just one coin, checks the balance of first coin in any case restAccount() { assertNotNull "line=${LINENO}, address required" "$1" - ACCT=$(curl ${URL}/query/account/sigs:$1 2>/dev/null) - if [ -n "$DEBUG" ]; then echo $ACCT; echo; fi + QUERY=${URL}/query/account/sigs:$1 + if [ -n "$3" ]; then + QUERY="${QUERY}?height=${3}" + fi + ACCT=$(curl ${QUERY} 2>/dev/null) + if [ -n "$DEBUG" ]; then echo $QUERY; echo $ACCT; echo; fi assertEquals "line=${LINENO}, proper money" "$2" $(echo $ACCT | jq .data.coins[0].amount) return $? } @@ -76,8 +80,8 @@ test01SendTx() { HASH=$(echo $TX | jq .hash | tr -d \") TX_HEIGHT=$(echo $TX | jq .height) - restAccount $SENDER "9007199254740000" - restAccount $RECV "992" + restAccount $SENDER "9007199254740000" "$TX_HEIGHT" + restAccount $RECV "992" "$TX_HEIGHT" # Make sure tx is indexed checkSendTx $HASH $TX_HEIGHT $SENDER "992" diff --git a/modules/coin/rest/handlers.go b/modules/coin/rest/handlers.go index 443cc9408..6deaf4494 100644 --- a/modules/coin/rest/handlers.go +++ b/modules/coin/rest/handlers.go @@ -48,7 +48,7 @@ func doQueryAccount(w http.ResponseWriter, r *http.Request) { } var h int - qHeight := args["height"] + qHeight := r.URL.Query().Get("height") if qHeight != "" { h, err = strconv.Atoi(qHeight) if err != nil { diff --git a/modules/nonce/rest/handlers.go b/modules/nonce/rest/handlers.go index 3a3077616..f22601951 100644 --- a/modules/nonce/rest/handlers.go +++ b/modules/nonce/rest/handlers.go @@ -31,7 +31,7 @@ func doQueryNonce(w http.ResponseWriter, r *http.Request) { } var h int - qHeight := args["height"] + qHeight := r.URL.Query().Get("height") if qHeight != "" { h, err = strconv.Atoi(qHeight) if err != nil {