From 6eac364c4322497f6d2f38f7d675d86cd9b6ee16 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 16 Jun 2017 16:59:23 +0200 Subject: [PATCH] Complete ibc tests with "basecoin ibc register" and "basecoin relay" --- tests/cli/basictx.sh | 3 +- tests/cli/common.sh | 6 ++-- tests/cli/counter.sh | 2 +- tests/cli/ibc.sh | 78 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index 945665b521..0f2eb7803a 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -12,7 +12,6 @@ oneTimeSetUp() { rm -rf $BASE_DIR 2>/dev/null mkdir -p $BASE_DIR - # set up client - make sure you use the proper prefix if you set # a custom CLIENT_EXE export BC_HOME=${BASE_DIR}/client @@ -22,7 +21,7 @@ oneTimeSetUp() { initServer $BASE_DIR $CHAIN_ID 3456 PID_SERVER=$! - initClient $CHAIN_ID 3456 + initClient $CHAIN_ID 34567 echo "...Testing may begin!" echo diff --git a/tests/cli/common.sh b/tests/cli/common.sh index faa9faa88b..d39355fe05 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -43,12 +43,12 @@ initServer() { sleep 5 } -# initClient requires chain_id arg, port is optional (default 4665{5,6,7}) +# initClient requires chain_id arg, port is optional (default 46657) initClient() { echo "Attaching ${CLIENT_EXE} client..." - PORT=${2:-4665} + PORT=${2:-46657} # hard-code the expected validator hash - ${CLIENT_EXE} init --chain-id=$1 --node=tcp://localhost:${PORT}7 --valhash=EB168E17E45BAEB194D4C79067FFECF345C64DE6 + ${CLIENT_EXE} init --chain-id=$1 --node=tcp://localhost:${PORT} --valhash=EB168E17E45BAEB194D4C79067FFECF345C64DE6 assertTrue "initialized light-client" $? } diff --git a/tests/cli/counter.sh b/tests/cli/counter.sh index 6f83e33da5..599f511297 100755 --- a/tests/cli/counter.sh +++ b/tests/cli/counter.sh @@ -21,7 +21,7 @@ oneTimeSetUp() { initServer $BASE_DIR $CHAIN_ID 1234 PID_SERVER=$! - initClient $CHAIN_ID 1234 + initClient $CHAIN_ID 12347 echo "...Testing may begin!" echo diff --git a/tests/cli/ibc.sh b/tests/cli/ibc.sh index dbe1ff4f95..bc9d76cd92 100755 --- a/tests/cli/ibc.sh +++ b/tests/cli/ibc.sh @@ -13,12 +13,14 @@ oneTimeSetUp() { BASE_DIR_1=$HOME/.basecoin_test_ibc/chain1 CHAIN_ID_1=test-chain-1 CLIENT_1=${BASE_DIR_1}/client - PORT_1=1234 + PREFIX_1=1234 + PORT_1=${PREFIX_1}7 BASE_DIR_2=$HOME/.basecoin_test_ibc/chain2 CHAIN_ID_2=test-chain-2 CLIENT_2=${BASE_DIR_2}/client - PORT_2=2345 + PREFIX_2=2345 + PORT_2=${PREFIX_2}7 # clean up and create the test dirs rm -rf $BASE_DIR_1 $BASE_DIR_2 2>/dev/null @@ -30,11 +32,11 @@ oneTimeSetUp() { 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 $PORT_1 + BC_HOME=${CLIENT_1} initServer $BASE_DIR_1 $CHAIN_ID_1 $PREFIX_1 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 $PORT_2 + BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 $PREFIX_2 PID_SERVER_2=$! # connect both clients @@ -100,14 +102,78 @@ test01SendIBCTx() { checkSendTx $HASH $TX_HEIGHT $SENDER "20002" # # make sure nothing arrived - yet - waitForBlock ${PORT_1}7 + waitForBlock ${PORT_1} assertFalse "no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV" # start the relay and wait a few blocks... + # (already sent a tx on chain1, so use higher sequence) + startRelay 2 1 + if [ $? != 0 ]; then echo "can't start relay!"; return 1; fi - # then make sure the money arrived + # give it a little time, then make sure the money arrived + echo "waiting for relay..." + sleep 1 + waitForBlock ${PORT_1} + waitForBlock ${PORT_2} + + # check the new account + echo "checking ibc recipient..." + BC_HOME=${CLIENT_2} checkAccount $RECV "0" "20002" + + # stop relay + kill -9 $PID_RELAY } +# startRelay $seq1 $seq2 +# startRelay hooks up a relay between chain1 and chain2 +# it needs the proper sequence number for $RICH on chain1 and chain2 as args +startRelay() { + # send some cash to the default key, so it can send messages + RELAY_KEY=${BASE_DIR_1}/server/key.json + RELAY_ADDR=$(cat $RELAY_KEY | jq .address | tr -d \") + + # get paid on chain1 + export BC_HOME=${CLIENT_1} + SENDER=$(getAddr $RICH) + RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin --sequence=$1 --to=$RELAY_ADDR --name=$RICH 2>/dev/null) + txSucceeded $? "$RES" + if [ $? != 0 ]; then echo "can't pay chain1!"; return 1; fi + + # get paid on chain2 + export BC_HOME=${CLIENT_2} + SENDER=$(getAddr $RICH) + RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=100000mycoin --sequence=$2 --to=$RELAY_ADDR --name=$RICH 2>/dev/null) + txSucceeded $? "$RES" + if [ $? != 0 ]; then echo "can't pay chain2!"; return 1; fi + + # now we need to register the chains + # TODO: do this with basecli!!!! + basecoin tx ibc --amount 10mycoin --from=$RELAY_KEY --chain_id=$CHAIN_ID_2 \ + --node=tcp://localhost:${PORT_2} \ + register --ibc_chain_id=$CHAIN_ID_1 --genesis=$BASE_DIR_1/server/genesis.json \ + >/dev/null + if [ $? != 0 ]; then echo "can't register chain1 on chain 2"; return 1; fi + + basecoin tx ibc --amount 10mycoin --from=$RELAY_KEY --chain_id=$CHAIN_ID_1 \ + --node=tcp://localhost:${PORT_1} \ + register --ibc_chain_id=$CHAIN_ID_2 --genesis=$BASE_DIR_2/server/genesis.json \ + >/dev/null + if [ $? != 0 ]; then echo "can't register chain2 on chain 1"; return 1; fi + + # now start the relay! (this remains a server command) + # TODO: bucky, why does this die if I don't provide home??? + # It doesn't use the --from flag???? + ${SERVER_EXE} relay --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \ + --chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \ + --home=${BASE_DIR_1}/server --from=$RELAY_KEY > ${BASE_DIR_1}/../relay.log & + PID_RELAY=$! + echo starting relay $PID_RELAY ... + + # return an error if it dies in the first two seconds to make sure it is running + sleep 2 + ps $PID_RELAY >/dev/null + return $? +} # load and run these tests with shunit2! DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory