-more script fixes

This commit is contained in:
Christian Grothoff 2023-07-25 14:34:03 +02:00
parent 987878469d
commit 4c6ab83925
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -19,13 +19,15 @@
# #
# Check that the auditor report is as expected. # Check that the auditor report is as expected.
# #
# shellcheck disable=SC2317
#
# Requires 'jq' tool and Postgres superuser rights! # Requires 'jq' tool and Postgres superuser rights!
set -eu set -eu
# set -x # set -x
# Set of numbers for all the testcases. # Set of numbers for all the testcases.
# When adding new tests, increase the last number: # When adding new tests, increase the last number:
ALL_TESTS=`seq 0 4` ALL_TESTS=$(seq 0 4)
# $TESTS determines which tests we should run. # $TESTS determines which tests we should run.
# This construction is used to make it easy to # This construction is used to make it easy to
@ -42,6 +44,7 @@ TESTS=${1:-$ALL_TESTS}
# Global variable to run the auditor processes under valgrind # Global variable to run the auditor processes under valgrind
# VALGRIND=valgrind # VALGRIND=valgrind
VALGRIND="" VALGRIND=""
LOGLEVEL="INFO"
# Exit, with status code "skip" (no 'real' failure) # Exit, with status code "skip" (no 'real' failure)
function exit_skip() { function exit_skip() {
@ -58,21 +61,21 @@ function exit_fail() {
function stop_libeufin() function stop_libeufin()
{ {
echo "killing libeufin..." echo "killing libeufin..."
if test -f ${MYDIR:-/}/libeufin-sandbox.pid if test -f "${MYDIR:-/}/libeufin-sandbox.pid"
then then
echo "Killing libeufin sandbox" echo "Killing libeufin sandbox"
PID=`cat ${MYDIR}/libeufin-sandbox.pid 2> /dev/null` PID=$(cat "${MYDIR}/libeufin-sandbox.pid" 2> /dev/null)
rm ${MYDIR}/libeufin-sandbox.pid rm "${MYDIR}/libeufin-sandbox.pid"
kill $PID 2> /dev/null || true kill "$PID" 2> /dev/null || true
wait $PID || true wait "$PID" || true
fi fi
if test -f ${MYDIR:-/}/libeufin-nexus.pid if test -f "${MYDIR:-/}/libeufin-nexus.pid"
then then
echo "Killing libeufin nexus" echo "Killing libeufin nexus"
PID=`cat ${MYDIR}/libeufin-nexus.pid 2> /dev/null` PID=$(cat "${MYDIR}/libeufin-nexus.pid" 2> /dev/null)
rm ${MYDIR}/libeufin-nexus.pid rm "${MYDIR}/libeufin-nexus.pid"
kill $PID 2> /dev/null || true kill "$PID" 2> /dev/null || true
wait $PID || true wait "$PID" || true
fi fi
echo "killing libeufin DONE" echo "killing libeufin DONE"
} }
@ -84,8 +87,8 @@ function cleanup()
if test ! -z "${EPID:-}" if test ! -z "${EPID:-}"
then then
echo -n "Stopping exchange $EPID..." echo -n "Stopping exchange $EPID..."
kill -TERM $EPID kill -TERM "$EPID"
wait $EPID wait "$EPID"
echo " DONE" echo " DONE"
unset EPID unset EPID
fi fi
@ -99,12 +102,17 @@ function exit_cleanup()
if test ! -z "${POSTGRES_PATH:-}" if test ! -z "${POSTGRES_PATH:-}"
then then
echo "Stopping Postgres at ${POSTGRES_PATH}" echo "Stopping Postgres at ${POSTGRES_PATH}"
${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null stop &> /dev/null || true "${POSTGRES_PATH}/pg_ctl" \
-D "$TMPDIR" \
-l /dev/null \
stop \
&> /dev/null \
|| true
fi fi
cleanup cleanup
for n in `jobs -p` for n in $(jobs -p)
do do
kill $n 2> /dev/null || true kill "$n" 2> /dev/null || true
done done
wait wait
echo "DONE" echo "DONE"
@ -119,7 +127,9 @@ function nexus_fetch_transactions () {
export LIBEUFIN_NEXUS_PASSWORD=x export LIBEUFIN_NEXUS_PASSWORD=x
export LIBEUFIN_NEXUS_URL=http://localhost:8082/ export LIBEUFIN_NEXUS_URL=http://localhost:8082/
libeufin-cli accounts fetch-transactions \ libeufin-cli accounts fetch-transactions \
--range-type since-last --level report exchange-nexus > /dev/null --range-type since-last \
--level report \
exchange-nexus > /dev/null
unset LIBEUFIN_NEXUS_USERNAME unset LIBEUFIN_NEXUS_USERNAME
unset LIBEUFIN_NEXUS_PASSWORD unset LIBEUFIN_NEXUS_PASSWORD
unset LIBEUFIN_NEXUS_URL unset LIBEUFIN_NEXUS_URL
@ -141,66 +151,90 @@ function get_payto_uri() {
export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_USERNAME=$1
export LIBEUFIN_SANDBOX_PASSWORD=$2 export LIBEUFIN_SANDBOX_PASSWORD=$2
export LIBEUFIN_SANDBOX_URL=http://localhost:18082 export LIBEUFIN_SANDBOX_URL=http://localhost:18082
libeufin-cli sandbox demobank info --bank-account $1 | jq --raw-output '.paytoUri' libeufin-cli sandbox demobank info \
--bank-account "$1" \
| jq --raw-output '.paytoUri'
} }
function launch_libeufin () { function launch_libeufin () {
export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${DB}-nexus.sqlite3" export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${DB}-nexus.sqlite3"
cd $MYDIR libeufin-nexus serve \
libeufin-nexus serve --port 8082 \ --port 8082 \
2> ${MYDIR}/libeufin-nexus-stderr.log \ 2> "${MYDIR}/libeufin-nexus-stderr.log" \
> ${MYDIR}/libeufin-nexus-stdout.log & > "${MYDIR}/libeufin-nexus-stdout.log" &
echo $! > ${MYDIR}/libeufin-nexus.pid echo $! > "${MYDIR}/libeufin-nexus.pid"
export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${DB}-sandbox.sqlite3" export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${DB}-sandbox.sqlite3"
libeufin-sandbox serve --no-auth --port 18082 \ libeufin-sandbox serve \
> ${MYDIR}/libeufin-sandbox-stdout.log \ --no-auth \
2> ${MYDIR}/libeufin-sandbox-stderr.log & --port 18082 \
echo $! > ${MYDIR}/libeufin-sandbox.pid > "${MYDIR}/libeufin-sandbox-stdout.log" \
cd $ORIGIN 2> "${MYDIR}/libeufin-sandbox-stderr.log" &
echo $! > "${MYDIR}/libeufin-sandbox.pid"
} }
# Operations to run before the actual audit # Operations to run before the actual audit
function pre_audit () { function pre_audit () {
# Launch bank # Launch bank
echo -n "Launching bank " echo -n "Launching bank "
EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
launch_libeufin launch_libeufin
for n in `seq 1 80` for n in $(seq 1 80)
do do
echo -n "." echo -n "."
sleep 0.1 sleep 0.1
OK=1 OK=1
wget http://localhost:18082/ -o /dev/null -O /dev/null >/dev/null && break wget http://localhost:18082/ \
-o /dev/null \
-O /dev/null \
>/dev/null && break
OK=0 OK=0
done done
if [ 1 != $OK ] if [ 1 != "$OK" ]
then then
exit_skip "Failed to launch Sandbox" exit_skip "Failed to launch Sandbox"
fi fi
for n in `seq 1 80` for n in $(seq 1 80)
do do
echo -n "." echo -n "."
sleep 0.1 sleep 0.1
OK=1 OK=1
wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null && break wget http://localhost:8082/ \
-o /dev/null \
-O /dev/null \
>/dev/null && break
OK=0 OK=0
done done
if [ 1 != $OK ] if [ 1 != "$OK" ]
then then
exit_skip "Failed to launch Nexus" exit_skip "Failed to launch Nexus"
fi fi
echo " DONE" echo " DONE"
if test ${1:-no} = "aggregator" if [ "${1:-no}" = "aggregator" ]
then then
export CONF export CONF
echo -n "Running exchange aggregator ... (config: $CONF)" echo -n "Running exchange aggregator ... (config: $CONF)"
taler-exchange-aggregator -L INFO -t -c $CONF -y 2> ${MYDIR}/aggregator.log || exit_fail "FAIL" taler-exchange-aggregator \
-L "$LOGLEVEL" \
-t \
-c "$CONF" \
-y \
2> "${MYDIR}/aggregator.log" \
|| exit_fail "FAIL"
echo " DONE" echo " DONE"
echo -n "Running exchange closer ..." echo -n "Running exchange closer ..."
taler-exchange-closer -L INFO -t -c $CONF 2> ${MYDIR}/closer.log || exit_fail "FAIL" taler-exchange-closer \
-L "$LOGLEVEL" \
-t \
-c "$CONF" \
2> "${MYDIR}/closer.log" \
|| exit_fail "FAIL"
echo " DONE" echo " DONE"
echo -n "Running exchange transfer ..." echo -n "Running exchange transfer ..."
taler-exchange-transfer -L INFO -t -c $CONF 2> ${MYDIR}/transfer.log || exit_fail "FAIL" taler-exchange-transfer \
-L "$LOGLEVEL" \
-t \
-c "$CONF" \
2> "${MYDIR}/transfer.log" \
|| exit_fail "FAIL"
echo " DONE" echo " DONE"
echo -n "Running Nexus payment submitter ..." echo -n "Running Nexus payment submitter ..."
nexus_submit_to_sandbox nexus_submit_to_sandbox
@ -218,28 +252,93 @@ function audit_only () {
echo -n "Running audit(s) ... (conf is $CONF)" echo -n "Running audit(s) ... (conf is $CONF)"
# Restart so that first run is always fresh, and second one is incremental # Restart so that first run is always fresh, and second one is incremental
taler-auditor-dbinit -r -c $CONF taler-auditor-dbinit \
$VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> test-audit-aggregation.log || exit_fail "aggregation audit failed" -r \
-c "$CONF"
$VALGRIND taler-helper-auditor-aggregation \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-aggregation.json \
2> test-audit-aggregation.log \
|| exit_fail "aggregation audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed" $VALGRIND taler-helper-auditor-aggregation \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-aggregation-inc.json \
2> test-audit-aggregation-inc.log \
|| exit_fail "incremental aggregation audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> test-audit-coins.log || exit_fail "coin audit failed" $VALGRIND taler-helper-auditor-coins \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-coins.json \
2> test-audit-coins.log \
|| exit_fail "coin audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> test-audit-coins-inc.log || exit_fail "incremental coin audit failed" $VALGRIND taler-helper-auditor-coins \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-coins-inc.json \
2> test-audit-coins-inc.log \
|| exit_fail "incremental coin audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> test-audit-deposits.log || exit_fail "deposits audit failed" $VALGRIND taler-helper-auditor-deposits \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-deposits.json \
2> test-audit-deposits.log \
|| exit_fail "deposits audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed" $VALGRIND taler-helper-auditor-deposits \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-deposits-inc.json \
2> test-audit-deposits-inc.log \
|| exit_fail "incremental deposits audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> test-audit-reserves.log || exit_fail "reserves audit failed" $VALGRIND taler-helper-auditor-reserves \
-i \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-reserves.json \
2> test-audit-reserves.log \
|| exit_fail "reserves audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed" $VALGRIND taler-helper-auditor-reserves \
-i \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-reserves-inc.json \
2> test-audit-reserves-inc.log \
|| exit_fail "incremental reserves audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> test-wire-audit.log || exit_fail "wire audit failed" $VALGRIND taler-helper-auditor-wire \
-i \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-wire.json \
2> test-wire-audit.log \
|| exit_fail "wire audit failed"
echo -n "." echo -n "."
$VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> test-wire-audit-inc.log || exit_fail "wire audit failed" $VALGRIND taler-helper-auditor-wire \
-i \
-L "$LOGLEVEL" \
-c "$CONF" \
-m "$MASTER_PUB" \
> test-audit-wire-inc.json \
2> test-wire-audit-inc.log \
|| exit_fail "wire audit failed"
echo -n "." echo -n "."
echo " DONE" echo " DONE"
} }
@ -248,12 +347,22 @@ function audit_only () {
function post_audit () { function post_audit () {
cleanup cleanup
echo -n "TeXing ." echo -n "TeXing ."
taler-helper-auditor-render.py test-audit-aggregation.json test-audit-coins.json test-audit-deposits.json test-audit-reserves.json test-audit-wire.json < ../../contrib/auditor-report.tex.j2 > test-report.tex || exit_fail "Renderer failed" taler-helper-auditor-render.py \
test-audit-aggregation.json \
test-audit-coins.json \
test-audit-deposits.json \
test-audit-reserves.json \
test-audit-wire.json \
< ../../contrib/auditor-report.tex.j2 \
> test-report.tex \
|| exit_fail "Renderer failed"
echo -n "." echo -n "."
timeout 10 pdflatex test-report.tex >/dev/null || exit_fail "pdflatex failed" timeout 10 pdflatex test-report.tex \
>/dev/null \
|| exit_fail "pdflatex failed"
echo -n "." echo -n "."
timeout 10 pdflatex test-report.tex >/dev/null timeout 10 pdflatex test-report.tex \
>/dev/null
echo " DONE" echo " DONE"
} }
@ -263,10 +372,9 @@ function post_audit () {
# $ taler-exchange-aggregator # $ taler-exchange-aggregator
# before auditor (to trigger pending wire transfers). # before auditor (to trigger pending wire transfers).
function run_audit () { function run_audit () {
pre_audit ${1:-no} pre_audit "${1:-no}"
audit_only audit_only
post_audit post_audit
} }
@ -274,35 +382,21 @@ function run_audit () {
function full_reload() function full_reload()
{ {
echo -n "Doing full reload of the database... " echo -n "Doing full reload of the database... "
dropdb $DB 2> /dev/null || true dropdb "$DB" 2> /dev/null || true
createdb -T template0 $DB || exit_skip "could not create database $DB (at $PGHOST)" createdb -T template0 "$DB" \
|| exit_skip "could not create database $DB (at $PGHOST)"
# Import pre-generated database, -q(ietly) using single (-1) transaction # Import pre-generated database, -q(ietly) using single (-1) transaction
psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database $DB from ${BASEDB}.sql" psql -Aqt "$DB" \
-q \
-1 \
-f "${BASEDB}.sql" \
> /dev/null \
|| exit_skip "Failed to load database $DB from ${BASEDB}.sql"
echo "DONE" echo "DONE"
cd $MYDIR
rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 || true # libeufin
echo "Loading libeufin Nexus basedb: ${BASEDB}-libeufin-nexus.sql"
sqlite3 ${DB}-nexus.sqlite3 < ${BASEDB}-libeufin-nexus.sql || exit_skip "Failed to load Nexus database"
echo "DONE"
echo "Loading libeufin Sandbox basedb: ${BASEDB}-libeufin-nexus.sql"
sqlite3 ${DB}-sandbox.sqlite3 < ${BASEDB}-libeufin-sandbox.sql || exit_skip "Failed to load Sandbox database"
echo "DONE"
# Exchange payto URI contains the (dynamically generated)
# IBAN, that can only be written in CONF after libeufin is
# setup.
taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI &> /dev/null || (
echo -n "Specifying exchange payto URI in the configuration ($CONF) (grab IBAN from ${DB}-sandbox.sqlite3)...";
EXCHANGE_IBAN=`echo "SELECT iban FROM BankAccounts WHERE label='exchange'" | sqlite3 ${DB}-sandbox.sqlite3`;
taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI \
-V "payto://iban/SANDBOXX/$EXCHANGE_IBAN?receiver-name=Exchange+Company"
echo " DONE"
)
cd $ORIGIN
} }
function test_0() { function test_0() {
echo "===========0: normal run with aggregator===========" echo "===========0: normal run with aggregator==========="
run_audit aggregator run_audit aggregator
@ -331,94 +425,105 @@ function test_0() {
echo PASS echo PASS
LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json` LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS" exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
fi fi
LOSS=`jq -r .irregular_loss < test-audit-coins.json` LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS" exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
fi fi
LOSS=`jq -r .total_bad_sig_loss < test-audit-reserves.json` LOSS=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS" exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
fi fi
echo -n "Test for wire amounts... " echo -n "Test for wire amounts... "
WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta plus wrong, got $WIRED" exit_fail "Expected total wire delta plus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta minus wrong, got $WIRED" exit_fail "Expected total wire delta minus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta plus wrong, got $WIRED" exit_fail "Expected total wire delta plus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta minus wrong, got $WIRED" exit_fail "Expected total wire delta minus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total misattribution in wrong, got $WIRED" exit_fail "Expected total misattribution in wrong, got $WIRED"
fi fi
echo PASS echo "PASS"
echo -n "Checking for unexpected arithmetic differences " echo -n "Checking for unexpected arithmetic differences "
LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json` LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS" exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
fi fi
LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json` LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS" exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
fi fi
LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS" exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
fi fi
LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS" exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
fi fi
LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-reserves.json` LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-reserves.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS" exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
fi fi
LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-reserves.json` LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-reserves.json)
if test $LOSS != "TESTKUDOS:0" if [ "$LOSS" != "TESTKUDOS:0" ]
then then
exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS" exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
fi fi
jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run" jq -e .amount_arithmetic_inconsistencies[0] \
jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run" < test-audit-aggregation.json \
jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run" > /dev/null \
echo PASS && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
jq -e .amount_arithmetic_inconsistencies[0] \
< test-audit-coins.json \
> /dev/null \
&& exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
jq -e .amount_arithmetic_inconsistencies[0] \
< test-audit-reserves.json \
> /dev/null \
&& exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
echo "PASS"
echo -n "Checking for unexpected wire out differences " echo -n "Checking for unexpected wire out differences "
jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run" jq -e .wire_out_inconsistencies[0] \
echo PASS < test-audit-aggregation.json \
> /dev/null \
&& exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
echo "PASS"
# cannot easily undo aggregator, hence full reload # cannot easily undo aggregator, hence full reload
full_reload full_reload
} }
@ -432,46 +537,72 @@ function test_1() {
echo "Checking output" echo "Checking output"
# if an emergency was detected, that is a bug and we should fail # if an emergency was detected, that is a bug and we should fail
echo -n "Test for emergencies... " echo -n "Test for emergencies... "
jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS jq -e .emergencies[0] \
< test-audit-coins.json \
> /dev/null \
&& exit_fail "Unexpected emergency detected in ordinary run" \
|| echo "PASS"
echo -n "Test for emergencies by count... " echo -n "Test for emergencies by count... "
jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS jq -e .emergencies_by_count[0] \
< test-audit-coins.json \
> /dev/null \
&& exit_fail "Unexpected emergency by count detected in ordinary run" \
|| echo "PASS"
echo -n "Test for wire inconsistencies... " echo -n "Test for wire inconsistencies... "
jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" jq -e .wire_out_amount_inconsistencies[0] \
jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" < test-audit-wire.json \
jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run" > /dev/null \
jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" jq -e .reserve_in_amount_inconsistencies[0] \
jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" < test-audit-wire.json \
> /dev/null \
&& exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
jq -e .misattribution_inconsistencies[0] \
< test-audit-wire.json \
> /dev/null \
&& exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
jq -e .row_inconsistencies[0] \
< test-audit-wire.json \
> /dev/null \
&& exit_fail "Unexpected row inconsistency detected in ordinary run"
jq -e .row_minor_inconsistencies[0] \
< test-audit-wire.json \
> /dev/null \
&& exit_fail "Unexpected minor row inconsistency detected in ordinary run"
jq -e .wire_format_inconsistencies[0] \
< test-audit-wire.json \
> /dev/null \
&& exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic) # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic) # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
echo PASS echo "PASS"
echo -n "Test for wire amounts... " echo -n "Test for wire amounts... "
WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta plus wrong, got $WIRED" exit_fail "Expected total wire delta plus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta minus wrong, got $WIRED" exit_fail "Expected total wire delta minus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta plus wrong, got $WIRED" exit_fail "Expected total wire delta plus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total wire delta minus wrong, got $WIRED" exit_fail "Expected total wire delta minus wrong, got $WIRED"
fi fi
WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
if test $WIRED != "TESTKUDOS:0" if [ "$WIRED" != "TESTKUDOS:0" ]
then then
exit_fail "Expected total misattribution in wrong, got $WIRED" exit_fail "Expected total misattribution in wrong, got $WIRED"
fi fi
@ -486,37 +617,37 @@ function test_1() {
function test_2() { function test_2() {
echo "===========2: recoup amount inconsistency===========" echo "===========2: recoup amount inconsistency==========="
echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt $DB echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt "$DB"
run_audit run_audit
# Reserve balance is now wrong # Reserve balance is now wrong
echo -n "Testing inconsistency detection... " echo -n "Testing inconsistency detection... "
AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json` AMOUNT=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json)
if test $AMOUNT != "TESTKUDOS:3" if [ "$AMOUNT" != "TESTKUDOS:3" ]
then then
exit_fail "Reserve auditor amount $AMOUNT is wrong" exit_fail "Reserve auditor amount $AMOUNT is wrong"
fi fi
AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json` AMOUNT=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json)
if test $AMOUNT != "TESTKUDOS:0" if [ "$AMOUNT" != "TESTKUDOS:0" ]
then then
exit_fail "Reserve exchange amount $AMOUNT is wrong" exit_fail "Reserve exchange amount $AMOUNT is wrong"
fi fi
# Coin spent exceeded coin's value # Coin spent exceeded coin's value
AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json` AMOUNT=$(jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json)
if test $AMOUNT != "TESTKUDOS:2" if [ "$AMOUNT" != "TESTKUDOS:2" ]
then then
exit_fail "Coin auditor amount $AMOUNT is wrong" exit_fail "Coin auditor amount $AMOUNT is wrong"
fi fi
AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json` AMOUNT=$(jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json)
if test $AMOUNT != "TESTKUDOS:5" if [ "$AMOUNT" != "TESTKUDOS:5" ]
then then
exit_fail "Coin exchange amount $AMOUNT is wrong" exit_fail "Coin exchange amount $AMOUNT is wrong"
fi fi
echo OK echo "OK"
# Undo database modification # Undo database modification
echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt "$DB"
} }
@ -525,26 +656,26 @@ function test_2() {
function test_3() { function test_3() {
echo "===========3: recoup-refresh amount inconsistency===========" echo "===========3: recoup-refresh amount inconsistency==========="
echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt "$DB"
run_audit run_audit
echo -n "Testing inconsistency detection... " echo -n "Testing inconsistency detection... "
# Coin spent exceeded coin's value # Coin spent exceeded coin's value
AMOUNT=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` AMOUNT=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
if test $AMOUNT != "TESTKUDOS:5" if [ "$AMOUNT" != "TESTKUDOS:5" ]
then then
exit_fail "Arithmetic delta minus amount $AMOUNT is wrong" exit_fail "Arithmetic delta minus amount $AMOUNT is wrong"
fi fi
AMOUNT=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` AMOUNT=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
if test $AMOUNT != "TESTKUDOS:0" if [ "$AMOUNT" != "TESTKUDOS:0" ]
then then
exit_fail "Arithmetic delta plus amount $AMOUNT is wrong" exit_fail "Arithmetic delta plus amount $AMOUNT is wrong"
fi fi
echo OK echo "OK"
# Undo database modification # Undo database modification
echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt "$DB"
} }
@ -553,34 +684,35 @@ function test_3() {
function test_4() { function test_4() {
echo "===========4: invalid recoup===========" echo "===========4: invalid recoup==========="
echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt $DB echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt "$DB"
run_audit run_audit
echo -n "Testing inconsistency detection... " echo -n "Testing inconsistency detection... "
# Coin spent exceeded coin's value # Coin spent exceeded coin's value
jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad recoup not detected" jq -e .bad_sig_losses[0] \
AMOUNT=`jq -r .irregular_loss < test-audit-coins.json` < test-audit-coins.json \
if test $AMOUNT == "TESTKUDOS:0" > /dev/null \
|| exit_fail "Bad recoup not detected"
AMOUNT=$(jq -r .irregular_loss < test-audit-coins.json)
if [ "$AMOUNT" == "TESTKUDOS:0" ]
then then
exit_fail "Total bad sig losses are wrong" exit_fail "Total bad sig losses are wrong"
fi fi
TAB=`jq -r .row_inconsistencies[0].table < test-audit-reserves.json` TAB=$(jq -r .row_inconsistencies[0].table < test-audit-reserves.json)
if test $TAB != "recoup" if [ "$TAB" != "recoup" ]
then then
exit_fail "Wrong table for row inconsistency, got $TAB" exit_fail "Wrong table for row inconsistency, got $TAB"
fi fi
echo OK echo "OK"
# Undo database modification (can't easily undo DELETE, so full reload) # Undo database modification (can't easily undo DELETE, so full reload)
full_reload full_reload
} }
# *************** Main test loop starts here ************** # *************** Main test loop starts here **************
@ -588,14 +720,14 @@ function test_4() {
# Sets $fail to 0 on success, non-zero on failure. # Sets $fail to 0 on success, non-zero on failure.
function check_with_database() function check_with_database()
{ {
BASEDB=$1 BASEDB="$1"
# Configuration file to use # Configuration file to use
CONF=$1.conf CONF="$1.conf"
echo "Running test suite with database $BASEDB using configuration $CONF" echo "Running test suite with database $BASEDB using configuration $CONF"
MASTER_PRIV_FILE=${BASEDB}.mpriv MASTER_PRIV_FILE="${BASEDB}.mpriv"
taler-config -f -c ${CONF} -s exchange-offline -o MASTER_PRIV_FILE -V ${MASTER_PRIV_FILE} taler-config -f -c "${CONF}" -s exchange-offline -o MASTER_PRIV_FILE -V "${MASTER_PRIV_FILE}"
MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE` MASTER_PUB=$(gnunet-ecc -p "$MASTER_PRIV_FILE")
echo "MASTER PUB is ${MASTER_PUB} using file ${MASTER_PRIV_FILE}" echo "MASTER PUB is ${MASTER_PUB} using file ${MASTER_PRIV_FILE}"
@ -605,14 +737,14 @@ function check_with_database()
fail=0 fail=0
for i in $TESTS for i in $TESTS
do do
test_$i "test_$i"
if test 0 != $fail if [ 0 != "$fail" ]
then then
break break
fi fi
done done
# echo "Cleanup (disabled, leaving database $DB behind)" # echo "Cleanup (disabled, leaving database $DB behind)"
dropdb $DB dropdb "$DB"
} }
@ -628,36 +760,49 @@ DB=revoke-basedb
echo "Testing for jq" echo "Testing for jq"
jq -h > /dev/null || exit_skip "jq required" jq -h > /dev/null || exit_skip "jq required"
echo "Testing for faketime" echo "Testing for faketime"
faketime -h > /dev/null || exit_skip "faketime required" faketime -h > /dev/null \
|| exit_skip "faketime required"
echo "Testing for libeufin(-cli)" echo "Testing for libeufin(-cli)"
libeufin-cli --help >/dev/null 2> /dev/null </dev/null || exit_skip "libeufin required" libeufin-cli --help \
>/dev/null \
2> /dev/null \
</dev/null \
|| exit_skip "libeufin required"
echo "Testing for pdflatex" echo "Testing for pdflatex"
which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required" which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
echo "Testing for taler-wallet-cli" echo "Testing for taler-wallet-cli"
taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required" taler-wallet-cli -h \
>/dev/null \
</dev/null \
2>/dev/null \
|| exit_skip "taler-wallet-cli required"
echo -n "Testing for Postgres" echo -n "Testing for Postgres "
# Available directly in path? # Available directly in path?
INITDB_BIN=$(command -v initdb) || true INITDB_BIN=$(command -v initdb) || true
if [[ ! -z "$INITDB_BIN" ]]; then if [[ -n "$INITDB_BIN" ]]; then
echo " FOUND (in path) at" $INITDB_BIN echo "FOUND (in path) at $INITDB_BIN"
else else
HAVE_INITDB=`find /usr -name "initdb" | head -1 2> /dev/null | grep postgres` || exit_skip " MISSING" HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) || exit_skip " MISSING"
echo " FOUND at" `dirname $HAVE_INITDB` echo "FOUND at " "$(dirname "$HAVE_INITDB")"
INITDB_BIN=`echo $HAVE_INITDB | grep bin/initdb | grep postgres | sort -n | tail -n1` INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
fi fi
echo -n "Setting up Postgres DB" echo -n "Setting up Postgres DB"
POSTGRES_PATH=`dirname $INITDB_BIN` POSTGRES_PATH=$(dirname "$INITDB_BIN")
ORIGIN=`pwd` MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX`
TMPDIR="${MYDIR}/postgres/" TMPDIR="${MYDIR}/postgres/"
mkdir -p $TMPDIR mkdir -p "$TMPDIR"
echo -n "Setting up Postgres DB at $TMPDIR ..." echo -n "Setting up Postgres DB at $TMPDIR ..."
$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > ${MYDIR}/postgres-dbinit.log 2> ${MYDIR}/postgres-dbinit.err "$INITDB_BIN" \
--no-sync \
--auth=trust \
-D "${TMPDIR}" \
> "${MYDIR}/postgres-dbinit.log" \
2> "${MYDIR}/postgres-dbinit.err"
echo " DONE" echo " DONE"
mkdir ${TMPDIR}/sockets mkdir "${TMPDIR}/sockets"
echo -n "Launching Postgres service at $POSTGRES_PATH" echo -n "Launching Postgres service at $POSTGRES_PATH"
cat - >> $TMPDIR/postgresql.conf <<EOF cat - >> "$TMPDIR/postgresql.conf" <<EOF
unix_socket_directories='${TMPDIR}/sockets' unix_socket_directories='${TMPDIR}/sockets'
fsync=off fsync=off
max_wal_senders=0 max_wal_senders=0
@ -665,23 +810,30 @@ synchronous_commit=off
wal_level=minimal wal_level=minimal
listen_addresses='' listen_addresses=''
EOF EOF
cat $TMPDIR/pg_hba.conf | grep -v host > $TMPDIR/pg_hba.conf.new grep -v host \
mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf < "$TMPDIR/pg_hba.conf" \
${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > ${MYDIR}/postgres-start.log 2> ${MYDIR}/postgres-start.err > "$TMPDIR/pg_hba.conf.new"
mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
"${POSTGRES_PATH}/pg_ctl" \
-D "$TMPDIR" \
-l /dev/null \
start \
> "${MYDIR}/postgres-start.log" \
2> "${MYDIR}/postgres-start.err"
echo " DONE" echo " DONE"
PGHOST="$TMPDIR/sockets" PGHOST="$TMPDIR/sockets"
export PGHOST export PGHOST
echo "Generating fresh database at $MYDIR" echo "Generating fresh database at $MYDIR"
if faketime -f '-1 d' ./generate-revoke-basedb.sh $MYDIR/$DB if faketime -f '-1 d' ./generate-revoke-basedb.sh "$MYDIR/$DB"
then then
check_with_database $MYDIR/$DB check_with_database "$MYDIR/$DB"
if test x$fail != x0 if [ "x$fail" != "x0" ]
then then
exit $fail exit "$fail"
else else
echo "Cleaning up $MYDIR..." echo "Cleaning up $MYDIR..."
rm -rf $MYDIR || echo "Removing $MYDIR failed" rm -rf "$MYDIR" || echo "Removing $MYDIR failed"
fi fi
else else
echo "Generation failed" echo "Generation failed"