From fb3e93748bd4dc43900277ede6280ae891682dc4 Mon Sep 17 00:00:00 2001
From: joshemb <josh@elixxir.io>
Date: Thu, 10 Nov 2022 11:33:18 -0800
Subject: [PATCH] Add crust.sh for Crust integration testing

---
 basice2e/crust.sh | 150 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100755 basice2e/crust.sh

diff --git a/basice2e/crust.sh b/basice2e/crust.sh
new file mode 100755
index 0000000..f521cb9
--- /dev/null
+++ b/basice2e/crust.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+
+# This file contains logic to run clients with the specific goal of putting
+# backups testing backups on Crust's architecture. These clients will then
+# recover these backups and ensure the recovered file matches the originally
+# backed up file.
+
+# NOTE: This is verbose on purpose.
+################################################################################
+## Initial Set Up & Clean Up of Past Runs
+################################################################################
+
+set -e
+rm -fr results.bak || true
+mv results results.bak || rm -fr results || true
+rm -fr blob* || true
+rm *-contact.json || true
+rm server-5.qdstrm || true
+rm server-5.qdrep || true
+
+mkdir -p .elixxir
+
+if [ $# -gt 1 ]
+then
+    echo "usage: $0 [gatewayip:port]"
+    exit
+fi
+
+
+NETWORKENTRYPOINT=$1
+
+DEBUGLEVEL=${DEBUGLEVEL-1}
+
+SERVERLOGS=results/servers
+GATEWAYLOGS=results/gateways
+CLIENTOUT=results/clients
+CLIENTCLEAN=results/clients-cleaned
+
+CLIENTOPTS="--password hello --ndf results/ndf.json --verify-sends --sendDelay 100 --waitTimeout 360 -v $DEBUGLEVEL"
+CLIENTUDOPTS="--password hello --ndf results/ndf.json -v $DEBUGLEVEL"
+
+mkdir -p $SERVERLOGS
+mkdir -p $GATEWAYLOGS
+mkdir -p $CLIENTOUT
+mkdir -p $CLIENTCLEAN
+
+################################################################################
+## Network Set Up
+################################################################################
+
+
+if [ "$NETWORKENTRYPOINT" == "betanet" ]
+then
+    NETWORKENTRYPOINT=$(sort -R betanet.txt | head -1)
+elif [ "$NETWORKENTRYPOINT" == "mainnet" ]
+then
+    NETWORKENTRYPOINT=$(sort -R mainnet.txt | head -1)
+elif [ "$NETWORKENTRYPOINT" == "release" ]
+then
+    NETWORKENTRYPOINT=$(sort -R release.txt | head -1)
+elif [ "$NETWORKENTRYPOINT" == "devnet" ]
+then
+    NETWORKENTRYPOINT=$(sort -R devnet.txt | head -1)
+elif [ "$NETWORKENTRYPOINT" == "" ]
+then
+    NETWORKENTRYPOINT=$(head -1 network.config)
+fi
+
+echo "NETWORK: $NETWORKENTRYPOINT"
+
+if [ "$NETWORKENTRYPOINT" == "localhost:8440" ]
+then
+    source network.sh
+
+else
+    echo "Connecting to network defined at $NETWORKENTRYPOINT"
+    echo $NETWORKENTRYPOINT > results/startgwserver.txt
+fi
+
+echo "DOWNLOADING TLS Cert..."
+CMD="openssl s_client -showcerts -connect $(tr -d '[:space:]' < results/startgwserver.txt)"
+echo $CMD
+eval $CMD < /dev/null 2>&1 > "results/startgwcert.bin"
+CMD="cat results/startgwcert.bin | openssl x509 -outform PEM"
+echo $CMD
+eval $CMD > "results/startgwcert.pem"
+head "results/startgwcert.pem"
+
+echo "DOWNLOADING NDF..."
+CLIENTCMD="../bin/client getndf --gwhost $(tr -d '[:space:]' < results/startgwserver.txt) --cert results/startgwcert.pem"
+eval $CLIENTCMD >> results/ndf.json 2>&1 &
+PIDVAL=$!
+echo "$CLIENTCMD -- $PIDVAL"
+wait $PIDVAL
+
+cat results/ndf.json | jq . | head -5
+
+file results/ndf.json
+
+if [ ! -s results/ndf.json ]
+then
+    echo "results/ndf.json is empty, cannot proceed"
+    exit -1
+fi
+
+
+#export GRPC_GO_LOG_VERBOSITY_LEVEL=99
+#export GRPC_GO_LOG_SEVERITY_LEVEL=info
+
+###############################################################################
+# Test Crust
+###############################################################################
+
+echo "TESTING CRUST..."
+
+# Register username with UD
+CLIENTCMD="timeout 240s ../bin/client ud $CLIENTUDOPTS -l $CLIENTOUT/client300.log -s blob300 --register josh300"
+eval $CLIENTCMD >> $CLIENTOUT/client300.txt &
+PIDVAL=$!
+echo "$CLIENTCMD -- $PIDVAL"
+wait $PIDVAL
+
+# Upload file to Crust
+CLIENTCMD="timeout 240s ../bin/client crust -l $CLIENTUDOPTS $CLIENTOUT/client300.log -s blob300 --upload --file LoremIpsum.txt"
+eval $CLIENTCMD >> $CLIENTOUT/client300.txt &
+PIDVAL=$!
+echo "$CLIENTCMD -- $PIDVAL"
+wait $PIDVAL
+
+# Recover file from Crust
+CLIENTCMD="timeout 240s ../bin/client crust -l $CLIENTUDOPTS $CLIENTOUT/client300.log -s blob300 --recover --file LoremIpsum.txt"
+eval $CLIENTCMD >> $CLIENTOUT/client300.txt &
+PIDVAL=$!
+echo "$CLIENTCMD -- $PIDVAL"
+wait $PIDVAL
+
+###############################################################################
+# Close Local Network
+###############################################################################
+
+if [ "$NETWORKENTRYPOINT" == "localhost:8440" ]
+then
+    cat $SERVERLOGS/server-*.log | grep -a "ERROR" | grep -a -v "context" | grep -av "metrics" | grep -av "database" | grep -av RequestClientKey > results/server-errors.txt || true
+    cat $SERVERLOGS/server-*.log | grep -a "FATAL" | grep -a -v "context" | grep -av "transport is closing" | grep -av "database" >> results/server-errors.txt || true
+    diff -aruN results/server-errors.txt noerrors.txt
+    IGNOREMSG="GetRoundBufferInfo: Error received: rpc error: code = Unknown desc = round buffer is empty"
+    cat $GATEWAYLOGS/*.log | grep -a "ERROR" | grep -av "context" | grep -av "certificate" | grep -av "Failed to read key" | grep -av "$IGNOREMSG" > results/gateway-errors.txt || true
+    cat $GATEWAYLOGS/*.log | grep -a "FATAL" | grep -av "context" | grep -av "transport is closing" >> results/gateway-errors.txt || true
+    diff -aruN results/gateway-errors.txt noerrors.txt
+fi
\ No newline at end of file
-- 
GitLab