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)
source $HERE/testutil.sh
cosmos-testd tx cosmostest new-bid 0 800 \
-y --from alice \
| expect_fail "Can't create bids for nonexistent auctions"
cosmos-testd tx cosmostest new-auction asdf asdf 100 token 1662155879 \
cosmos-testd tx cosmostest new-auction asdf asdf 500 token 1662155879 \
-y --from bob \
| 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.
function get_balance {
addr=$1
denom=$2
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"
| jq -M ".balance.amount | tonumber"
)
}
@ -33,21 +33,30 @@ function get_block_time {
return \
$(
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 {
read out
read -r out
return $out | grep code: | awk -F ': ' '{print $2}'
}
function get_key {
local out=$1
read -r out
local filter=$2
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 {
local op=$1
local amount=$2
@ -59,14 +68,14 @@ function now {
}
function expect_success {
read out
read -r out
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 raw_log=$(echo $out | jq -M ".raw_log")
# globally write response key
# response=$(echo $out | jq -M ".")
if [[ $res = 0 ]]; then
log_ok
echo $msg
@ -79,9 +88,8 @@ function expect_success {
}
function expect_fail {
read out
read -r out
local msg=${1:-Expect transaction to revert}
# local res=$(echo $out | grep code: | awk -F ': ' '{print $2}')
local res=$(echo $out | jq -M ".code")
if [[ $res = 0 ]]; then
log_fail
@ -93,6 +101,10 @@ function expect_fail {
fi
}
function log_info {
printf "[INFO]\t$1\n"
}
function log_test {
printf "$(fmt_cyan [TEST])\t$1\n"
}