tests & utils for checking balance/escrow + fixes

master
michael 2022-09-05 00:10:42 +00:00
parent 7f37e69011
commit fd20f608fd
3 changed files with 35 additions and 11 deletions

View File

@ -9,8 +9,8 @@ validator:
client: client:
openapi: openapi:
path: "docs/static/openapi.yml" path: "docs/static/openapi.yml"
vuex: # vuex:
path: "vue/src/store" # path: "vue/src/store"
faucet: faucet:
name: bob name: bob
coins: ["5token", "100000stake"] coins: ["5token", "100000stake"]

View File

@ -4,9 +4,14 @@
HERE=$(cd $(dirname $BASH_SOURCE) && pwd) HERE=$(cd $(dirname $BASH_SOURCE) && pwd)
source $HERE/testutil.sh source $HERE/testutil.sh
before=$(get_balance $BOB token)
cosmos-testd tx cosmostest new-auction asdf asdf 500 token $(now + 100) \ cosmos-testd tx cosmostest new-auction asdf asdf 500 token $(now + 100) \
-y --from bob \ -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 \ cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 100 \
-y --from alice \ -y --from alice \
@ -36,7 +41,7 @@ cosmos-testd q cosmostest auction-bids $(get_last_auction_index) \
| jq -M ".bids | length" \ | jq -M ".bids | length" \
| assert_eq 2 "Number of auction bids" | assert_eq 2 "Number of auction bids"
log_info "Waiting until auction expires..." log_info "Waiting 10s until auction expires..."
sleep 10 sleep 10
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 50 \ cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 50 \

View File

@ -4,8 +4,13 @@
set -e set -e
cosmos-testd config chain-id cosmostest cosmos-testd config chain-id cosmostest
cosmos-testd config output json 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 { function assert_eq {
read -r out read -r out
if [[ $out = $1 ]]; then if [[ $out = $1 ]]; then
@ -18,22 +23,36 @@ function assert_eq {
fi 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. # Get balance of an account.
function get_balance { function get_balance {
local addr=$1 local addr=$1
local denom=$2 local denom=$2
return \ cosmos-testd q bank balances $addr \
$( | jq -rM ".balances[] | select(.denom == \"$denom\") | .amount"
curl http://0.0.0.0:1317/cosmos/bank/v1beta1/balances/$addr/by_denom?denom=$denom \
| jq -M ".balance.amount | tonumber"
)
} }
# Get current block time from chain. # Get current block time from chain.
function get_block_time { function get_block_time {
return \ 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" | jq -M ".blocks.header.height | tonumber"
) )
} }