Skip to content

Commit

Permalink
Implement tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Oct 5, 2022
1 parent acda7b6 commit 663fadd
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ display-all-java-steps:
find src/test/java/com/algorand/algosdk -name "*.java" | xargs grep "io.cucumber.java.en" 2>/dev/null | grep -v Binary | cut -d: -f1 | sort | uniq | xargs grep -E "@(Given|Then|When)"

harness:
./test-harness.sh
./test-harness.sh up

harness-down:
./test-harness.sh down

docker-javasdk-build:
# Build SDK testing environment
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/algorand/algosdk/unit/AlgodPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ public void getLightBlockHeaderProof(Long round) {
public void getStateProof(Long round) {
ps.q = algodClient.GetStateProof(round);
}

@When("we make a Lookup Block Hash call against round {long}")
public void getBlockHash(Long round) {
ps.q = algodClient.GetBlockHash(round);
}
}
9 changes: 9 additions & 0 deletions src/test/java/com/algorand/algosdk/unit/IndexerPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,13 @@ public void searchForApplications(String string) {
ps.q = q;
}


@When("we make a Lookup Block call against round {long} and header {string}")
public void anyBlockLookupCall(Long round, String headerOnly) {
LookupBlock q = this.indexerClient.lookupBlock(round);
headerOnly = headerOnly.toLowerCase();
if (headerOnly.contentEquals("true")) q.headerOnly(true);
if (headerOnly.contentEquals("false")) q.headerOnly(false);
ps.q = q;
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/algorand/algosdk/unit/ResponsesShared.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public void we_make_any_call_to(String client, String endpoint) throws Exception
Response<StateProof> r = algod.GetStateProof(1234L).execute();
response = r;
break;
case "GetBlockHash":
response = algod.GetBlockHash(1234L).execute();
break;
default:
Assertions.fail("Unsupported algod endpoint: " + endpoint);
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/unit.tags
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@unit.abijson
@unit.abijson.byname
@unit.algod
@unit.algod.blockhash
@unit.algod.ledger_refactoring
@unit.applications
@unit.atomic_transaction_composer
@unit.dryrun
@unit.dryrun.trace.application
@unit.feetest
@unit.indexer
@unit.indexer.blocks
@unit.indexer.ledger_refactoring
@unit.indexer.logs
@unit.indexer.rekey
Expand All @@ -19,6 +21,8 @@
@unit.responses.messagepack
@unit.responses.messagepack.231
@unit.responses.unlimited_assets
@unit.responses.blockhash
@unit.responses.block.headeronly
@unit.sourcemap
@unit.stateproof.paths
@unit.stateproof.responses
Expand Down
55 changes: 55 additions & 0 deletions test-harness.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

# test-harness.sh setup/start cucumber test environment.
#
# Configuration is managed with environment variables, the ones you
# are most likely to reconfigured are stored in '.test-env'.
#
# Variables:
# SDK_TESTING_URL - URL to algorand-sdk-testing, useful for forks.
# SDK_TESTING_BRANCH - branch to checkout, useful for new tests.
# SDK_TESTING_HARNESS - in case you want to change the clone directory?
# VERBOSE_HARNESS - more output while the script runs.
# INSTALL_ONLY - installs feature files only, useful for unit tests.
#
# WARNING: If set to 1, new features will be LOST when downloading the test harness.
# REGARDLESS: modified features are ALWAYS overwritten.
# REMOVE_LOCAL_FEATURES - cleanup cucumber feature files?
#
# WARNING: Be careful when turning on the next variable.
# In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env`
# OVERWRITE_TESTING_ENVIRONMENT=0

SHUTDOWN=0
if [ $# -ne 0 ]; then
if [ $# -ne 1 ]; then
echo "this script accepts a single argument, which must be 'up' or 'down'."
exit 1
fi

case $1 in
'up')
;; # default.
'down')
SHUTDOWN=1
;;
*)
echo "unknown parameter '$1'."
echo "this script accepts a single argument, which must be 'up' or 'down'."
exit 1
;;
esac
fi

START=$(date "+%s")

THIS=$(basename "$0")
Expand All @@ -23,10 +64,19 @@ if [ -d "$SDK_TESTING_HARNESS" ]; then
./scripts/down.sh
popd
rm -rf "$SDK_TESTING_HARNESS"
if [[ $SHUTDOWN == 1 ]]; then
echo "network shutdown complete."
exit 0
fi
else
echo "$THIS: directory $SDK_TESTING_HARNESS does not exist - NOOP"
fi

if [[ $SHUTDOWN == 1 ]]; then
echo "unable to shutdown network."
exit 1
fi

git clone --depth 1 --single-branch --branch "$SDK_TESTING_BRANCH" "$SDK_TESTING_URL" "$SDK_TESTING_HARNESS"


Expand Down Expand Up @@ -63,6 +113,11 @@ if [[ $VERBOSE_HARNESS == 1 ]]; then
fi
echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s"

if [[ $INSTALL_ONLY == 1 ]]; then
echo "$THIS: configured to install feature files only. Not starting test harness environment."
exit 0
fi

## Start test harness environment
pushd "$SDK_TESTING_HARNESS"

Expand Down

0 comments on commit 663fadd

Please sign in to comment.