2017-06-15 08:16:00 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-15 11:56:59 -07:00
|
|
|
# these are two globals to control all scripts (can use eg. counter instead)
|
|
|
|
SERVER_EXE=basecoin
|
|
|
|
CLIENT_EXE=basecli
|
2017-06-15 11:47:59 -07:00
|
|
|
|
2017-06-15 08:16:00 -07:00
|
|
|
oneTimeSetUp() {
|
2017-06-15 11:56:59 -07:00
|
|
|
# these are passed in as args
|
2017-06-15 08:16:00 -07:00
|
|
|
BASE_DIR=$HOME/.basecoin_test_basictx
|
2017-06-15 11:47:59 -07:00
|
|
|
CHAIN_ID=my-test-chain
|
2017-06-15 08:16:00 -07:00
|
|
|
|
2017-06-15 11:47:59 -07:00
|
|
|
rm -rf $BASE_DIR 2>/dev/null
|
2017-06-15 08:16:00 -07:00
|
|
|
mkdir -p $BASE_DIR
|
|
|
|
|
|
|
|
|
2017-06-15 11:56:59 -07:00
|
|
|
# set up client - make sure you use the proper prefix if you set
|
|
|
|
# a custom CLIENT_EXE
|
2017-06-15 11:47:59 -07:00
|
|
|
export BC_HOME=${BASE_DIR}/client
|
2017-06-15 08:16:00 -07:00
|
|
|
prepareClient
|
|
|
|
|
|
|
|
# start basecoin server (with counter)
|
2017-06-15 11:47:59 -07:00
|
|
|
initServer $BASE_DIR $CHAIN_ID 3456
|
2017-06-15 08:16:00 -07:00
|
|
|
echo pid $PID_SERVER
|
|
|
|
|
2017-06-15 11:47:59 -07:00
|
|
|
initClient $CHAIN_ID 3456
|
2017-06-15 08:16:00 -07:00
|
|
|
|
|
|
|
echo "...Testing may begin!"
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
oneTimeTearDown() {
|
2017-06-15 08:45:44 -07:00
|
|
|
echo
|
|
|
|
echo
|
2017-06-15 11:56:59 -07:00
|
|
|
echo "stopping $SERVER_EXE test server..."
|
2017-06-15 08:45:44 -07:00
|
|
|
kill -9 $PID_SERVER >/dev/null 2>&1
|
2017-06-15 08:16:00 -07:00
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
2017-06-15 08:45:44 -07:00
|
|
|
test00GetAccount() {
|
2017-06-15 08:16:00 -07:00
|
|
|
SENDER=$(getAddr $RICH)
|
|
|
|
RECV=$(getAddr $POOR)
|
|
|
|
|
2017-06-15 11:56:59 -07:00
|
|
|
assertFalse "requires arg" "${CLIENT_EXE} query account"
|
2017-06-16 05:26:35 -07:00
|
|
|
|
|
|
|
checkAccount $SENDER "0" "9007199254740992"
|
2017-06-15 08:45:44 -07:00
|
|
|
|
2017-06-15 11:56:59 -07:00
|
|
|
ACCT2=$(${CLIENT_EXE} query account $RECV)
|
2017-06-15 08:45:44 -07:00
|
|
|
assertFalse "has no genesis account" $?
|
|
|
|
}
|
|
|
|
|
|
|
|
test01SendTx() {
|
|
|
|
SENDER=$(getAddr $RICH)
|
|
|
|
RECV=$(getAddr $POOR)
|
|
|
|
|
2017-06-15 11:56:59 -07:00
|
|
|
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"
|
2017-06-15 08:45:44 -07:00
|
|
|
# we have to remove the password request from stdout, to just get the json
|
2017-06-15 11:56:59 -07:00
|
|
|
RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null | tail -n +2)
|
2017-06-16 05:26:35 -07:00
|
|
|
txSucceeded "$RES"
|
|
|
|
|
2017-06-15 08:45:44 -07:00
|
|
|
HASH=$(echo $RES | jq .hash | tr -d \")
|
|
|
|
TX_HEIGHT=$(echo $RES | jq .height)
|
|
|
|
|
2017-06-16 05:26:35 -07:00
|
|
|
checkAccount $SENDER "1" "9007199254740000"
|
|
|
|
checkAccount $RECV "0" "992"
|
2017-06-15 08:45:44 -07:00
|
|
|
|
|
|
|
# make sure tx is indexed
|
2017-06-16 05:26:35 -07:00
|
|
|
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
2017-06-15 08:16:00 -07:00
|
|
|
}
|
|
|
|
|
2017-06-15 08:45:44 -07:00
|
|
|
|
2017-06-15 08:16:00 -07:00
|
|
|
# load and run these tests with shunit2!
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
2017-06-15 11:47:59 -07:00
|
|
|
|
|
|
|
# load common helpers
|
|
|
|
. $DIR/common.sh
|
|
|
|
|
2017-06-15 08:16:00 -07:00
|
|
|
. $DIR/shunit2
|