From fd20f608fd604b711ddc13419ff2bdcbad4755a9 Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Mon, 5 Sep 2022 00:10:42 +0000 Subject: [PATCH] tests & utils for checking balance/escrow + fixes --- config.yml | 4 ++-- tests/test_auction_flow.sh | 9 +++++++-- tests/testutil.sh | 33 ++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/config.yml b/config.yml index 0e5d5b6..ccc191d 100644 --- a/config.yml +++ b/config.yml @@ -9,8 +9,8 @@ validator: client: openapi: path: "docs/static/openapi.yml" - vuex: - path: "vue/src/store" + # vuex: + # path: "vue/src/store" faucet: name: bob coins: ["5token", "100000stake"] diff --git a/tests/test_auction_flow.sh b/tests/test_auction_flow.sh index 9b2adba..810c069 100755 --- a/tests/test_auction_flow.sh +++ b/tests/test_auction_flow.sh @@ -4,9 +4,14 @@ HERE=$(cd $(dirname $BASH_SOURCE) && pwd) source $HERE/testutil.sh +before=$(get_balance $BOB token) + cosmos-testd tx cosmostest new-auction asdf asdf 500 token $(now + 100) \ -y --from bob \ - | expect_success "New auction is created" + | expect_success "New auction is created" + +# sleep 1 +get_balance $BOB token | expect_change -500 $before "Change in Bob's balance" cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 100 \ -y --from alice \ @@ -36,7 +41,7 @@ cosmos-testd q cosmostest auction-bids $(get_last_auction_index) \ | jq -M ".bids | length" \ | assert_eq 2 "Number of auction bids" -log_info "Waiting until auction expires..." +log_info "Waiting 10s until auction expires..." sleep 10 cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 50 \ diff --git a/tests/testutil.sh b/tests/testutil.sh index dcc1ffc..acd3f7a 100644 --- a/tests/testutil.sh +++ b/tests/testutil.sh @@ -4,8 +4,13 @@ set -e cosmos-testd config chain-id cosmostest cosmos-testd config output json +cosmos-testd config broadcast-mode block + +# Test config addresses (Alice & Bob) +accounts=$(curl -s http://localhost:1317/cosmos/auth/v1beta1/accounts | jq -M ".accounts") +declare -g ALICE=$(echo $accounts | jq -rM '.[] | select(.account_number == "0") | .address') +declare -g BOB=$(echo $accounts | jq -rM '.[] | select(.account_number == "1") | .address') -# Compares $1 & $2, exiting with $3 (label) if not eq function assert_eq { read -r out if [[ $out = $1 ]]; then @@ -18,22 +23,36 @@ function assert_eq { fi } +function expect_change { + read -r out + expected=$1 + comp=$2 + desc=$3 + res=$(echo "$out - $comp" | bc) + if [[ $res = $expected ]]; then + log_ok + echo $desc correctly equals $res + else + log_fail + echo $desc should equal $expected, instead got $res + exit 1 + fi +} + + # Get balance of an account. function get_balance { local addr=$1 local denom=$2 - return \ - $( - curl http://0.0.0.0:1317/cosmos/bank/v1beta1/balances/$addr/by_denom?denom=$denom \ - | jq -M ".balance.amount | tonumber" - ) + cosmos-testd q bank balances $addr \ + | jq -rM ".balances[] | select(.denom == \"$denom\") | .amount" } # Get current block time from chain. function get_block_time { return \ $( - curl http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \ + curl -s http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \ | jq -M ".blocks.header.height | tonumber" ) }