From 6ce743fbd55e37db06a1aa69580ee8e8bfcde378 Mon Sep 17 00:00:00 2001 From: Tommy Verrall Date: Tue, 21 Feb 2023 17:11:20 +0200 Subject: [PATCH] add the nym-client and tidy up the mixnode next up gateway, socks-5, network-requester --- tests/nym-client-binary-check.sh | 114 ++++++++++++++++++++++++++++++ tests/nym-mixnode-binary-check.sh | 20 ++++-- 2 files changed, 127 insertions(+), 7 deletions(-) create mode 100755 tests/nym-client-binary-check.sh diff --git a/tests/nym-client-binary-check.sh b/tests/nym-client-binary-check.sh new file mode 100755 index 0000000000..c54f40948c --- /dev/null +++ b/tests/nym-client-binary-check.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +set -e + +. assert.sh -v -x + +PWD="../" +RELEASE_DIRECTORY="target/release" +VERSION_NUMBER=$1 +OUTPUT=$(for i in {1..8}; do echo -n $(($RANDOM % 10)); done) +ID="test-${OUTPUT}" +BINARY_NAME="nym-client" + +echo "the version number is ${VERSION_NUMBER} to be installed from github" + +cd ${PWD}${RELEASE_DIRECTORY} + +# steps +# we curl the existing binary from the release page of github +# we init the binary to check successful init +# then in our testing branch, we build the binary locally +# re run the init based upon the configuration injected +# we validate that no errors are return from upgrading the binary against the test + +# install the current release binary +# so this is dependant on running on a linux machine for the time being + +curl -L https://github.com/nymtech/nym/releases/download/nym-binaries-${RELEASE_VERSION_NUMBER}/$BINARY_NAME -o $BINARY_NAME +chmod u+x $BINARY_NAME + +#---------------------------------------------------------------------------------------------------------- +# functions +#---------------------------------------------------------------------------------------------------------- + +check_nym_client_binary_build() if [ -f $BINARY_NAME ]; then + echo "running init tests" + ./${BINARY_NAME} init --id ${ID} --output-json >/dev/null 2>&1 + + # currently this outputs to a file name name + # we currently store the output in a file in the same directory + + if [ -f client_init_results.json ]; then + OUTPUT=$(cat client_init_results.json) + + # get jq values for things we can assert against + # until the service provider is provided in the output we can validate the id is correct on init + VALUE=$(echo ${OUTPUT} | jq .id) + VALUE=${VALUE#\"} + VALUE=${VALUE%\"} + + echo "${OUTPUT}" + sleep 2 + + # do asserts here based upon the output on init + + assert $(echo ${VALUE}) $(echo ${ID}) + assert_end nym-client-tests + else + echo "exting test no binary found" + fi +else + echo "exting test no binary found" +fi + +#---------------------------------------------------------------------------------------------------------- +# tests +#---------------------------------------------------------------------------------------------------------- +# we run the release version first + +check_nym_client_binary_build + +first_init=$(cat /root/.nym/clients/${ID}/config/config.toml | grep -v "^version =") + +#---------------------------------------------------------------------------------------------------------- +# lets remove the binary then navigate to the target/release directory for checking the latest version +# expect to have successful output and configuration +#---------------------------------------------------------------------------------------------------------- + +if [ -f $BINARY_NAME ]; then + echo "removing client binary" + rm -rf $BINARY_NAME +else + echo "no binary found exiting" + exit 1 +fi + +#---------------------------------------------------------------------------------------------------------- +# we should expect it to pass because no errors should be presented when performing the upgrade of an init +# this should be caught at testing stage - navigate to latest binary build +#---------------------------------------------------------------------------------------------------------- + +cd ${PWD}${RELEASE_DIRECTORY} + +# re-run against the current binary built locally + +echo "diff the config files after each init" +echo "-------------------------------------" + +check_nym_client_binary_build + +second_init=$(cat /root/.nym/clients/${ID}/config/config.toml | grep -v "^version =") + +diff -w <(echo "$first_init") <(echo "$second_init") + +# check the status of the diff +if [ $? -eq 0 ]; then + echo "no differences in config files, exiting script" + exit 0 +else + echo "there are differences in the config files, it may require a fresh init on the binary" + exit 1 +fi + +# we should expect it to pass because no errors should be presented when performing the upgrade of an init diff --git a/tests/nym-mixnode-binary-check.sh b/tests/nym-mixnode-binary-check.sh index 35c2a5b9a2..89a4a604b6 100755 --- a/tests/nym-mixnode-binary-check.sh +++ b/tests/nym-mixnode-binary-check.sh @@ -25,14 +25,15 @@ echo "the version number is ${VERSION_NUMBER} to be installed from github" curl -L "https://github.com/nymtech/nym/releases/download/nym-binaries-${RELEASE_VERSION_NUMBER}/${BINARY_NAME}" -o nym-mixnode chmod u+x "$BINARY_NAME" -#-------------------------------------- +#---------------------------------------------------------------------------------------------------------- # functions -#-------------------------------------- +#---------------------------------------------------------------------------------------------------------- + check_mixnode_binary_build() { if [ -f "$BINARY_NAME" ]; then echo "running init tests" # we wont use config env files for now - OUTPUT=$(./${BINARY_NAME} --output json init --id ${ID} --host ${MOCK_HOST} --wallet-address ${WALLET_ADDRESS_CONST} > /dev/null) + OUTPUT=$(./${BINARY_NAME} --output json init --id ${ID} --host ${MOCK_HOST} --wallet-address ${WALLET_ADDRESS_CONST} >/dev/null) # get jq values for things we can assert against # tidy this bit up - okay for first push @@ -46,9 +47,9 @@ check_mixnode_binary_build() { fi } -#------------------------------- +#---------------------------------------------------------------------------------------------------------- # tests -#------------------------------- +#---------------------------------------------------------------------------------------------------------- # we run the release version first check_mixnode_binary_build @@ -65,11 +66,16 @@ else echo "no binary found exiting" exit 1 fi + +#---------------------------------------------------------------------------------------------------------- # we should expect it to pass because no errors should be presented when performing the upgrade of an init -# this should be caught at testing stage -# navigate to latest binary build +# this should be caught at testing stage - navigate to latest binary build +#---------------------------------------------------------------------------------------------------------- + cd $PWD$RELEASE_DIRECTORY + #re run against the current binary built locally + check_mixnode_binary_build echo "diff the config files after each init"