cosmos-sdk/tests/cli/basictx.sh

90 lines
2.9 KiB
Bash
Raw Normal View History

2017-06-15 08:16:00 -07:00
#!/bin/bash
2017-06-20 04:21:06 -07:00
# These global variables are required for common.sh
2017-06-15 11:56:59 -07:00
SERVER_EXE=basecoin
CLIENT_EXE=basecli
2017-06-20 04:21:06 -07:00
ACCOUNTS=(jae ethan bucky rigel igor)
RICH=${ACCOUNTS[0]}
POOR=${ACCOUNTS[4]}
2017-06-15 08:16:00 -07:00
oneTimeSetUp() {
if ! quickSetup .basecoin_test_basictx basictx-chain; then
exit 1;
fi
2017-06-15 08:16:00 -07:00
}
oneTimeTearDown() {
2017-06-28 22:29:10 -07:00
quickTearDown
2017-06-15 08:16:00 -07:00
}
test00GetAccount() {
2017-06-28 22:29:10 -07:00
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
2017-06-15 08:16:00 -07:00
2017-07-18 21:13:39 -07:00
assertFalse "line=${LINENO}, requires arg" "${CLIENT_EXE} query account"
2017-06-16 05:26:35 -07:00
checkAccount $SENDER "9007199254740992"
2017-06-28 22:29:10 -07:00
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
2017-07-18 21:13:39 -07:00
assertFalse "line=${LINENO}, has no genesis account" $?
}
test01SendTx() {
2017-06-28 22:29:10 -07:00
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
2017-07-18 21:13:39 -07:00
assertFalse "line=${LINENO}, missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1"
assertFalse "line=${LINENO}, bad password" "echo foo | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH"
2017-06-28 22:29:10 -07:00
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
txSucceeded $? "$TX" "$RECV"
2017-06-28 22:29:10 -07:00
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
checkAccount $SENDER "9007199254740000"
2017-06-28 22:29:10 -07:00
# make sure 0x prefix also works
checkAccount "0x$SENDER" "9007199254740000"
checkAccount $RECV "992"
2017-06-28 22:29:10 -07:00
# Make sure tx is indexed
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
2017-06-15 08:16:00 -07:00
}
2017-07-12 11:51:07 -07:00
test02SendTxWithFee() {
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
2017-07-18 21:13:39 -07:00
# Test to see if the auto-sequencing works, the sequence here should be calculated to be 2
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --to=$RECV --name=$RICH)
2017-07-12 11:51:07 -07:00
txSucceeded $? "$TX" "$RECV"
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
# deduct 100 from sender, add 90 to receiver... fees "vanish"
checkAccount $SENDER "9007199254739900"
checkAccount $RECV "1082"
# Make sure tx is indexed
2017-07-12 12:04:34 -07:00
checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10"
# assert replay protection
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null)
2017-07-18 21:13:39 -07:00
assertFalse "line=${LINENO}, replay: $TX" $?
checkAccount $SENDER "9007199254739900"
checkAccount $RECV "1082"
# make sure we can query the proper nonce
NONCE=$(${CLIENT_EXE} query nonce $SENDER)
if [ -n "$DEBUG" ]; then echo $NONCE; echo; fi
# TODO: note that cobra returns error code 0 on parse failure,
# so currently this check passes even if there is no nonce query command
2017-07-18 21:13:39 -07:00
if assertTrue "line=${LINENO}, no nonce query" $?; then
assertEquals "line=${LINENO}, proper nonce" "2" $(echo $NONCE | jq .data)
fi
2017-07-12 11:51:07 -07:00
}
2017-06-20 04:21:06 -07:00
# Load common then run these tests with shunit2!
2017-06-15 08:16:00 -07:00
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
. $DIR/common.sh
2017-06-15 08:16:00 -07:00
. $DIR/shunit2