exchange/src/auditor/test-auditor.sh

51 lines
1.4 KiB
Bash
Raw Normal View History

2019-08-22 15:30:02 +02:00
#!/bin/bash
2019-08-22 15:43:30 +02:00
# Setup database which was generated from a perfectly normal
# exchange-wallet interaction and run the auditor against it.
#
# Check that the auditor report is as expected.
#
# Requires 'jq' tool and Postgres superuser rights!
2019-08-22 15:30:02 +02:00
set -eu
2019-08-23 15:10:10 +02:00
echo "Database setup"
2019-08-22 15:30:02 +02:00
DB=taler-auditor-test
2019-08-22 15:43:30 +02:00
dropdb $DB 2> /dev/null || true
2019-08-22 15:30:02 +02:00
createdb -T template0 $DB || exit 77
2019-08-22 15:43:30 +02:00
jq -h > /dev/null || exit 77
2019-08-22 15:48:35 +02:00
# Import pre-generated database, -q(ietly) using single (-1) transaction
2019-08-22 15:43:30 +02:00
psql $DB -q -1 -f ../benchmark/auditor-basedb.sql > /dev/null
2019-08-22 15:30:02 +02:00
MASTER_PUB=`cat ../benchmark/auditor-basedb.mpub`
2019-08-23 15:10:10 +02:00
# Launch bank
echo "Launching bank"
taler-bank-manage -c test-auditor.conf serve-http 2>/dev/null >/dev/null &
sleep 10
2019-08-22 15:48:35 +02:00
# Run the auditor!
2019-08-23 15:10:10 +02:00
echo "Running audit(s)"
2019-08-22 15:30:02 +02:00
taler-auditor -c test-auditor.conf -m $MASTER_PUB > test-audit.json
2019-08-23 15:10:10 +02:00
taler-wire-auditor -c test-auditor.conf -m $MASTER_PUB > test-wire-audit.json
echo "Shutting down services"
kill `jobs -p`
2019-08-22 15:30:02 +02:00
2019-08-22 15:43:30 +02:00
2019-08-23 15:10:10 +02:00
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 "Checking output"
2019-08-22 15:43:30 +02:00
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
2019-08-22 15:43:30 +02:00
# TODO: Add more checks to ensure test-audit.json matches expectations
2019-08-22 15:30:02 +02:00
2019-08-23 15:10:10 +02:00
echo "Cleanup"
2019-08-22 15:30:02 +02:00
dropdb $DB
2019-08-22 15:43:30 +02:00
exit $fail