Clear output of test failures in ibc

This commit is contained in:
Ethan Frey 2017-06-16 15:33:37 +02:00
parent 4606fc84f7
commit cba5523ca5
4 changed files with 77 additions and 26 deletions

View File

@ -56,12 +56,11 @@ test01SendTx() {
assertFalse "missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 2>/dev/null"
assertFalse "bad password" "echo foo | ${CLIENT_EXE} 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 | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null | tail -n +2)
txSucceeded "$RES"
HASH=$(echo $RES | jq .hash | tr -d \")
TX_HEIGHT=$(echo $RES | jq .height)
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null)
txSucceeded $? "$RES"
TX=`echo $RES | cut -d: -f2-`
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
checkAccount $SENDER "1" "9007199254740000"
checkAccount $RECV "0" "992"

View File

@ -78,14 +78,19 @@ checkAccount() {
assertTrue "must have genesis account" $?
assertEquals "proper sequence" "$2" $(echo $ACCT | jq .data.sequence)
assertEquals "proper money" "$3" $(echo $ACCT | jq .data.coins[0].amount)
return $?
}
# txSucceeded $RES
# txSucceeded $? "$RES"
# must be called right after the `tx` command, makes sure it got a success response
txSucceeded() {
assertTrue "sent tx" $?
assertEquals "good check" "0" $(echo $1 | jq .check_tx.code)
assertEquals "good deliver" "0" $(echo $1 | jq .deliver_tx.code)
if (assertTrue "sent tx: $2" $1); then
TX=`echo $2 | cut -d: -f2-` # strip off first line asking for password
assertEquals "good check: $TX" "0" $(echo $TX | jq .check_tx.code)
assertEquals "good deliver: $TX" "0" $(echo $TX | jq .deliver_tx.code)
else
return 1
fi
}
# checkSendTx $HASH $HEIGHT $SENDER $AMOUNT
@ -98,5 +103,20 @@ checkSendTx() {
assertEquals "type=send" '"send"' $(echo $TX | jq .data.type)
assertEquals "proper sender" "\"$3\"" $(echo $TX | jq .data.data.inputs[0].address)
assertEquals "proper out amount" "$4" $(echo $TX | jq .data.data.outputs[0].coins[0].amount)
return $?
}
# waitForBlock $port
# waits until the block height on that node increases by one
waitForBlock() {
addr=http://localhost:$1
b1=`curl -s $addr/status | jq .result.latest_block_height`
b2=$b1
while [ "$b2" == "$b1" ]; do
echo "Waiting for node $addr to commit a block ..."
sleep 1
b2=`curl -s $addr/status | jq .result.latest_block_height`
done
}

View File

@ -56,11 +56,11 @@ test01SendTx() {
assertFalse "missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 2>/dev/null"
assertFalse "bad password" "echo foo | ${CLIENT_EXE} 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 | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null | tail -n +2)
txSucceeded "$RES"
HASH=$(echo $RES | jq .hash | tr -d \")
TX_HEIGHT=$(echo $RES | jq .height)
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null)
txSucceeded $? "$RES"
TX=`echo $RES | cut -d: -f2-`
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
checkAccount $SENDER "1" "9007199254740000"
checkAccount $RECV "0" "992"
@ -88,11 +88,11 @@ test02AddCount() {
SENDER=$(getAddr $RICH)
assertFalse "bad password" "echo hi | ${CLIENT_EXE} tx counter --amount=1000mycoin --sequence=2 --name=${RICH} 2>/dev/null"
# we have to remove the password request from stdout, to just get the json
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --amount=10mycoin --sequence=2 --name=${RICH} --valid --countfee=5mycoin 2>/dev/null | tail -n +2)
txSucceeded "$RES"
HASH=$(echo $RES | jq .hash | tr -d \")
TX_HEIGHT=$(echo $RES | jq .height)
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --amount=10mycoin --sequence=2 --name=${RICH} --valid --countfee=5mycoin 2>/dev/null)
txSucceeded $? "$RES"
TX=`echo $RES | cut -d: -f2-`
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
checkCounter "1" "5"

View File

@ -11,10 +11,12 @@ oneTimeSetUp() {
BASE_DIR_1=$HOME/.basecoin_test_ibc/chain1
CHAIN_ID_1=test-chain-1
CLIENT_1=${BASE_DIR_1}/client
PORT_1=1234
BASE_DIR_2=$HOME/.basecoin_test_ibc/chain2
CHAIN_ID_2=test-chain-2
CLIENT_2=${BASE_DIR_2}/client
PORT_2=2345
# clean up and create the test dirs
rm -rf $BASE_DIR_1 $BASE_DIR_2 2>/dev/null
@ -26,16 +28,16 @@ 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 2345
BC_HOME=${CLIENT_1} initServer $BASE_DIR_1 $CHAIN_ID_1 $PORT_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 3456
BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 $PORT_2
PID_SERVER_2=$!
# connect both clients
BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 2345
BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 3456
BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 $PORT_1
BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 $PORT_2
echo "...Testing may begin!"
echo
@ -53,9 +55,9 @@ oneTimeTearDown() {
}
test00GetAccount() {
SENDER_1=$(BC_HOME=${CLIENT_1} getAddr $RICH)
RECV_1=$(BC_HOME=${CLIENT_1} getAddr $POOR)
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"
@ -74,6 +76,36 @@ test00GetAccount() {
assertNotEquals "recipient keys must be different" "$RECV_1" "$RECV_2"
}
test01SendIBCTx() {
# trigger a cross-chain sendTx... from RICH on chain1 to POOR on chain2
# we make sure the money was reduced, but nothing arrived
SENDER=$(BC_HOME=${CLIENT_1} getAddr $RICH)
RECV=$(BC_HOME=${CLIENT_2} getAddr $POOR)
# we have to remove the password request from stdout, to just get the json
export BC_HOME=${CLIENT_1}
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20002mycoin --sequence=1 --to=${CHAIN_ID_2}/${RECV} --name=$RICH 2>/dev/null)
txSucceeded $? "$RES"
# an example to quit early if there is no point in more tests
if [ $? != 0 ]; then echo "aborting!"; return 1; fi
TX=`echo $RES | cut -d: -f2-`
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
# make sure balance went down and tx is indexed
checkAccount $SENDER "1" "9007199254720990"
checkSendTx $HASH $TX_HEIGHT $SENDER "20002"
# # make sure nothing arrived - yet
waitForBlock ${PORT_1}7
assertFalse "no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV"
# start the relay and wait a few blocks...
# then make sure the money arrived
}
# load and run these tests with shunit2!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory