diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-08-26 03:16:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-08-26 03:18:32 +0200 |
commit | 7b20ee8c8d691c0d79403462411ec66c5ada36c4 (patch) | |
tree | b709105fb87a9a2f976246cbd2ab0648ccb8d87b /src/auditor/test-auditor.sh | |
parent | 613217be0354a02611f5e1a34e07989e2c5d5cfe (diff) |
minor auditor report generation bugfixes:
Diffstat (limited to 'src/auditor/test-auditor.sh')
-rwxr-xr-x | src/auditor/test-auditor.sh | 147 |
1 files changed, 118 insertions, 29 deletions
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index 260124fab..a5c20577b 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -7,56 +7,145 @@ # Requires 'jq' tool and Postgres superuser rights! set -eu +function exit_skip() { + echo $1 + exit 77 +} + +function exit_fail() { + echo $1 + kill `jobs -p` + exit 1 +} + +function run_audit () { + # Launch bank + echo "Launching bank" + taler-bank-manage -c test-auditor.conf serve-http 2>bank.err >bank.log & + while true + do + echo -n "." + wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null && break + sleep 1 + done + echo "OK" + + # Run the auditor! + echo "Running audit(s)" + taler-auditor -r -c test-auditor.conf -m $MASTER_PUB > test-audit.json || exit_fail "auditor failed" + + taler-wire-auditor -r -c test-auditor.conf -m $MASTER_PUB > test-wire-audit.json || exit_fail "wire auditor failed" + + echo "Shutting down services" + kill `jobs -p` + + echo "TeXing" + ../../contrib/render.py test-audit.json test-wire-audit.json < ../../contrib/auditor-report.tex.j2 > test-report.tex || exit_fail Renderer failed + + pdflatex test-report.tex >/dev/null || exit_fail pdflatex failed + pdflatex test-report.tex >/dev/null +} + + # test required commands exist echo "Testing for jq" -jq -h > /dev/null || exit 77 +jq -h > /dev/null || exit_skip "jq required" echo "Testing for taler-bank-manage" -taler-bank-manage -h >/dev/null || exit 77 +taler-bank-manage -h >/dev/null </dev/null || exit_skip "taler-bank-manage required" echo "Testing for pdflatex" -which pdflatex > /dev/null || exit 77 +which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required" echo "Database setup" DB=taler-auditor-test dropdb $DB 2> /dev/null || true -createdb -T template0 $DB || exit 77 +createdb -T template0 $DB || exit_skip "could not create database" # Import pre-generated database, -q(ietly) using single (-1) transaction psql $DB -q -1 -f ../benchmark/auditor-basedb.sql > /dev/null MASTER_PUB=`cat ../benchmark/auditor-basedb.mpub` -# Launch bank -echo "Launching bank" -taler-bank-manage -c test-auditor.conf serve-http 2>/dev/null >/dev/null & - - -# Run the auditor! -echo "Running audit(s)" -taler-auditor -c test-auditor.conf -m $MASTER_PUB > test-audit.json - -# TODO: -# - need to configure exchange's bank accounts in test-auditor.conf, -# otherwise the auditor cannot find them! -taler-wire-auditor -c test-auditor.conf -m $MASTER_PUB > test-wire-audit.json - -echo "Shutting down services" -kill `jobs -p` - - -echo "TeXing" -../../contrib/render.py test-audit.json test-wire-audit.json < ../../contrib/auditor-report.tex.j2 > test-report.tex - -pdflatex test-report.tex >/dev/null -pdflatex test-report.tex >/dev/null +echo "===========1: normal run===========" +run_audit echo "Checking output" fail=0 # if an emergency was detected, that is a bug and we should fail echo -n "Test for emergencies... " -jq -e .emergencies[0] < test-audit.json > /dev/null && (echo Failed; fail=1) || echo OK - +jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo OK + +echo -n "Test for wire inconsistencies... " +jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" +jq -e .reserve_in_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" +jq -e .missattribution_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected missattribution inconsistency detected in ordinary run" +jq -e .row_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" +jq -e .row_minor_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" +jq -e .lag_details[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run" +jq -e .wire_format_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" + +echo OK + +echo -n "Test for wire amounts... " +WIRED=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:0" +then + exit_fail "Expected total wire delta plus wrong, got $WIRED" +fi +WIRED=`jq -r .total_wire_in_delta_minus < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:0" +then + exit_fail "Expected total wire delta minus wrong, got $WIRED" +fi +WIRED=`jq -r .total_wire_out_delta_plus < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:0" +then + exit_fail "Expected total wire delta plus wrong, got $WIRED" +fi +WIRED=`jq -r .total_wire_out_delta_minus < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:0" +then + exit_fail "Expected total wire delta minus wrong, got $WIRED" +fi +WIRED=`jq -r .total_missattribution_in < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:0" +then + exit_fail "Expected total missattribution in wrong, got $WIRED" +fi +echo "OK" + + +echo "===========2: reserves_in inconsitency===========" # TODO: Add more checks to ensure test-audit.json matches expectations echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql $DB +run_audit + +echo -n "Test for inconsistency detection... " +ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-wire-audit.json` +if test $ROW != 1 +then + exit_fail "Row wrong" +fi +WIRED=`jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:10" +then + exit_fail "Amount wrong" +fi +EXPECTED=`jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-wire-audit.json` +if test $EXPECTED != "TESTKUDOS:5" +then + exit_fail "Expected amount wrong" +fi +DELTA=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` +if test $DELTA != "TESTKUDOS:5" +then + exit_fail "Expected total wire delta plus wrong" +fi +echo OK + +# Undo database modification +echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql $DB + +# TODO: insert more tests! echo "Cleanup" dropdb $DB |