#!/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" }