2022-09-02 13:48:12 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-09-03 00:41:54 -07:00
|
|
|
# Configuration options that all tests must include
|
|
|
|
set -e
|
2022-09-05 16:03:12 -07:00
|
|
|
colineard config chain-id colinear
|
|
|
|
colineard config output json
|
|
|
|
colineard config broadcast-mode block
|
2022-09-04 17:10:42 -07:00
|
|
|
|
|
|
|
# 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')
|
2022-09-03 00:41:54 -07:00
|
|
|
|
2022-09-08 15:43:24 -07:00
|
|
|
function swallow {
|
|
|
|
read -r out
|
|
|
|
log_ok
|
|
|
|
echo $1 + swallow error
|
|
|
|
}
|
|
|
|
|
2022-09-02 13:48:12 -07:00
|
|
|
function assert_eq {
|
2022-09-03 17:59:37 -07:00
|
|
|
read -r out
|
|
|
|
if [[ $out = $1 ]]; then
|
|
|
|
log_ok
|
|
|
|
echo $2 correctly equals $1
|
|
|
|
else
|
2022-09-03 00:41:54 -07:00
|
|
|
log_fail
|
2022-09-03 17:59:37 -07:00
|
|
|
echo $2 should equal $1, instead got $out.
|
2022-09-02 13:48:12 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-04 17:10:42 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-09-14 14:50:33 -07:00
|
|
|
function expect_increase {
|
|
|
|
read -r out
|
|
|
|
comp=$1
|
|
|
|
desc=$2
|
|
|
|
expected=1
|
|
|
|
res=$(echo "$out>$comp" | bc)
|
|
|
|
if [[ $res = $expected ]]; then
|
|
|
|
log_ok
|
|
|
|
echo $desc correctly increased
|
|
|
|
else
|
|
|
|
log_fail
|
|
|
|
echo $desc did not increase ($out should be greater than $comp)
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_decrease {
|
|
|
|
read -r out
|
|
|
|
comp=$1
|
|
|
|
desc=$2
|
|
|
|
expected=1
|
|
|
|
res=$(echo "$out<$comp" | bc)
|
|
|
|
if [[ $res = $expected ]]; then
|
|
|
|
log_ok
|
|
|
|
echo $desc correctly decreased
|
|
|
|
else
|
|
|
|
log_fail
|
|
|
|
echo $desc did not decrease ($out should be less than than $comp)
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2022-09-04 17:10:42 -07:00
|
|
|
|
2022-09-03 00:41:54 -07:00
|
|
|
# Get balance of an account.
|
|
|
|
function get_balance {
|
2022-09-03 17:41:27 -07:00
|
|
|
local addr=$1
|
|
|
|
local denom=$2
|
2022-09-05 16:03:12 -07:00
|
|
|
colineard q bank balances $addr \
|
2022-09-04 17:10:42 -07:00
|
|
|
| jq -rM ".balances[] | select(.denom == \"$denom\") | .amount"
|
2022-09-03 00:41:54 -07:00
|
|
|
}
|
|
|
|
|
2022-09-02 13:48:12 -07:00
|
|
|
# Get current block time from chain.
|
|
|
|
function get_block_time {
|
2022-09-13 17:01:24 -07:00
|
|
|
curl -s http://0.0.0.0:1317/cosmos/base/tendermint/v1beta1/blocks/latest \
|
|
|
|
| jq -M ".block.header.height | tonumber"
|
2022-09-02 13:48:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_code {
|
2022-09-03 17:41:27 -07:00
|
|
|
read -r out
|
2022-09-02 13:48:12 -07:00
|
|
|
return $out | grep code: | awk -F ': ' '{print $2}'
|
|
|
|
}
|
|
|
|
|
2022-09-03 00:41:54 -07:00
|
|
|
function get_key {
|
2022-09-03 17:41:27 -07:00
|
|
|
read -r out
|
2022-09-03 00:41:54 -07:00
|
|
|
local filter=$2
|
2022-09-02 13:48:12 -07:00
|
|
|
echo $out | jq -M $filter
|
|
|
|
}
|
|
|
|
|
2022-09-03 17:41:27 -07:00
|
|
|
function get_last_auction_index {
|
2022-09-07 15:15:49 -07:00
|
|
|
res=$(colineard q colinearcore show-next-auction | jq -M ".NextAuction.auctionId | tonumber")
|
2022-09-03 17:41:27 -07:00
|
|
|
echo "$res-1" | bc
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_next_auction_index {
|
2022-09-07 15:15:49 -07:00
|
|
|
colineard q colinearcore show-next-auction | jq -M ".NextAuction.auctionId | tonumber"
|
2022-09-03 17:41:27 -07:00
|
|
|
}
|
|
|
|
|
2022-09-03 00:41:54 -07:00
|
|
|
function now {
|
|
|
|
local op=$1
|
|
|
|
local amount=$2
|
|
|
|
if [[ op = "" ]]; then
|
|
|
|
date +%s
|
|
|
|
else
|
|
|
|
echo "$(date +%s) $op $amount" | bc
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-02 13:48:12 -07:00
|
|
|
function expect_success {
|
2022-09-03 17:41:27 -07:00
|
|
|
read -r out
|
2022-09-03 00:41:54 -07:00
|
|
|
local msg=${1:-Expect transaction to succeed}
|
|
|
|
local res=$(echo $out | jq -M ".code")
|
|
|
|
local raw_log=$(echo $out | jq -M ".raw_log")
|
2022-09-03 17:41:27 -07:00
|
|
|
|
|
|
|
# globally write response key
|
|
|
|
# response=$(echo $out | jq -M ".")
|
|
|
|
|
2022-09-02 13:48:12 -07:00
|
|
|
if [[ $res = 0 ]]; then
|
|
|
|
log_ok
|
2022-09-03 00:41:54 -07:00
|
|
|
echo $msg
|
2022-09-02 13:48:12 -07:00
|
|
|
else
|
|
|
|
log_fail
|
2022-09-03 00:41:54 -07:00
|
|
|
echo $msg
|
2022-09-02 13:48:12 -07:00
|
|
|
echo $raw_log
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_fail {
|
2022-09-03 17:41:27 -07:00
|
|
|
read -r out
|
2022-09-03 00:41:54 -07:00
|
|
|
local msg=${1:-Expect transaction to revert}
|
|
|
|
local res=$(echo $out | jq -M ".code")
|
2022-09-02 13:48:12 -07:00
|
|
|
if [[ $res = 0 ]]; then
|
|
|
|
log_fail
|
2022-09-03 00:41:54 -07:00
|
|
|
echo $msg
|
2022-09-02 13:48:12 -07:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
log_ok
|
2022-09-03 00:41:54 -07:00
|
|
|
echo $msg
|
2022-09-02 13:48:12 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-03 17:41:27 -07:00
|
|
|
function log_info {
|
2022-09-05 14:18:04 -07:00
|
|
|
printf "[ INFO ] $1\n"
|
2022-09-03 17:41:27 -07:00
|
|
|
}
|
|
|
|
|
2022-09-02 13:48:12 -07:00
|
|
|
function log_test {
|
2022-09-05 14:18:04 -07:00
|
|
|
printf "$(fmt_cyan '[ TEST ]') $1\n"
|
2022-09-02 13:48:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function log_ok {
|
2022-09-05 14:18:04 -07:00
|
|
|
printf "$(fmt_green '[ OK ]') "
|
2022-09-02 13:48:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function log_fail {
|
2022-09-05 14:18:04 -07:00
|
|
|
printf "$(fmt_red '[ FAIL ]') "
|
2022-09-02 13:48:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|