From cfe13e9c130ea5e29f291cf4b8e15b3cfeaca539 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 15 Jun 2017 17:45:44 +0200 Subject: [PATCH] Cleanup proof format, complete basic cli tests --- Makefile | 1 + clitest/basictx.sh | 60 ++++++++++++++++++++++++++++++++++++---------- glide.lock | 2 +- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 3cb3937e7..c336e05e2 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ clitest/shunit2: -q -O clitest/shunit2 test_cli: clitest/shunit2 + # sudo apt-get install jq @./clitest/basictx.sh # @./clitest/ibc.sh diff --git a/clitest/basictx.sh b/clitest/basictx.sh index 0cface81f..e5e159a33 100755 --- a/clitest/basictx.sh +++ b/clitest/basictx.sh @@ -17,8 +17,6 @@ oneTimeSetUp() { # start basecoin server (with counter) initServer - sleep 5 - PID_SERVER=$! echo pid $PID_SERVER initClient @@ -30,8 +28,10 @@ oneTimeSetUp() { } oneTimeTearDown() { - echo "stopping basecoin test server" - kill -9 $PID_SERVER + echo + echo + echo "stopping basecoin test server..." + kill -9 $PID_SERVER >/dev/null 2>&1 sleep 1 } @@ -59,6 +59,8 @@ initServer() { echo "Starting server..." basecoin start --home=$SERVE_DIR >>$SERVER_LOG 2>&1 & + sleep 5 + PID_SERVER=$! } initClient() { @@ -86,22 +88,56 @@ getAddr() { echo $RAW | cut -d' ' -f2 } -testGetAccount() { +test00GetAccount() { SENDER=$(getAddr $RICH) RECV=$(getAddr $POOR) - echo sender $RICH - echo $SENDER - - echo recipient $POOR - echo $RECV - assertFalse "requires arg" "basecli query account" ACCT=$(basecli query account $SENDER) assertTrue "must have proper genesis account" $? - echo $ACCT + assertEquals "no tx" "0" $(echo $ACCT | jq .data.sequence) + assertEquals "has money" "9007199254740992" $(echo $ACCT | jq .data.coins[0].amount) + + ACCT2=$(basecli query account $RECV) + assertFalse "has no genesis account" $? } +test01SendTx() { + SENDER=$(getAddr $RICH) + RECV=$(getAddr $POOR) + + assertFalse "missing dest" "basecli tx send --amount=992mycoin --sequence=1 2>/dev/null" + assertFalse "bad password" "echo foo | basecli tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null" + # we have to remove the password request from stdout, to just get the json + RES=$(echo qwertyuiop | basecli tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null | tail -n +2) + assertTrue "sent tx" $? + HASH=$(echo $RES | jq .hash | tr -d \") + TX_HEIGHT=$(echo $RES | jq .height) + assertEquals "good check" "0" $(echo $RES | jq .check_tx.code) + assertEquals "good deliver" "0" $(echo $RES | jq .deliver_tx.code) + + # make sure sender goes down + ACCT=$(basecli query account $SENDER) + assertTrue "must have genesis account" $? + assertEquals "one tx" "1" $(echo $ACCT | jq .data.sequence) + assertEquals "has money" "9007199254740000" $(echo $ACCT | jq .data.coins[0].amount) + + # make sure recipient goes up + ACCT2=$(basecli query account $RECV) + assertTrue "must have new account" $? + assertEquals "no tx" "0" $(echo $ACCT2 | jq .data.sequence) + assertEquals "has money" "992" $(echo $ACCT2 | jq .data.coins[0].amount) + + # make sure tx is indexed + TX=$(basecli query tx $HASH) + assertTrue "found tx" $? + assertEquals "proper height" $TX_HEIGHT $(echo $TX | jq .height) + assertEquals "type=send" '"send"' $(echo $TX | jq .data.type) + assertEquals "proper sender" "\"$SENDER\"" $(echo $TX | jq .data.data.inputs[0].address) + assertEquals "proper out amount" "992" $(echo $TX | jq .data.data.outputs[0].coins[0].amount) +} + + # load and run these tests with shunit2! DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory . $DIR/shunit2 diff --git a/glide.lock b/glide.lock index bd3888209..3a7d423fa 100644 --- a/glide.lock +++ b/glide.lock @@ -127,7 +127,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: 88fb726e779d97acac5f0bd387892bfc541f3701 + version: a4dbbcacfd2d0a53da1393cbe176c0a81cab42e7 subpackages: - certifiers - certifiers/client