test framework upgrades + start actual tests

master
michael 2022-09-04 00:41:27 +00:00
parent 61a037ee3c
commit 8db387eab7
2 changed files with 52 additions and 18 deletions

View File

@ -4,11 +4,33 @@
HERE=$(cd $(dirname $BASH_SOURCE) && pwd) HERE=$(cd $(dirname $BASH_SOURCE) && pwd)
source $HERE/testutil.sh source $HERE/testutil.sh
cosmos-testd tx cosmostest new-bid 0 800 \ cosmos-testd tx cosmostest new-auction asdf asdf 500 token 1662155879 \
-y --from alice \
| expect_fail "Can't create bids for nonexistent auctions"
cosmos-testd tx cosmostest new-auction asdf asdf 100 token 1662155879 \
-y --from bob \ -y --from bob \
| expect_success "New auction is created" | expect_success "New auction is created"
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 100 \
-y --from alice \
| expect_success "New bid is correctly created"
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 100 \
-y --from alice \
| expect_fail "Can't create duplicate bids"
cosmos-testd tx cosmostest new-bid $(get_next_auction_index) 100 \
-y --from alice \
| expect_fail "Can't create bids for nonexistent auctions"
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 600 \
-y --from alice \
| expect_fail "Can't bid over price ceiling"
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 0 \
-y --from alice \
| expect_fail "Can't bid 0 tokens"
log_info "Waiting until auction expires..."
sleep 10
cosmos-testd tx cosmostest new-bid $(get_last_auction_index) 100 \
-y --from alice \
| expect_fail "Can't add bids after auction expiry"

View File

@ -19,12 +19,12 @@ function assert_eq {
# Get balance of an account. # Get balance of an account.
function get_balance { function get_balance {
addr=$1 local addr=$1
denom=$2 local denom=$2
return \ return \
$( $(
curl http://0.0.0.0:1317/cosmos/bank/v1beta1/balances/$addr/by_denom?denom=$denom \ curl http://0.0.0.0:1317/cosmos/bank/v1beta1/balances/$addr/by_denom?denom=$denom \
| jq -M ".balance.amount" | jq -M ".balance.amount | tonumber"
) )
} }
@ -33,21 +33,30 @@ function get_block_time {
return \ return \
$( $(
curl http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \ curl http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \
| jq -M ".blocks.header.height" | jq -M ".blocks.header.height | tonumber"
) )
} }
function get_code { function get_code {
read out read -r out
return $out | grep code: | awk -F ': ' '{print $2}' return $out | grep code: | awk -F ': ' '{print $2}'
} }
function get_key { function get_key {
local out=$1 read -r out
local filter=$2 local filter=$2
echo $out | jq -M $filter echo $out | jq -M $filter
} }
function get_last_auction_index {
res=$(cosmos-testd q cosmostest show-next-auction | jq -M ".NextAuction.auctionId | tonumber")
echo "$res-1" | bc
}
function get_next_auction_index {
cosmos-testd q cosmostest show-next-auction | jq -M ".NextAuction.auctionId | tonumber"
}
function now { function now {
local op=$1 local op=$1
local amount=$2 local amount=$2
@ -59,14 +68,14 @@ function now {
} }
function expect_success { function expect_success {
read out read -r out
local msg=${1:-Expect transaction to succeed} local msg=${1:-Expect transaction to succeed}
# if we want to pipe:
# read out
# local res=$(echo $out | grep code: | awk -F ': ' '{print $2}')
# local raw_log=$(echo $out | awk -F ': ' '{print $2}')
local res=$(echo $out | jq -M ".code") local res=$(echo $out | jq -M ".code")
local raw_log=$(echo $out | jq -M ".raw_log") local raw_log=$(echo $out | jq -M ".raw_log")
# globally write response key
# response=$(echo $out | jq -M ".")
if [[ $res = 0 ]]; then if [[ $res = 0 ]]; then
log_ok log_ok
echo $msg echo $msg
@ -79,9 +88,8 @@ function expect_success {
} }
function expect_fail { function expect_fail {
read out read -r out
local msg=${1:-Expect transaction to revert} local msg=${1:-Expect transaction to revert}
# local res=$(echo $out | grep code: | awk -F ': ' '{print $2}')
local res=$(echo $out | jq -M ".code") local res=$(echo $out | jq -M ".code")
if [[ $res = 0 ]]; then if [[ $res = 0 ]]; then
log_fail log_fail
@ -93,6 +101,10 @@ function expect_fail {
fi fi
} }
function log_info {
printf "[INFO]\t$1\n"
}
function log_test { function log_test {
printf "$(fmt_cyan [TEST])\t$1\n" printf "$(fmt_cyan [TEST])\t$1\n"
} }