From 342cccc384148e93142ed9dca59ad23e58388564 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Jan 2020 14:22:34 +0100 Subject: do not rely on filetime, as Git does not preserve it --- src/auditor/auditor-basedb.age | 1 + src/auditor/generate-auditor-basedb.sh | 4 ++- src/auditor/taler-auditor.c | 7 +++-- src/auditor/test-auditor.sh | 48 +++++++++++++++++++++++++++++----- 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/auditor/auditor-basedb.age (limited to 'src/auditor') diff --git a/src/auditor/auditor-basedb.age b/src/auditor/auditor-basedb.age new file mode 100644 index 000000000..d81cc0710 --- /dev/null +++ b/src/auditor/auditor-basedb.age @@ -0,0 +1 @@ +42 diff --git a/src/auditor/generate-auditor-basedb.sh b/src/auditor/generate-auditor-basedb.sh index 3f896b31f..d23b67431 100755 --- a/src/auditor/generate-auditor-basedb.sh +++ b/src/auditor/generate-auditor-basedb.sh @@ -3,7 +3,8 @@ # testing from a 'correct' interaction between exchange, # wallet and merchant. # -# Creates $BASEDB.sql, $BASEDB.fees and $BASEDB.mpub. +# Creates $BASEDB.sql, $BASEDB.fees, $BASEDB.mpub and +# $BASEDB.age. # Default $BASEDB is "auditor-basedb", override via $1. # # Currently must be run online as it interacts with @@ -144,6 +145,7 @@ echo $MASTER_PUB > ${BASEDB}.mpub WIRE_FEE_DIR=`taler-config -c $CONF -f -s exchangedb -o WIREFEE_BASE_DIR` cp $WIRE_FEE_DIR/x-taler-bank.fee ${BASEDB}.fees +date +%s > ${BASEDB}.age # clean up echo "Final clean up" diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index 5f484d752..6752b34ab 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -2422,7 +2422,7 @@ check_transaction_history_for_deposit (const struct return GNUNET_SYSERR; } - /* Now check that 'spent' is less or equal than total coin value */ + /* Now check that 'spent' is less or equal than the total coin value */ TALER_amount_ntoh (&value, &issue->value); if (1 == TALER_amount_cmp (&spent, @@ -4658,14 +4658,13 @@ analyze_coins (void *cls) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - _ ( - "First analysis using this auditor, starting audit from scratch\n")); + "First analysis using this auditor, starting from scratch\n"); } else { ppc_start = ppc; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ ("Resuming coin audit at %llu/%llu/%llu/%llu/%llu\n"), + "Resuming coin audit at %llu/%llu/%llu/%llu/%llu\n", (unsigned long long) ppc.last_deposit_serial_id, (unsigned long long) ppc.last_melt_serial_id, (unsigned long long) ppc.last_refund_serial_id, diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index 832bfb836..06f1b3707 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -9,7 +9,7 @@ set -eu # Set of numbers for all the testcases. # When adding new tests, increase the last number: -ALL_TESTS=`seq 0 24` +ALL_TESTS=`seq 0 25` # $TESTS determines which tests we should run. # This construction is used to make it easy to @@ -118,7 +118,7 @@ function run_audit () { # Do a full reload of the (original) database full_reload() { - echo "Doing full reload of the database..." + echo -n "Doing full reload of the database... " dropdb $DB 2> /dev/null || true createdb -T template0 $DB || exit_skip "could not create database" # Import pre-generated database, -q(ietly) using single (-1) transaction @@ -1382,14 +1382,50 @@ full_reload } +# Test for inconsistent coin history. +function test_25() { + +echo "=========25: inconsistent coin history=========" +# Drop refund, so coin history is bogus. +echo "DELETE FROM refunds WHERE refund_serial_id=1;" | psql -Aqt $DB + +run_audit aggregator + +echo -n "Testing inconsistency detection... " + +jq -e .coin_inconsistencies[0] < test-audit.json > /dev/null || exit_fail "Coin inconsistency NOT detected" + +jq -e .row_inconsistencies[0] < test-audit.json > /dev/null || exit_fail "Coin history verification failure NOT reported" + +# Note: if the wallet withdrew much more than it spent, this might indeed +# go legitimately unnoticed. +jq -e .emergencies[0] < test-audit.json > /dev/null || exit_fail "Denomination value emergency NOT reported" + +AMOUNT=`jq -er .total_coin_delta_minus < test-audit.json` +if test x$AMOUNT = xTESTKUDOS:0 +then + exit_fail "Expected non-zero total inconsistency amount from coins" +fi +# Note: if the wallet withdrew much more than it spent, this might indeed +# go legitimately unnoticed. +COUNT=`jq -er .emergencies_risk_by_amount < test-audit.json` +if test x$AMOUNT = xTESTKUDOS:0 +then + exit_fail "Expected non-zero emergency-by-amount" +fi +echo PASS + +# cannot easily undo DELETE, hence full reload +full_reload +} + + # ************************************************** # FIXME: Add more tests here! :-) # Specifically: # - revocation (payback, accepting # of coins despite denomination revocation) -# - refunds -# - arithmetic problems # ************************************************** @@ -1413,8 +1449,8 @@ check_with_database() cp ${BASEDB}.fees $WIRE_FEE_DIR/x-taler-bank.fee # Determine database age - echo "Calculating database age based on ${BASEDB}.fees" - AGE=`stat -c %Y ${BASEDB}.fees` + echo "Calculating database age based on ${BASEDB}.age" + AGE=`cat ${BASEDB}.age` NOW=`date +%s` # NOTE: expr "fails" if the result is zero. DATABASE_AGE=`expr ${NOW} - ${AGE} || true` -- cgit v1.2.3