begin test suite

master
michael 2022-09-02 20:48:12 +00:00
parent b493c6dc09
commit e8e7680ae2
3 changed files with 113 additions and 0 deletions

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
SHELL = /bin/bash
.DEFAULT_GOAL := serve
.PHONY: test
test:
./tests/test_auction_flow.sh

21
tests/test_auction_flow.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# import utilities
HERE=$(cd $(dirname $BASH_SOURCE) && pwd)
source $HERE/testutil.sh
# log commands
# set -x
log_test "Typical Auction Flow"
out=$(cosmos-testd tx cosmostest new-auction asdf asdf utoken -y --from bob --chain-id cosmostest)
expect_success $out
log_test "Failed Bidding Edge Cases"
# out=$(cosmos-testd tx cosmostest new-bid 0 800 -y --from bob --chain-id cosmostest | expect_fail)
# expect_success $out
# cosmos-testd tx cosmostest new-bid 0 800 --from bob --chain-id cosmostest

86
tests/testutil.sh Normal file
View File

@ -0,0 +1,86 @@
#!/bin/bash
# Compares $1 & $2, exiting with $3 (label) if not eq
function assert_eq {
if [[ $1 = $2 ]]; then
echo Expected $3 to equal $2, instead got $1.
exit 1
else
echo $3 has correct value.
fi
}
# Get current block time from chain.
function get_block_time {
return \
$(
curl http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \
| jq ".blocks.header.height"
)
}
function get_code {
read out
return $out | grep code: | awk -F ': ' '{print $2}'
}
function filter_out {
out=$1
filter=$2
echo $out | jq -M $filter
}
function expect_success {
out=$1
# if we want to pipe:
# read out
res=$(echo $out | grep code: | awk -F ': ' '{print $2}')
raw_log=$(echo $out | grep raw_log: | awk -F ': ' '{print $2}')
if [[ $res = 0 ]]; then
log_ok
echo Transaction succeeded.
else
log_fail
echo Transaction unexpectedly reverted.
echo
echo $raw_log
exit 1
fi
}
function expect_fail {
out=$1
res=$(echo $out | grep code: | awk -F ': ' '{print $2}')
if [[ $res = 0 ]]; then
log_fail
echo Transaction unexpectedly succeeded.
exit 1
else
log_ok
echo Transaction reverted.
fi
}
function log_test {
printf "$(fmt_cyan [TEST])\t$1\n"
}
function log_ok {
printf "$(fmt_green [OK])\t"
}
function log_fail {
printf "$(fmt_red [FAIL])\t"
}
function fmt_red {
printf "\e[31m$1\e[0m"
}
function fmt_green {
printf "\e[32m$1\e[0m"
}
function fmt_cyan {
printf "\e[96m$1\e[0m"
}