circle fixes
This commit is contained in:
parent
ec7ef41fdc
commit
a08775052c
14
Makefile
14
Makefile
|
@ -31,11 +31,15 @@ test_cli: tests/cli/shunit2
|
|||
|
||||
test_tutorial:
|
||||
shelldown ${TUTORIALS}
|
||||
for script in ${TUTORIALS} ; do \
|
||||
echo "\n\n\nRunning test for script: $$script.sh" ; \
|
||||
bash $$script.sh ; \
|
||||
for script in docs/guide/*.sh ; do \
|
||||
bash $$script ; \
|
||||
done
|
||||
|
||||
tests/cli/shunit2:
|
||||
wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \
|
||||
-q -O tests/cli/shunit2
|
||||
cp tests/cli/shunit2 docs/guide/shunit2
|
||||
|
||||
get_vendor_deps: tools
|
||||
glide install
|
||||
|
||||
|
@ -44,10 +48,6 @@ build-docker:
|
|||
"/go/src/github.com/tendermint/basecoin" -e "CGO_ENABLED=0" golang:alpine go build ./cmd/basecoin
|
||||
docker build -t "tendermint/basecoin" .
|
||||
|
||||
tests/cli/shunit2:
|
||||
wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \
|
||||
-q -O tests/cli/shunit2
|
||||
|
||||
tools:
|
||||
@go get $(GOTOOLS)
|
||||
|
||||
|
|
|
@ -2,60 +2,60 @@
|
|||
#!/bin/bash
|
||||
|
||||
testTutorial_BasecoinBasics() {
|
||||
|
||||
rm -rf ~/.basecoin 2>/dev/null
|
||||
rm -rf ~/.basecli 2>/dev/null
|
||||
KEYPASS=qwertyuiop
|
||||
|
||||
#shelldown[1][2]
|
||||
RES=$((echo $KEYPASS; echo $KEYPASS) | #shelldown[1][3])
|
||||
assertTrue "Line $LINENO: Expected to contain safe, got $RES" '[[ $RES == *safe* ]]'
|
||||
RES=$((echo $KEYPASS; echo $KEYPASS) | #shelldown[1][4])
|
||||
assertTrue "Line $LINENO: Expected to contain safe, got $RES" '[[ $RES == *safe* ]]'
|
||||
assertTrue "Expected true for line $LINENO" $?
|
||||
|
||||
#shelldown[3][-1]
|
||||
assertTrue "Expected true for line $LINENO" $?
|
||||
|
||||
#shelldown[4][-1] >>/dev/null 2>&1 &
|
||||
sleep 5
|
||||
PID_SERVER=$!
|
||||
disown
|
||||
|
||||
RES=$((echo y) | #shelldown[5][-1] $1)
|
||||
assertTrue "Line $LINENO: Expected to contain validator, got $RES" '[[ $RES == *validator* ]]'
|
||||
rm -rf ~/.basecoin 2>/dev/null
|
||||
rm -rf ~/.basecli 2>/dev/null
|
||||
KEYPASS=qwertyuiop
|
||||
|
||||
#shelldown[6][0]
|
||||
#shelldown[6][1]
|
||||
RES="$(#shelldown[6][2])"
|
||||
assertTrue "Line $LINENO: Expected to contain mycoin, got $RES" '[[ $RES == *mycoin* ]]'
|
||||
RES="$(#shelldown[6][3] 2>&1)"
|
||||
assertTrue "Line $LINENO: Expected to contain ERROR, got $RES" '[[ $RES == *ERROR* ]]'
|
||||
#shelldown[1][2]
|
||||
RES=$((echo $KEYPASS; echo $KEYPASS) | #shelldown[1][3])
|
||||
assertTrue "Line $LINENO: Expected to contain safe, got $RES" '[[ $RES == *safe* ]]'
|
||||
RES=$((echo $KEYPASS; echo $KEYPASS) | #shelldown[1][4])
|
||||
assertTrue "Line $LINENO: Expected to contain safe, got $RES" '[[ $RES == *safe* ]]'
|
||||
assertTrue "Expected true for line $LINENO" $?
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[7][-1] | jq '.deliver_tx.code')
|
||||
assertTrue "Line $LINENO: Expected 0 code deliver_tx, got $RES" '[[ $RES == 0 ]]'
|
||||
#shelldown[3][-1]
|
||||
assertTrue "Expected true for line $LINENO" $?
|
||||
|
||||
#shelldown[4][-1] >>/dev/null 2>&1 &
|
||||
sleep 5
|
||||
PID_SERVER=$!
|
||||
disown
|
||||
|
||||
RES=$(#shelldown[8][-1])
|
||||
assertTrue "Line $LINENO: Expected to contain 1000 mycoin, got $RES" '[[ $RES == *1000* ]]'
|
||||
assertTrue "Line $LINENO: Expected to not contain Error, got $RES" '[[ $RES != *Error* ]]'
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[9][-1] | jq '.deliver_tx.code')
|
||||
assertTrue "Line $LINENO: Expected 0 code deliver_tx, got $RES" '[[ $RES == 0 ]]'
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[10][-1])
|
||||
assertTrue "Line $LINENO: Expected to contain insufficient funds error, got $RES" \
|
||||
'[[ $RES == *"insufficient funds"* ]]'
|
||||
|
||||
#perform a substitution within the final tests
|
||||
HASH=$((echo $KEYPASS) | #shelldown[11][-1] | jq '.hash' | tr -d '"')
|
||||
PRESUB="#shelldown[12][-1]"
|
||||
RES=$(eval ${PRESUB/<HASH>/$HASH})
|
||||
assertTrue "Line $LINENO: Expected to not contain Error, got $RES" '[[ $RES != *Error* ]]'
|
||||
RES=$((echo y) | #shelldown[5][-1] $1)
|
||||
assertTrue "Line $LINENO: Expected to contain validator, got $RES" '[[ $RES == *validator* ]]'
|
||||
|
||||
#shelldown[6][0]
|
||||
#shelldown[6][1]
|
||||
RES="$(#shelldown[6][2])"
|
||||
assertTrue "Line $LINENO: Expected to contain mycoin, got $RES" '[[ $RES == *mycoin* ]]'
|
||||
RES="$(#shelldown[6][3] 2>&1)"
|
||||
assertTrue "Line $LINENO: Expected to contain ERROR, got $RES" '[[ $RES == *ERROR* ]]'
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[7][-1] | jq '.deliver_tx.code')
|
||||
assertTrue "Line $LINENO: Expected 0 code deliver_tx, got $RES" '[[ $RES == 0 ]]'
|
||||
|
||||
RES=$(#shelldown[8][-1])
|
||||
assertTrue "Line $LINENO: Expected to contain 1000 mycoin, got $RES" '[[ $RES == *1000* ]]'
|
||||
assertTrue "Line $LINENO: Expected to not contain Error, got $RES" '[[ $RES != *Error* ]]'
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[9][-1] | jq '.deliver_tx.code')
|
||||
assertTrue "Line $LINENO: Expected 0 code deliver_tx, got $RES" '[[ $RES == 0 ]]'
|
||||
|
||||
RES=$((echo $KEYPASS) | #shelldown[10][-1])
|
||||
assertTrue "Line $LINENO: Expected to contain insufficient funds error, got $RES" \
|
||||
'[[ $RES == *"insufficient funds"* ]]'
|
||||
|
||||
#perform a substitution within the final tests
|
||||
HASH=$((echo $KEYPASS) | #shelldown[11][-1] | jq '.hash' | tr -d '"')
|
||||
PRESUB="#shelldown[12][-1]"
|
||||
RES=$(eval ${PRESUB/<HASH>/$HASH})
|
||||
assertTrue "Line $LINENO: Expected to not contain Error, got $RES" '[[ $RES != *Error* ]]'
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
}
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
|
|
|
@ -8,43 +8,43 @@ RICH=${ACCOUNTS[0]}
|
|||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
quickSetup .basecoin_test_basictx basictx-chain
|
||||
quickSetup .basecoin_test_basictx basictx-chain
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
quickTearDown
|
||||
quickTearDown
|
||||
}
|
||||
|
||||
test00GetAccount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account"
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account"
|
||||
|
||||
checkAccount $SENDER "0" "9007199254740992"
|
||||
checkAccount $SENDER "0" "9007199254740992"
|
||||
|
||||
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
|
||||
assertFalse "has no genesis account" $?
|
||||
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
|
||||
assertFalse "has no genesis account" $?
|
||||
}
|
||||
|
||||
test01SendTx() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
assertFalse "missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1"
|
||||
assertFalse "bad password" "echo foo | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH"
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
assertFalse "missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1"
|
||||
assertFalse "bad password" "echo foo | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH"
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
# make sure 0x prefix also works
|
||||
checkAccount "0x$SENDER" "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
# make sure 0x prefix also works
|
||||
checkAccount "0x$SENDER" "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
|
||||
# Make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
# Make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
}
|
||||
|
||||
# Load common then run these tests with shunit2!
|
||||
|
|
|
@ -7,49 +7,50 @@
|
|||
# ACCOUNTS=(foo bar) # List of accounts for initialization
|
||||
# RICH=${ACCOUNTS[0]} # Account to assign genesis balance
|
||||
|
||||
|
||||
# XXX Ex Usage: quickSetup $WORK_NAME $CHAIN_ID
|
||||
# Desc: Start the program, use with shunit2 OneTimeSetUp()
|
||||
quickSetup() {
|
||||
# These are passed in as args
|
||||
BASE_DIR=$HOME/$1
|
||||
CHAIN_ID=$2
|
||||
# These are passed in as args
|
||||
BASE_DIR=$HOME/$1
|
||||
CHAIN_ID=$2
|
||||
|
||||
rm -rf $BASE_DIR 2>/dev/null
|
||||
mkdir -p $BASE_DIR
|
||||
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
|
||||
prepareClient
|
||||
# Set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
# start basecoin server (with counter)
|
||||
initServer $BASE_DIR $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
# start basecoin server (with counter)
|
||||
initServer $BASE_DIR $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
initClient $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
initClient $CHAIN_ID
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
# XXX Ex Usage: quickTearDown
|
||||
# Desc: close the test server, use with shunit2 OneTimeTearDown()
|
||||
quickTearDown() {
|
||||
printf "\n\nstopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
printf "\n\nstopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
}
|
||||
|
||||
############################################################
|
||||
|
||||
prepareClient() {
|
||||
echo "Preparing client keys..."
|
||||
${CLIENT_EXE} reset_all
|
||||
assertTrue $?
|
||||
echo "Preparing client keys..."
|
||||
${CLIENT_EXE} reset_all
|
||||
assertTrue $?
|
||||
|
||||
for i in "${!ACCOUNTS[@]}"; do
|
||||
newKey ${ACCOUNTS[$i]}
|
||||
done
|
||||
for i in "${!ACCOUNTS[@]}"; do
|
||||
newKey ${ACCOUNTS[$i]}
|
||||
done
|
||||
}
|
||||
|
||||
# XXX Ex Usage1: initServer $ROOTDIR $CHAINID
|
||||
|
@ -57,37 +58,37 @@ prepareClient() {
|
|||
# Desc: Grabs the Rich account and gives it all genesis money
|
||||
# port-prefix default is 4665{6,7,8}
|
||||
initServer() {
|
||||
echo "Setting up genesis..."
|
||||
SERVE_DIR=$1/server
|
||||
assertNotNull "no chain" $2
|
||||
CHAIN=$2
|
||||
SERVER_LOG=$1/${SERVER_EXE}.log
|
||||
echo "Setting up genesis..."
|
||||
SERVE_DIR=$1/server
|
||||
assertNotNull "no chain" $2
|
||||
CHAIN=$2
|
||||
SERVER_LOG=$1/${SERVER_EXE}.log
|
||||
|
||||
GENKEY=$(${CLIENT_EXE} keys get ${RICH} | awk '{print $2}')
|
||||
${SERVER_EXE} init --chain-id $CHAIN $GENKEY --home=$SERVE_DIR >>$SERVER_LOG
|
||||
GENKEY=$(${CLIENT_EXE} keys get ${RICH} | awk '{print $2}')
|
||||
${SERVER_EXE} init --chain-id $CHAIN $GENKEY --home=$SERVE_DIR >>$SERVER_LOG
|
||||
|
||||
# optionally set the port
|
||||
if [ -n "$3" ]; then
|
||||
echo "setting port $3"
|
||||
sed -ie "s/4665/$3/" $SERVE_DIR/config.toml
|
||||
fi
|
||||
# optionally set the port
|
||||
if [ -n "$3" ]; then
|
||||
echo "setting port $3"
|
||||
sed -ie "s/4665/$3/" $SERVE_DIR/config.toml
|
||||
fi
|
||||
|
||||
echo "Starting ${SERVER_EXE} server..."
|
||||
startServer $SERVE_DIR $SERVER_LOG
|
||||
return $?
|
||||
echo "Starting ${SERVER_EXE} server..."
|
||||
startServer $SERVE_DIR $SERVER_LOG
|
||||
return $?
|
||||
}
|
||||
|
||||
# XXX Ex Usage: startServer $SERVE_DIR $SERVER_LOG
|
||||
startServer() {
|
||||
${SERVER_EXE} start --home=$1 >>$2 2>&1 &
|
||||
sleep 5
|
||||
PID_SERVER=$!
|
||||
disown
|
||||
if ! ps $PID_SERVER >/dev/null; then
|
||||
echo "**FAILED**"
|
||||
cat $SERVER_LOG
|
||||
return 1
|
||||
fi
|
||||
${SERVER_EXE} start --home=$1 >>$2 2>&1 &
|
||||
sleep 5
|
||||
PID_SERVER=$!
|
||||
disown
|
||||
if ! ps $PID_SERVER >/dev/null; then
|
||||
echo "**FAILED**"
|
||||
cat $SERVER_LOG
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# XXX Ex Usage1: initClient $CHAINID
|
||||
|
@ -95,86 +96,86 @@ startServer() {
|
|||
# Desc: Initialize the client program
|
||||
# port-prefix default is 46657
|
||||
initClient() {
|
||||
echo "Attaching ${CLIENT_EXE} client..."
|
||||
PORT=${2:-46657}
|
||||
# hard-code the expected validator hash
|
||||
${CLIENT_EXE} init --chain-id=$1 --node=tcp://localhost:${PORT} --valhash=EB168E17E45BAEB194D4C79067FFECF345C64DE6
|
||||
assertTrue "initialized light-client" $?
|
||||
echo "Attaching ${CLIENT_EXE} client..."
|
||||
PORT=${2:-46657}
|
||||
# hard-code the expected validator hash
|
||||
${CLIENT_EXE} init --chain-id=$1 --node=tcp://localhost:${PORT} --valhash=EB168E17E45BAEB194D4C79067FFECF345C64DE6
|
||||
assertTrue "initialized light-client" $?
|
||||
}
|
||||
|
||||
# XXX Ex Usage1: newKey $NAME
|
||||
# XXX Ex Usage2: newKey $NAME $PASSWORD
|
||||
# Desc: Generates key for given username and password
|
||||
newKey(){
|
||||
assertNotNull "keyname required" "$1"
|
||||
KEYPASS=${2:-qwertyuiop}
|
||||
(echo $KEYPASS; echo $KEYPASS) | ${CLIENT_EXE} keys new $1 >/dev/null 2>/dev/null
|
||||
assertTrue "created $1" $?
|
||||
assertTrue "$1 doesn't exist" "${CLIENT_EXE} keys get $1"
|
||||
assertNotNull "keyname required" "$1"
|
||||
KEYPASS=${2:-qwertyuiop}
|
||||
(echo $KEYPASS; echo $KEYPASS) | ${CLIENT_EXE} keys new $1 >/dev/null 2>/dev/null
|
||||
assertTrue "created $1" $?
|
||||
assertTrue "$1 doesn't exist" "${CLIENT_EXE} keys get $1"
|
||||
}
|
||||
|
||||
# XXX Ex Usage: getAddr $NAME
|
||||
# Desc: Gets the address for a key name
|
||||
getAddr() {
|
||||
assertNotNull "keyname required" "$1"
|
||||
RAW=$(${CLIENT_EXE} keys get $1)
|
||||
assertTrue "no key for $1" $?
|
||||
# print the addr
|
||||
echo $RAW | cut -d' ' -f2
|
||||
assertNotNull "keyname required" "$1"
|
||||
RAW=$(${CLIENT_EXE} keys get $1)
|
||||
assertTrue "no key for $1" $?
|
||||
# print the addr
|
||||
echo $RAW | cut -d' ' -f2
|
||||
}
|
||||
|
||||
# Desc: Assumes just one coin, checks the balance of first coin in any case
|
||||
checkAccount() {
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query account $1)
|
||||
if ! assertTrue "account must exist" $?; then
|
||||
return 1
|
||||
fi
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query account $1)
|
||||
if ! assertTrue "account must exist" $?; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -n "$DEBUG" ]; then echo $ACCT; echo; fi
|
||||
assertEquals "proper sequence" "$2" $(echo $ACCT | jq .data.sequence)
|
||||
assertEquals "proper money" "$3" $(echo $ACCT | jq .data.coins[0].amount)
|
||||
return $?
|
||||
if [ -n "$DEBUG" ]; then echo $ACCT; echo; fi
|
||||
assertEquals "proper sequence" "$2" $(echo $ACCT | jq .data.sequence)
|
||||
assertEquals "proper money" "$3" $(echo $ACCT | jq .data.coins[0].amount)
|
||||
return $?
|
||||
}
|
||||
|
||||
# XXX Ex Usage: txSucceeded $? "$TX"
|
||||
# Desc: Must be called right after the `tx` command, makes sure it got a success response
|
||||
txSucceeded() {
|
||||
if (assertTrue "sent tx: $2" $1); then
|
||||
TX=$2
|
||||
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
|
||||
if (assertTrue "sent tx: $2" $1); then
|
||||
TX=$2
|
||||
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
|
||||
}
|
||||
|
||||
# XXX Ex Usage: checkSendTx $HASH $HEIGHT $SENDER $AMOUNT
|
||||
# Desc: This looks up the tx by hash, and makes sure the height and type match
|
||||
# and that the first input was from this sender for this amount
|
||||
checkSendTx() {
|
||||
TX=$(${CLIENT_EXE} query tx $1)
|
||||
assertTrue "found tx" $?
|
||||
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
|
||||
TX=$(${CLIENT_EXE} query tx $1)
|
||||
assertTrue "found tx" $?
|
||||
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
|
||||
|
||||
assertEquals "proper height" $2 $(echo $TX | jq .height)
|
||||
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 $?
|
||||
assertEquals "proper height" $2 $(echo $TX | jq .height)
|
||||
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 $?
|
||||
}
|
||||
|
||||
# XXX Ex Usage: waitForBlock $port
|
||||
# Desc: 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
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,84 +8,84 @@ RICH=${ACCOUNTS[0]}
|
|||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
quickSetup .basecoin_test_counter counter-chain
|
||||
quickSetup .basecoin_test_counter counter-chain
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
quickTearDown
|
||||
quickTearDown
|
||||
}
|
||||
|
||||
test00GetAccount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account"
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account"
|
||||
|
||||
checkAccount $SENDER "0" "9007199254740992"
|
||||
checkAccount $SENDER "0" "9007199254740992"
|
||||
|
||||
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
|
||||
assertFalse "has no genesis account" $?
|
||||
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
|
||||
assertFalse "has no genesis account" $?
|
||||
}
|
||||
|
||||
test01SendTx() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
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"
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
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"
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
}
|
||||
|
||||
test02GetCounter() {
|
||||
COUNT=$(${CLIENT_EXE} query counter 2>/dev/null)
|
||||
assertFalse "no default count" $?
|
||||
COUNT=$(${CLIENT_EXE} query counter 2>/dev/null)
|
||||
assertFalse "no default count" $?
|
||||
}
|
||||
|
||||
# checkCounter $COUNT $BALANCE
|
||||
# Assumes just one coin, checks the balance of first coin in any case
|
||||
checkCounter() {
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query counter)
|
||||
assertTrue "count is set" $?
|
||||
assertEquals "proper count" "$1" $(echo $ACCT | jq .data.Counter)
|
||||
assertEquals "proper money" "$2" $(echo $ACCT | jq .data.TotalFees[0].amount)
|
||||
# make sure sender goes down
|
||||
ACCT=$(${CLIENT_EXE} query counter)
|
||||
assertTrue "count is set" $?
|
||||
assertEquals "proper count" "$1" $(echo $ACCT | jq .data.Counter)
|
||||
assertEquals "proper money" "$2" $(echo $ACCT | jq .data.TotalFees[0].amount)
|
||||
}
|
||||
|
||||
test03AddCount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
assertFalse "bad password" "echo hi | ${CLIENT_EXE} tx counter --amount=1000mycoin --sequence=2 --name=${RICH} 2>/dev/null"
|
||||
SENDER=$(getAddr $RICH)
|
||||
assertFalse "bad password" "echo hi | ${CLIENT_EXE} tx counter --amount=1000mycoin --sequence=2 --name=${RICH} 2>/dev/null"
|
||||
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --amount=10mycoin --sequence=2 --name=${RICH} --valid --countfee=5mycoin)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --amount=10mycoin --sequence=2 --name=${RICH} --valid --countfee=5mycoin)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
checkCounter "1" "5"
|
||||
checkCounter "1" "5"
|
||||
|
||||
# FIXME: cannot load apptx properly.
|
||||
# Look at the stack trace
|
||||
# This cannot be fixed with the current ugly apptx structure...
|
||||
# Leave for refactoring
|
||||
# FIXME: cannot load apptx properly.
|
||||
# Look at the stack trace
|
||||
# This cannot be fixed with the current ugly apptx structure...
|
||||
# Leave for refactoring
|
||||
|
||||
# make sure tx is indexed
|
||||
# echo hash $HASH
|
||||
# TX=$(${CLIENT_EXE} query tx $HASH --trace)
|
||||
# echo tx $TX
|
||||
# if [-z assertTrue "found tx" $?]; then
|
||||
# assertEquals "proper height" $TX_HEIGHT $(echo $TX | jq .height)
|
||||
# assertEquals "type=app" '"app"' $(echo $TX | jq .data.type)
|
||||
# assertEquals "proper sender" "\"$SENDER\"" $(echo $TX | jq .data.data.input.address)
|
||||
# fi
|
||||
# echo $TX
|
||||
# make sure tx is indexed
|
||||
# echo hash $HASH
|
||||
# TX=$(${CLIENT_EXE} query tx $HASH --trace)
|
||||
# echo tx $TX
|
||||
# if [-z assertTrue "found tx" $?]; then
|
||||
# assertEquals "proper height" $TX_HEIGHT $(echo $TX | jq .height)
|
||||
# assertEquals "type=app" '"app"' $(echo $TX | jq .data.type)
|
||||
# assertEquals "proper sender" "\"$SENDER\"" $(echo $TX | jq .data.data.input.address)
|
||||
# fi
|
||||
# echo $TX
|
||||
}
|
||||
|
||||
# Load common then run these tests with shunit2!
|
||||
|
|
236
tests/cli/ibc.sh
236
tests/cli/ibc.sh
|
@ -13,163 +13,163 @@ POOR=${ACCOUNTS[4]}
|
|||
# CLIENT_EXE="basecli --trace"
|
||||
|
||||
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
|
||||
PREFIX_1=1234
|
||||
PORT_1=${PREFIX_1}7
|
||||
# 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
|
||||
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
|
||||
PREFIX_2=2345
|
||||
PORT_2=${PREFIX_2}7
|
||||
BASE_DIR_2=$HOME/.basecoin_test_ibc/chain2
|
||||
CHAIN_ID_2=test-chain-2
|
||||
CLIENT_2=${BASE_DIR_2}/client
|
||||
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
|
||||
mkdir -p $BASE_DIR_1 $BASE_DIR_2
|
||||
# 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
|
||||
# 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 $PREFIX_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_1=$PID_SERVER
|
||||
# Start basecoin server, giving money to the key in the first client
|
||||
BC_HOME=${CLIENT_1} initServer $BASE_DIR_1 $CHAIN_ID_1 $PREFIX_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_1=$PID_SERVER
|
||||
|
||||
# Start second basecoin server, giving money to the key in the second client
|
||||
BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 $PREFIX_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_2=$PID_SERVER
|
||||
# Start second basecoin server, giving money to the key in the second client
|
||||
BC_HOME=${CLIENT_2} initServer $BASE_DIR_2 $CHAIN_ID_2 $PREFIX_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
PID_SERVER_2=$PID_SERVER
|
||||
|
||||
# Connect both clients
|
||||
BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 $PORT_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 $PORT_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
# Connect both clients
|
||||
BC_HOME=${CLIENT_1} initClient $CHAIN_ID_1 $PORT_1
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
BC_HOME=${CLIENT_2} initClient $CHAIN_ID_2 $PORT_2
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
printf "\n\nstopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2"
|
||||
kill -9 $PID_SERVER_1
|
||||
kill -9 $PID_SERVER_2
|
||||
sleep 1
|
||||
printf "\n\nstopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2"
|
||||
kill -9 $PID_SERVER_1
|
||||
kill -9 $PID_SERVER_2
|
||||
sleep 1
|
||||
}
|
||||
|
||||
test00GetAccount() {
|
||||
SENDER_1=$(BC_HOME=${CLIENT_1} getAddr $RICH)
|
||||
RECV_1=$(BC_HOME=${CLIENT_1} getAddr $POOR)
|
||||
export BC_HOME=${CLIENT_1}
|
||||
SENDER_1=$(BC_HOME=${CLIENT_1} getAddr $RICH)
|
||||
RECV_1=$(BC_HOME=${CLIENT_1} getAddr $POOR)
|
||||
export BC_HOME=${CLIENT_1}
|
||||
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
|
||||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1 2>/dev/null"
|
||||
checkAccount $SENDER_1 "0" "9007199254740992"
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
|
||||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1 2>/dev/null"
|
||||
checkAccount $SENDER_1 "0" "9007199254740992"
|
||||
|
||||
export BC_HOME=${CLIENT_2}
|
||||
SENDER_2=$(getAddr $RICH)
|
||||
RECV_2=$(getAddr $POOR)
|
||||
export BC_HOME=${CLIENT_2}
|
||||
SENDER_2=$(getAddr $RICH)
|
||||
RECV_2=$(getAddr $POOR)
|
||||
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
|
||||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2 2>/dev/null"
|
||||
checkAccount $SENDER_2 "0" "9007199254740992"
|
||||
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
|
||||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2 2>/dev/null"
|
||||
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"
|
||||
# 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"
|
||||
}
|
||||
|
||||
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)
|
||||
# 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)
|
||||
|
||||
export BC_HOME=${CLIENT_1}
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20002mycoin \
|
||||
--sequence=1 --to=${CHAIN_ID_2}/${RECV} --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
# an example to quit early if there is no point in more tests
|
||||
if [ $? != 0 ]; then echo "aborting!"; return 1; fi
|
||||
export BC_HOME=${CLIENT_1}
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20002mycoin \
|
||||
--sequence=1 --to=${CHAIN_ID_2}/${RECV} --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
# an example to quit early if there is no point in more tests
|
||||
if [ $? != 0 ]; then echo "aborting!"; return 1; fi
|
||||
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
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 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}
|
||||
assertFalse "no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV"
|
||||
# Make sure nothing arrived - yet
|
||||
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"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
# 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"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
# Give it a little time, then make sure the money arrived
|
||||
echo "waiting for relay..."
|
||||
sleep 1
|
||||
waitForBlock ${PORT_1}
|
||||
waitForBlock ${PORT_2}
|
||||
# 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"
|
||||
# Check the new account
|
||||
echo "checking ibc recipient..."
|
||||
BC_HOME=${CLIENT_2} checkAccount $RECV "0" "20002"
|
||||
|
||||
# Stop relay
|
||||
printf "stoping relay\n"
|
||||
kill -9 $PID_RELAY
|
||||
# Stop relay
|
||||
printf "stoping relay\n"
|
||||
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 \")
|
||||
echo starting relay $PID_RELAY ...
|
||||
# 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 \")
|
||||
echo starting relay $PID_RELAY ...
|
||||
|
||||
# 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)
|
||||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain1!"; return 1; fi
|
||||
# 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)
|
||||
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)
|
||||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain2!"; 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)
|
||||
txSucceeded $? "$RES"
|
||||
if [ $? != 0 ]; then echo "can't pay chain2!"; return 1; fi
|
||||
|
||||
# Initialize the relay (register both chains)
|
||||
${SERVER_EXE} relay init --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--genesis1=${BASE_DIR_1}/server/genesis.json --genesis2=${BASE_DIR_2}/server/genesis.json \
|
||||
--from=$RELAY_KEY > ${BASE_DIR_1}/../relay.log
|
||||
if [ $? != 0 ]; then echo "can't initialize relays"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
# Initialize the relay (register both chains)
|
||||
${SERVER_EXE} relay init --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--genesis1=${BASE_DIR_1}/server/genesis.json --genesis2=${BASE_DIR_2}/server/genesis.json \
|
||||
--from=$RELAY_KEY > ${BASE_DIR_1}/../relay.log
|
||||
if [ $? != 0 ]; then echo "can't initialize relays"; cat ${BASE_DIR_1}/../relay.log; return 1; fi
|
||||
|
||||
# Now start the relay (constantly send packets)
|
||||
${SERVER_EXE} relay start --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--from=$RELAY_KEY >> ${BASE_DIR_1}/../relay.log &
|
||||
sleep 2
|
||||
PID_RELAY=$!
|
||||
disown
|
||||
# Now start the relay (constantly send packets)
|
||||
${SERVER_EXE} relay start --chain1-id=$CHAIN_ID_1 --chain2-id=$CHAIN_ID_2 \
|
||||
--chain1-addr=tcp://localhost:${PORT_1} --chain2-addr=tcp://localhost:${PORT_2} \
|
||||
--from=$RELAY_KEY >> ${BASE_DIR_1}/../relay.log &
|
||||
sleep 2
|
||||
PID_RELAY=$!
|
||||
disown
|
||||
|
||||
# Return an error if it dies in the first two seconds to make sure it is running
|
||||
ps $PID_RELAY >/dev/null
|
||||
return $?
|
||||
# Return an error if it dies in the first two seconds to make sure it is running
|
||||
ps $PID_RELAY >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
# Load common then run these tests with shunit2!
|
||||
|
|
|
@ -8,77 +8,74 @@ RICH=${ACCOUNTS[0]}
|
|||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
quickSetup .basecoin_test_restart restart-chain
|
||||
quickSetup .basecoin_test_restart restart-chain
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
quickTearDown
|
||||
quickTearDown
|
||||
}
|
||||
|
||||
test00PreRestart() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
|
||||
}
|
||||
|
||||
test01OnRestart() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=10000mycoin --sequence=2 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
if [ $? != 0 ]; then echo "can't make tx!"; return 1; fi
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=10000mycoin --sequence=2 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
if [ $? != 0 ]; then echo "can't make tx!"; return 1; fi
|
||||
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
# wait til we have quite a few blocks... like at least 20,
|
||||
# so the query command won't just wait for the next eg. 7 blocks to verify the result
|
||||
echo "waiting to generate lots of blocks..."
|
||||
sleep 5
|
||||
echo "done waiting!"
|
||||
# wait til we have quite a few blocks... like at least 20,
|
||||
# so the query command won't just wait for the next eg. 7 blocks to verify the result
|
||||
echo "waiting to generate lots of blocks..."
|
||||
sleep 5
|
||||
echo "done waiting!"
|
||||
|
||||
# last minute tx just at the block cut-off...
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20000mycoin --sequence=3 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
if [ $? != 0 ]; then echo "can't make second tx!"; return 1; fi
|
||||
# last minute tx just at the block cut-off...
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20000mycoin --sequence=3 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX"
|
||||
if [ $? != 0 ]; then echo "can't make second tx!"; return 1; fi
|
||||
|
||||
# now we do a restart...
|
||||
quickTearDown
|
||||
startServer $BASE_DIR/server $BASE_DIR/${SERVER_EXE}.log
|
||||
if [ $? != 0 ]; then echo "can't restart server!"; return 1; fi
|
||||
# now we do a restart...
|
||||
quickTearDown
|
||||
startServer $BASE_DIR/server $BASE_DIR/${SERVER_EXE}.log
|
||||
if [ $? != 0 ]; then echo "can't restart server!"; return 1; fi
|
||||
|
||||
# make sure queries still work properly, with all 3 tx now executed
|
||||
echo "Checking state after restart..."
|
||||
checkAccount $SENDER "3" "9007199254710000"
|
||||
checkAccount $RECV "0" "30992"
|
||||
# make sure queries still work properly, with all 3 tx now executed
|
||||
echo "Checking state after restart..."
|
||||
checkAccount $SENDER "3" "9007199254710000"
|
||||
checkAccount $RECV "0" "30992"
|
||||
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "10000"
|
||||
# make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "10000"
|
||||
|
||||
# for double-check of logs
|
||||
if [ -n "$DEBUG" ]; then
|
||||
cat $BASE_DIR/${SERVER_EXE}.log;
|
||||
fi
|
||||
# for double-check of logs
|
||||
if [ -n "$DEBUG" ]; then
|
||||
cat $BASE_DIR/${SERVER_EXE}.log;
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
# Load common then run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
|
||||
# load common helpers
|
||||
. $DIR/common.sh
|
||||
|
||||
. $DIR/shunit2
|
||||
|
||||
|
|
Loading…
Reference in New Issue