Skip to content

Commit

Permalink
Starting bash cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 15, 2017
1 parent 282a157 commit 66c9010
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
vendor
merkleeyes.db
build
shunit2
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand All @@ -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
Expand Down
107 changes: 107 additions & 0 deletions clitest/basictx.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions clitest/ibc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "ibc test not implemented"

0 comments on commit 66c9010

Please sign in to comment.