From 4606fc84f7687d757009851dc4f20e82c9ad173d Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 16 Jun 2017 14:43:54 +0200 Subject: [PATCH] Add ibc test scaffolding --- Makefile | 2 +- tests/cli/basictx.sh | 2 +- tests/cli/common.sh | 1 - tests/cli/counter.sh | 2 +- tests/cli/ibc.sh | 83 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b61cc2ffd5..dddf4fc2ce 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ test_cli: tests/cli/shunit2 # sudo apt-get install jq @./tests/cli/basictx.sh @./tests/cli/counter.sh - # @./clitest/ibc.sh + @./clitest/ibc.sh get_vendor_deps: tools glide install diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index 550bd2c430..efb01f1852 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -20,7 +20,7 @@ oneTimeSetUp() { # start basecoin server (with counter) initServer $BASE_DIR $CHAIN_ID 3456 - echo pid $PID_SERVER + PID_SERVER=$! initClient $CHAIN_ID 3456 diff --git a/tests/cli/common.sh b/tests/cli/common.sh index 4a60128444..08acb71e01 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -41,7 +41,6 @@ initServer() { echo "Starting ${SERVER_EXE} server..." ${SERVER_EXE} start --home=$SERVE_DIR >>$SERVER_LOG 2>&1 & sleep 5 - PID_SERVER=$! } # initClient requires chain_id arg, port is optional (default 4665{5,6,7}) diff --git a/tests/cli/counter.sh b/tests/cli/counter.sh index 461fb410e5..fbc7699d3c 100755 --- a/tests/cli/counter.sh +++ b/tests/cli/counter.sh @@ -19,7 +19,7 @@ oneTimeSetUp() { # start basecoin server (with counter) initServer $BASE_DIR $CHAIN_ID 1234 - echo pid $PID_SERVER + PID_SERVER=$! initClient $CHAIN_ID 1234 diff --git a/tests/cli/ibc.sh b/tests/cli/ibc.sh index 2b0c889a74..662f91b106 100755 --- a/tests/cli/ibc.sh +++ b/tests/cli/ibc.sh @@ -1,3 +1,84 @@ #!/bin/bash -echo "ibc test not implemented" +#!/bin/bash + +# these are two globals to control all scripts (can use eg. counter instead) +SERVER_EXE=basecoin +CLIENT_EXE=basecli + +oneTimeSetUp() { + # these are passed in as args + BASE_DIR_1=$HOME/.basecoin_test_ibc/chain1 + CHAIN_ID_1=test-chain-1 + CLIENT_1=${BASE_DIR_1}/client + + BASE_DIR_2=$HOME/.basecoin_test_ibc/chain2 + CHAIN_ID_2=test-chain-2 + CLIENT_2=${BASE_DIR_2}/client + + # clean up and create the test dirs + rm -rf $BASE_DIR_1 $BASE_DIR_2 2>/dev/null + mkdir -p $BASE_DIR_1 $BASE_DIR_2 + + # set up client for chain 1- make sure you use the proper prefix if you set + # a custom CLIENT_EXE + BC_HOME=${CLIENT_1} prepareClient + BC_HOME=${CLIENT_2} prepareClient + + # start basecoin server, giving money to the key in the first client + BC_HOME=${CLIENT_1} initServer $BASE_DIR_1 $CHAIN_ID_1 2345 + PID_SERVER_1=$! + + # start second basecoin server, giving money to the key in the second client + BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 3456 + PID_SERVER_2=$! + + # connect both clients + BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 2345 + BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 3456 + + echo "...Testing may begin!" + echo + echo + echo +} + +oneTimeTearDown() { + echo + echo + echo "stopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2" + kill -9 $PID_SERVER_1 + kill -9 $PID_SERVER_2 + sleep 1 +} + +test00GetAccount() { + export BC_HOME=${CLIENT_1} + SENDER_1=$(getAddr $RICH) + RECV_1=$(getAddr $POOR) + + assertFalse "requires arg" "${CLIENT_EXE} query account" + assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1" + checkAccount $SENDER_1 "0" "9007199254740992" + + export BC_HOME=${CLIENT_2} + SENDER_2=$(getAddr $RICH) + RECV_2=$(getAddr $POOR) + + assertFalse "requires arg" "${CLIENT_EXE} query account" + assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2" + checkAccount $SENDER_2 "0" "9007199254740992" + + # make sure that they have different addresses on both chains (they are random keys) + assertNotEquals "sender keys must be different" "$SENDER_1" "$SENDER_2" + assertNotEquals "recipient keys must be different" "$RECV_1" "$RECV_2" +} + + +# load and run these tests with shunit2! +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory + +# load common helpers +. $DIR/common.sh + +. $DIR/shunit2