bash test cleanup
int
This commit is contained in:
committed by
Ethan Frey
parent
22057b910f
commit
a78a24bbe9
+11
-17
@@ -1,19 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=basecoin
|
||||
CLIENT_EXE=basecli
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
# These are passed in as args
|
||||
BASE_DIR=$HOME/.basecoin_test_basictx
|
||||
CHAIN_ID=my-test-chain
|
||||
|
||||
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
|
||||
# Set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
@@ -23,16 +26,11 @@ oneTimeSetUp() {
|
||||
|
||||
initClient $CHAIN_ID 34567
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping $SERVER_EXE test server..."
|
||||
printf "\n\nstopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
}
|
||||
@@ -64,15 +62,11 @@ test01SendTx() {
|
||||
checkAccount $SENDER "1" "9007199254740000"
|
||||
checkAccount $RECV "0" "992"
|
||||
|
||||
# make sure tx is indexed
|
||||
# Make sure tx is indexed
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "992"
|
||||
}
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
+28
-20
@@ -1,9 +1,11 @@
|
||||
# this is not executable, but helper functions for the other scripts
|
||||
# This is not executable, but helper functions for the other scripts
|
||||
|
||||
# these are general accounts to be prepared
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
# XXX XXX XXX XXX XXX
|
||||
# The following global variables must be defined before calling common functions:
|
||||
# SERVER_EXE=foobar # Server binary name
|
||||
# CLIENT_EXE=foobarcli # Client binary name
|
||||
# ACCOUNTS=(foo bar) # List of accounts for initialization
|
||||
# RICH=${ACCOUNTS[0]} # Account to assign genesis balance
|
||||
|
||||
prepareClient() {
|
||||
echo "Preparing client keys..."
|
||||
@@ -15,9 +17,10 @@ prepareClient() {
|
||||
done
|
||||
}
|
||||
|
||||
# initServer takes two args - (root dir, chain_id)
|
||||
# and optionally port prefix as a third arg (default is 4665{6,7,8})
|
||||
# it grabs the first account to give it the money
|
||||
# XXX Ex Usage1: initServer $ROOTDIR $CHAINID
|
||||
# XXX Ex Usage2: initServer $ROOTDIR $CHAINID $PORTPREFIX
|
||||
# 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
|
||||
@@ -46,7 +49,10 @@ initServer() {
|
||||
fi
|
||||
}
|
||||
|
||||
# initClient requires chain_id arg, port is optional (default 46657)
|
||||
# XXX Ex Usage1: initClient $CHAINID
|
||||
# XXX Ex Usage2: initClient $CHAINID $PORTPREFIX
|
||||
# Desc: Initialize the client program
|
||||
# port-prefix default is 46657
|
||||
initClient() {
|
||||
echo "Attaching ${CLIENT_EXE} client..."
|
||||
PORT=${2:-46657}
|
||||
@@ -55,7 +61,9 @@ initClient() {
|
||||
assertTrue "initialized light-client" $?
|
||||
}
|
||||
|
||||
# newKeys makes a key for a given username, second arg optional password
|
||||
# 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}
|
||||
@@ -64,7 +72,8 @@ newKey(){
|
||||
assertTrue "$1 doesn't exist" "${CLIENT_EXE} keys get $1"
|
||||
}
|
||||
|
||||
# getAddr gets the address for a key name
|
||||
# XXX Ex Usage: getAddr $NAME
|
||||
# Desc: Gets the address for a key name
|
||||
getAddr() {
|
||||
assertNotNull "keyname required" "$1"
|
||||
RAW=$(${CLIENT_EXE} keys get $1)
|
||||
@@ -73,8 +82,7 @@ getAddr() {
|
||||
echo $RAW | cut -d' ' -f2
|
||||
}
|
||||
|
||||
# checkAccount $ADDR $SEQUENCE $BALANCE
|
||||
# assumes just one coin, checks the balance of first coin in any case
|
||||
# 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)
|
||||
@@ -84,8 +92,8 @@ checkAccount() {
|
||||
return $?
|
||||
}
|
||||
|
||||
# txSucceeded $? "$RES"
|
||||
# must be called right after the `tx` command, makes sure it got a success response
|
||||
# XXX Ex Usage: txSucceeded $? "$RES"
|
||||
# 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=`echo $2 | cut -d: -f2-` # strip off first line asking for password
|
||||
@@ -96,9 +104,9 @@ txSucceeded() {
|
||||
fi
|
||||
}
|
||||
|
||||
# checkSendTx $HASH $HEIGHT $SENDER $AMOUNT
|
||||
# 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
|
||||
# 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" $?
|
||||
@@ -109,8 +117,8 @@ checkSendTx() {
|
||||
return $?
|
||||
}
|
||||
|
||||
# waitForBlock $port
|
||||
# waits until the block height on that node increases by one
|
||||
# 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`
|
||||
|
||||
+13
-18
@@ -1,19 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=counter
|
||||
CLIENT_EXE=countercli
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
# These are passed in as args
|
||||
BASE_DIR=$HOME/.basecoin_test_counter
|
||||
CHAIN_ID="counter-chain"
|
||||
|
||||
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
|
||||
# Set up client - make sure you use the proper prefix if you set
|
||||
# a custom CLIENT_EXE
|
||||
export BC_HOME=${BASE_DIR}/client
|
||||
prepareClient
|
||||
|
||||
@@ -24,16 +27,11 @@ oneTimeSetUp() {
|
||||
initClient $CHAIN_ID 12347
|
||||
if [ $? != 0 ]; then return 1; fi
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping $SERVER_EXE test server..."
|
||||
printf "\n\nstopping $SERVER_EXE test server..."
|
||||
kill -9 $PID_SERVER >/dev/null 2>&1
|
||||
sleep 1
|
||||
}
|
||||
@@ -75,8 +73,8 @@ test02GetCounter() {
|
||||
assertFalse "no default count" $?
|
||||
}
|
||||
|
||||
# checkAccount $COUNT $BALANCE
|
||||
# assumes just one coin, checks the balance of first coin in any case
|
||||
# CheckAccount $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)
|
||||
@@ -85,7 +83,7 @@ checkCounter() {
|
||||
assertEquals "proper money" "$2" $(echo $ACCT | jq .data.TotalFees[0].amount)
|
||||
}
|
||||
|
||||
test02AddCount() {
|
||||
test03AddCount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
assertFalse "bad password" "echo hi | ${CLIENT_EXE} tx counter --amount=1000mycoin --sequence=2 --name=${RICH} 2>/dev/null"
|
||||
|
||||
@@ -114,10 +112,7 @@ test02AddCount() {
|
||||
# echo $TX
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
+39
-41
@@ -2,14 +2,18 @@
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# these are two globals to control all scripts (can use eg. counter instead)
|
||||
# These global variables are required for common.sh
|
||||
SERVER_EXE=basecoin
|
||||
CLIENT_EXE=basecli
|
||||
# just uncomment this line for full stack traces in error output
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[4]}
|
||||
|
||||
# Uncomment the following line for full stack traces in error output
|
||||
# CLIENT_EXE="basecli --trace"
|
||||
|
||||
oneTimeSetUp() {
|
||||
# these are passed in as args
|
||||
# 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
|
||||
@@ -22,41 +26,36 @@ oneTimeSetUp() {
|
||||
PREFIX_2=2345
|
||||
PORT_2=${PREFIX_2}7
|
||||
|
||||
# clean up and create the test dirs
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
printf "...Testing may begin!\n\n\n"
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo
|
||||
echo
|
||||
echo "stopping both $SERVER_EXE test servers... $PID_SERVER_1 $PID_SERVER_2"
|
||||
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
|
||||
@@ -79,20 +78,21 @@ test00GetAccount() {
|
||||
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2"
|
||||
checkAccount $SENDER_2 "0" "9007199254740992"
|
||||
|
||||
# make sure that they have different addresses on both chains (they are random keys)
|
||||
# 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
|
||||
# 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)
|
||||
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
|
||||
@@ -101,66 +101,67 @@ test01SendIBCTx() {
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
# make sure balance went down and tx is indexed
|
||||
# Make sure balance went down and tx is indexed
|
||||
checkAccount $SENDER "1" "9007199254720990"
|
||||
checkSendTx $HASH $TX_HEIGHT $SENDER "20002"
|
||||
|
||||
# # make sure nothing arrived - yet
|
||||
# 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...
|
||||
# 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
|
||||
# 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
|
||||
# Check the new account
|
||||
echo "checking ibc recipient..."
|
||||
BC_HOME=${CLIENT_2} checkAccount $RECV "0" "20002"
|
||||
|
||||
# stop relay
|
||||
echo "stoping relay"
|
||||
echo
|
||||
# Stop relay
|
||||
printf "stoping relay\n"
|
||||
kill -9 $PID_RELAY
|
||||
}
|
||||
|
||||
# startRelay $seq1 $seq2
|
||||
# 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
|
||||
# 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
|
||||
# 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)
|
||||
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
|
||||
# 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)
|
||||
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
|
||||
|
||||
# initialize the relay (register both chains)
|
||||
# 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)
|
||||
# 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 &
|
||||
@@ -168,15 +169,12 @@ startRelay() {
|
||||
PID_RELAY=$!
|
||||
disown
|
||||
|
||||
# return an error if it dies in the first two seconds to make sure it is running
|
||||
# Return an error if it dies in the first two seconds to make sure it is running
|
||||
ps $PID_RELAY >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user