diff --git a/circle.yml b/circle.yml index 4e74a43a09699cf736f3ea1404d3d996e5d0b08d..494e7ad29578abb13892fe10337809decdd36153 100644 --- a/circle.yml +++ b/circle.yml @@ -23,6 +23,8 @@ dependencies: test: pre: + # jq is a dependency for the integration framework + - sudo apt-get install jq curl - go get github.com/Masterminds/glide - cd $REPO && glide install # Test the build target for eris-db @@ -30,13 +32,13 @@ test: - cd $REPO && go install ./cmd/eris-db && eris-db --help # Test the build target for eris-client - echo "Build target eris-client..." - - cd $REPO && go install ./client/cmd/eris-client && echo eris-client --help + - cd $REPO && go install ./client/cmd/eris-client && eris-client --help override: # We only wish to test our packages not vendored ones - echo "Running unit tests..." - cd $REPO && glide novendor | xargs go test -tags integration - echo "Running integration tests..." - # - cd $REPO && "tests/circle_test.sh | tee $CIRCLE_ARTIFACTS/output.log; test ${PIPESTATUS[0]} -eq 0" + - cd $REPO && "tests/circle_test.sh | tee $CIRCLE_ARTIFACTS/output.log; test ${PIPESTATUS[0]} -eq 0" deployment: master: diff --git a/tests/circle_test.sh b/tests/circle_test.sh index 4619715dcdef42a1da4117beb14cc0d5f20ac36c..5763470d6e381b21db8d851f7db1599029d6c667 100644 --- a/tests/circle_test.sh +++ b/tests/circle_test.sh @@ -11,6 +11,7 @@ # docker installed locally # docker-machine installed locally # eris installed locally +# jq installed locally # ---------------------------------------------------------- # USAGE @@ -56,7 +57,7 @@ echo # ---------------------------------------------------------- # Run integration tests -tests/test.sh +tests/test_client.sh test_exit=$? # ---------------------------------------------------------- diff --git a/tests/test.sh b/tests/test_client.sh similarity index 63% rename from tests/test.sh rename to tests/test_client.sh index 4dfc27083734539b1edcd338e2276960ef7e4d9d..450929b8ffc42dea5c8f6e5c37aaecd8fe9490b2 100644 --- a/tests/test.sh +++ b/tests/test_client.sh @@ -123,13 +123,13 @@ get_uuid() { test_build() { echo "" - echo "Building eris-cm in a docker container." + echo "Building eris-db in a docker container." set -e tests/build_tool.sh 1>/dev/null set +e if [ $? -ne 0 ] then - echo "Could not build eris-cm. Debug via by directly running [`pwd`/tests/build_tool.sh]" + echo "Could not build eris-db. Debug via by directly running [`pwd`/tests/build_tool.sh]" exit 1 fi echo "Build complete." @@ -147,72 +147,87 @@ test_setup(){ echo "Setup complete" } -check_test(){ - # check chain is running - chain=( $(eris chains ls --quiet --running | grep $uuid) ) - if [ ${#chain[@]} -ne 1 ] +start_chain(){ + echo + echo "starting new chain for client tests..." + if [ $? -ne 0 ] then - echo "chain does not appear to be running" - echo - ls -la $dir_to_use test_exit=1 return 1 fi - - # check results file exists - if [ ! -e "$chains_dir/$uuid/accounts.csv" ] + eris chains make $uuid --account-types=Participant:2,Validator:1 + eris chains new $uuid --dir "$uuid"/"$uuid"_validator_000 + if [ $? -ne 0 ] then - echo "accounts.csv not present" - ls -la $chains_dir/$uuid - pwd - ls -la $chains_dir test_exit=1 return 1 fi + sleep 3 # let 'er boot + + # set variables for chain + CHAIN_ID=$uuid + eris_client_ip=$(eris chains inspect $uuid NetworkSettings.IPAddress) + ERIS_CLIENT_NODE_ADDRESS="tcp://$(eris chains inspect $uuid NetworkSettings.IPAddress):46657" + ERIS_CLIENT_SIGN_ADDRESS="http://$(eris services inspect keys NetworkSettings.IPAddress):4767" + echo "node address: " $ERIS_CLIENT_NODE_ADDRESS + echo "keys address: " $ERIS_CLIENT_SIGN_ADDRESS + + # set addresses from participants + participant_000_address=$(cat $chains_dir/accounts.json | jq '. | ."$uuid"_participant_000.address') + participant_001_address=$(cat $chains_dir/accounts.json | jq '. | ."$uuid"_participant_001.address') + } + + stop_chain(){ + echo + echo "stopping test chain for client tests..." + eris chains stop --force $uuid + if [ ! "$ci" = true ] + then + eris chains rm --data $uuid + fi + rm -rf $HOME/.eris/scratch/data/$uuid + rm -rf $chains_dir/$uuid +} - # check genesis.json - genOut=$(cat $dir_to_use/genesis.json | sed 's/[[:space:]]//g') - genIn=$(eris chains plop $uuid genesis | sed 's/[[:space:]]//g') - if [[ "$genOut" != "$genIn" ]] +perform_client_tests(){ + uuid=$(get_uuid) + start_chain + + echo + echo "simplest client send transaction test" + amount=1000 + eris-client tx send --amt $amount -addr $participant_000_address --to $participant_001_address + sleep 2 # poll for resulting state - sleeping, rather than waiting for confirmation + sender_amt=$(curl "$eris_client_ip"/get_account?address=$participant_000_address | jq '. | .result[1].account.balance') + receiver_amt=$(curl "$eris_client_ip"/get_account?address=$participant_001_address | jq '. | .result[1].account.balance') + difference='expr $receiver_amt - $sender_amt' + if [[ "$difference" != "$amount" ]] then - test_exit=1 - echo "genesis.json's do not match" - echo - echo "expected" - echo - echo -e "$genOut" - echo - echo "received" - echo - echo -e "$genIn" - echo - echo "difference" - echo - diff <(echo "$genOut" ) <(echo "$genIn") | colordiff + echo "simple send transaction failed" return 1 fi + echo + stop_chain +} - # check priv_validator - privOut=$(cat $dir_to_use/priv_validator.json | tr '\n' ' ' | sed 's/[[:space:]]//g' | set 's/(,\"last_height\":[^0-9]+,\"last_round\":[^0-9]+,\"last_step\":[^0-9]+//g' ) - privIn=$(eris data exec $uuid "cat /home/eris/.eris/chains/$uuid/priv_validator.json" | tr '\n' ' ' | sed 's/[[:space:]]//g' | set 's/(,\"last_height\":[^0-9]+,\"last_round\":[^0-9]+,\"last_step\":[^0-9]+//g' ) - if [[ "$privOut" != "$privIn" ]] +test_teardown(){ + if [ "$ci" = false ] then - test_exit=1 - echo "priv_validator.json's do not match" - echo - echo "expected" - echo - echo -e "$privOut" - echo - echo "received" - echo - echo -e "$privIn" echo - echo "difference" + if [ "$was_running" -eq 0 ] + then + eris services stop -rx keys + fi echo - diff <(echo "$privOut" ) <(echo "$privIn") | colordiff - return 1 fi + if [ "$test_exit" -eq 0 ] + then + echo "Tests complete! Tests are Green. :)" + else + echo "Tests complete. Tests are Red. :(" + fi + cd $start + exit $test_exit } # --------------------------------------------------------------------------- @@ -234,7 +249,7 @@ echo # Go ahead with client integration tests ! echo "Running Client Tests..." -# perform_client_tests +perform_client_tests # --------------------------------------------------------------------------- # Cleaning up