mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-04 20:24:25 -08:00
tests & utils for checking balance/escrow + fixes
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user