Starting bash cli tests
This commit is contained in:
parent
282a157997
commit
66c9010bcb
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
vendor
|
||||
merkleeyes.db
|
||||
build
|
||||
shunit2
|
||||
|
||||
18
Makefile
18
Makefile
@ -3,7 +3,7 @@ GOTOOLS = \
|
||||
github.com/Masterminds/glide
|
||||
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
|
||||
|
||||
all: test install
|
||||
all: get_vendor_deps test install
|
||||
|
||||
build:
|
||||
go build ./cmd/...
|
||||
@ -15,15 +15,23 @@ dist:
|
||||
@bash scripts/dist.sh
|
||||
@bash scripts/publish.sh
|
||||
|
||||
clitest/shunit2:
|
||||
wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \
|
||||
-q -O clitest/shunit2
|
||||
|
||||
test_cli: clitest/shunit2
|
||||
@./clitest/basictx.sh
|
||||
# @./clitest/ibc.sh
|
||||
|
||||
test:
|
||||
go test $(PACKAGES)
|
||||
#go run tests/tendermint/*.go
|
||||
|
||||
get_deps:
|
||||
go get -d ./...
|
||||
# get_deps:
|
||||
# go get -d ./...
|
||||
|
||||
update_deps:
|
||||
go get -d -u ./...
|
||||
# update_deps:
|
||||
# go get -d -u ./...
|
||||
|
||||
get_vendor_deps: tools
|
||||
glide install
|
||||
|
||||
107
clitest/basictx.sh
Executable file
107
clitest/basictx.sh
Executable file
@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
|
||||
oneTimeSetUp() {
|
||||
BASE_DIR=$HOME/.basecoin_test_basictx
|
||||
LOG=$BASE_DIR/test.log
|
||||
SERVER_LOG=$BASE_DIR/basecoin.log
|
||||
|
||||
rm -rf $BASE_DIR
|
||||
mkdir -p $BASE_DIR
|
||||
|
||||
ACCOUNTS=(jae ethan bucky rigel igor)
|
||||
RICH=${ACCOUNTS[0]}
|
||||
POOR=${ACCOUNTS[1]}
|
||||
|
||||
# set up client
|
||||
prepareClient
|
||||
|
||||
# start basecoin server (with counter)
|
||||
initServer
|
||||
sleep 5
|
||||
PID_SERVER=$!
|
||||
echo pid $PID_SERVER
|
||||
|
||||
initClient
|
||||
|
||||
echo "...Testing may begin!"
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
echo "stopping basecoin test server"
|
||||
kill -9 $PID_SERVER
|
||||
sleep 1
|
||||
}
|
||||
|
||||
prepareClient() {
|
||||
echo "Preparing client keys..."
|
||||
export BC_HOME=$BASE_DIR/client
|
||||
basecli reset_all
|
||||
assertTrue $?
|
||||
|
||||
for i in "${!ACCOUNTS[@]}"; do
|
||||
newKey ${ACCOUNTS[$i]}
|
||||
done
|
||||
}
|
||||
|
||||
initServer() {
|
||||
echo "Setting up genesis..."
|
||||
SERVE_DIR=$BASE_DIR/server
|
||||
rm -rf $SERVE_DIR 2>/dev/null
|
||||
basecoin init --home=$SERVE_DIR >>$SERVER_LOG
|
||||
|
||||
#change the genesis to the first account
|
||||
GENKEY=$(basecli keys get ${RICH} -o json | jq .pubkey.data)
|
||||
GENJSON=$(cat $SERVE_DIR/genesis.json)
|
||||
echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY > $SERVE_DIR/genesis.json
|
||||
|
||||
echo "Starting server..."
|
||||
basecoin start --home=$SERVE_DIR >>$SERVER_LOG 2>&1 &
|
||||
}
|
||||
|
||||
initClient() {
|
||||
echo "Attaching client..."
|
||||
# hard-code the expected validator hash
|
||||
basecli init --chainid=test_chain_id --node=tcp://localhost:46657 --valhash=EB168E17E45BAEB194D4C79067FFECF345C64DE6
|
||||
assertTrue "initialized light-client" $?
|
||||
}
|
||||
|
||||
# newKeys makes a key for a given username, second arg optional password
|
||||
newKey(){
|
||||
assertNotNull "keyname required" "$1"
|
||||
KEYPASS=${2:-qwertyuiop}
|
||||
(echo $KEYPASS; echo $KEYPASS) | basecli keys new $1 >>$LOG 2>/dev/null
|
||||
assertTrue "created $1" $?
|
||||
assertTrue "$1 doesn't exist" "basecli keys get $1"
|
||||
}
|
||||
|
||||
# getAddr gets the address for a key name
|
||||
getAddr() {
|
||||
assertNotNull "keyname required" "$1"
|
||||
RAW=$(basecli keys get $1)
|
||||
assertTrue "no key for $1" $?
|
||||
# print the addr
|
||||
echo $RAW | cut -d' ' -f2
|
||||
}
|
||||
|
||||
testGetAccount() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
echo sender $RICH
|
||||
echo $SENDER
|
||||
|
||||
echo recipient $POOR
|
||||
echo $RECV
|
||||
|
||||
assertFalse "requires arg" "basecli query account"
|
||||
ACCT=$(basecli query account $SENDER)
|
||||
assertTrue "must have proper genesis account" $?
|
||||
echo $ACCT
|
||||
}
|
||||
|
||||
# load and run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
. $DIR/shunit2
|
||||
3
clitest/ibc.sh
Executable file
3
clitest/ibc.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "ibc test not implemented"
|
||||
Loading…
Reference in New Issue
Block a user