commit 6532c90ece44394bafec7957bf3ce2cb1dbbeaf2
parent 0ccb54cfa385179527bb865a4e1108b2f66c60d8
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 8 Oct 2024 15:31:46 +0200
implement auditor test_16, plus associated bugfixes
Diffstat:
3 files changed, 134 insertions(+), 114 deletions(-)
diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c
@@ -54,24 +54,24 @@
* created by imperfect clock synchronization and network delay.
*/
#define TIME_TOLERANCE GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MINUTES, \
- 15)
+ GNUNET_TIME_UNIT_MINUTES, \
+ 15)
/**
* How long do we try to long-poll for bank wire transfers?
*/
#define MAX_LONGPOLL_DELAY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_HOURS, \
- 1)
+ GNUNET_TIME_UNIT_HOURS, \
+ 1)
/**
* How long do we wait between polling for bank wire transfers at the minimum?
*/
#define MIN_LONGPOLL_DELAY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MINUTES, \
- 5)
+ GNUNET_TIME_UNIT_MINUTES, \
+ 5)
/**
@@ -714,14 +714,16 @@ check_rc_matches (void *cls,
{
struct CheckMatchContext *cmx = cls;
struct ReserveClosure *rc = value;
+ char *ra = TALER_payto_normalize (rc->receiver_account);
if ((0 == GNUNET_memcmp (&cmx->roi->details.wtid,
&rc->wtid)) &&
- (0 == strcasecmp (rc->receiver_account,
+ (0 == strcasecmp (ra,
cmx->roi->details.credit_account_uri)) &&
(0 == TALER_amount_cmp (&rc->amount,
&cmx->roi->details.amount)))
{
+ GNUNET_free (ra);
if (! check_time_difference ("reserves_closures",
rc->rowid,
rc->execution_date,
@@ -738,6 +740,7 @@ check_rc_matches (void *cls,
rc);
return GNUNET_NO;
}
+ GNUNET_free (ra);
return GNUNET_OK;
}
@@ -1072,6 +1075,7 @@ wire_out_cb (
struct WireAccount *wa = cls;
struct GNUNET_HashCode key;
struct ReserveOutInfo *roi;
+ char *np = TALER_payto_normalize (payto_uri);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Exchange wire OUT #%llu at %s of %s with WTID %s\n",
@@ -1098,7 +1102,7 @@ wire_out_cb (
May be cleared later by check_reported_inconsistency() */
char diag[MAX_DIAG_LEN];
struct TALER_AUDITORDB_WireOutInconsistency woi = {
- .destination_account = (char *) payto_uri,
+ .destination_account = np,
.diagnostic = diag,
.wire_out_row_id = rowid,
.expected = *amount,
@@ -1114,6 +1118,7 @@ wire_out_cb (
qs = TALER_ARL_adb->insert_wire_out_inconsistency (
TALER_ARL_adb->cls,
&woi);
+ GNUNET_free (np);
if (qs < 0)
{
global_qs = qs;
@@ -1125,59 +1130,61 @@ wire_out_cb (
amount);
return GNUNET_OK;
}
+
+ if (0 != strcasecmp (np,
+ roi->details.credit_account_uri))
{
- char *np = TALER_payto_normalize (payto_uri);
+ /* Destination bank account is wrong in actual wire transfer, so
+ we should count the wire transfer as entirely spurious, and
+ additionally consider the justified wire transfer as missing. */
+ struct TALER_AUDITORDB_WireOutInconsistency woi = {
+ .wire_out_row_id = rowid,
+ .destination_account = np,
+ .diagnostic = "receiver account mismatch",
+ .expected = *amount,
+ .claimed = roi->details.amount,
+ };
+ enum GNUNET_DB_QueryStatus qs;
- if (0 != strcasecmp (np,
- roi->details.credit_account_uri))
+ qs = TALER_ARL_adb->insert_wire_out_inconsistency (
+ TALER_ARL_adb->cls,
+ &woi);
+ GNUNET_free (np);
+ if (qs < 0)
{
- /* Destination bank account is wrong in actual wire transfer, so
- we should count the wire transfer as entirely spurious, and
- additionally consider the justified wire transfer as missing. */
- struct TALER_AUDITORDB_WireOutInconsistency woi = {
- .wire_out_row_id = rowid,
- .destination_account = (char *) payto_uri,
- .diagnostic = "receiver account mismatch",
- .expected = *amount,
- .claimed = zero,
- };
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_free (np);
- qs = TALER_ARL_adb->insert_wire_out_inconsistency (
- TALER_ARL_adb->cls,
- &woi);
- if (qs < 0)
- {
- global_qs = qs;
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return GNUNET_SYSERR;
- }
- TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus),
- &TALER_ARL_USE_AB (total_bad_amount_out_plus),
- &roi->details.amount);
- TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_minus),
- &TALER_ARL_USE_AB (total_bad_amount_out_minus),
- amount);
- return GNUNET_OK;
+ global_qs = qs;
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return GNUNET_SYSERR;
}
- GNUNET_free (np);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_plus),
+ &TALER_ARL_USE_AB (total_bad_amount_out_plus),
+ &roi->details.amount);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_bad_amount_out_minus),
+ &TALER_ARL_USE_AB (total_bad_amount_out_minus),
+ amount);
+ GNUNET_assert (GNUNET_OK ==
+ free_roi (NULL,
+ &key,
+ roi));
+ return GNUNET_OK;
}
+
if (0 != TALER_amount_cmp (&roi->details.amount,
amount))
{
struct TALER_AUDITORDB_WireOutInconsistency woi = {
- .destination_account = (char *) payto_uri,
+ .destination_account = np,
.diagnostic = "wire amount does not match",
.wire_out_row_id = rowid,
.expected = *amount,
- .claimed = zero,
+ .claimed = roi->details.amount,
};
enum GNUNET_DB_QueryStatus qs;
qs = TALER_ARL_adb->insert_wire_out_inconsistency (
TALER_ARL_adb->cls,
&woi);
+ GNUNET_free (np);
if (qs < 0)
{
global_qs = qs;
@@ -1209,6 +1216,10 @@ wire_out_cb (
&TALER_ARL_USE_AB (total_bad_amount_out_plus),
&delta);
}
+ GNUNET_assert (GNUNET_OK ==
+ free_roi (NULL,
+ &key,
+ roi));
return GNUNET_OK;
}
@@ -1231,6 +1242,7 @@ wire_out_cb (
free_roi (NULL,
&key,
roi));
+ GNUNET_free (np);
return ret;
}
}
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh
@@ -1283,103 +1283,90 @@ function test_15() {
# Test where wired amount (wire out) is wrong
-# FIXME: test-16 not implemented
function test_16() {
echo "===========16: incorrect wire_out amount================="
- # Check wire transfer lag reported (no aggregator!)
-
# First, we need to run the aggregator so we even
# have a wire_out to modify.
pre_audit aggregator
check_auditor_running
-#TODO FIX LIBEUFIN
- #stop_libeufin
- #OLD_AMOUNT=$(echo "SELECT amount FROM TalerRequestedPayments WHERE id='1';" | psql "${DB}" -Aqt)
- #NEW_AMOUNT="TESTKUDOS:50"
- #echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" \
- # | psql "${DB}" -q
- #launch_libeufin
- #audit_only
- #check_auditor_running
-#
- #echo -n "Testing inconsistency detection... "
+ stop_libeufin
+ OLD_AMOUNT_VAL=$(echo "SELECT (amount).val FROM libeufin_bank.bank_account_transactions WHERE debtor_name='Exchange Company' AND direction='debit';" | psql "${DB}" -Aqt)
+ OLD_AMOUNT_FRAC=$(echo "SELECT (amount).frac FROM libeufin_bank.bank_account_transactions WHERE debtor_name='Exchange Company' AND direction='debit';" | psql "${DB}" -Aqt)
+ if [[ 0 = "$OLD_AMOUNT_FRAC" ]]
+ then
+ OLD_AMOUNT="TESTKUDOS:${OLD_AMOUNT_VAL}"
+ else
+ OLD_AMOUNT_CENTS=$(($OLD_AMOUNT_FRAC / 1000000))
+ if [[ 10 -gt "$OLD_AMOUNT_CENTS" ]]
+ then
+ OLD_AMOUNT="TESTKUDOS:${OLD_AMOUNT_VAL}.0${OLD_AMOUNT_CENTS}"
+ else
+ OLD_AMOUNT="TESTKUDOS:${OLD_AMOUNT_VAL}.${OLD_AMOUNT_CENTS}"
+ fi
+ fi
+ NEW_AMOUNT="TESTKUDOS:50"
+ echo "UPDATE libeufin_bank.bank_account_transactions SET amount=(50,0) WHERE debtor_name='Exchange Company';" \
+ | psql "${DB}" -q
+ launch_libeufin
+ await_bank
+
+ audit_only
+ check_auditor_running
+
+ echo -n "Testing wire-out-inconsistency-expected... "
check_report \
"wire-out-inconsistency" \
"expected" \
"$OLD_AMOUNT"
-
- #AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json)
- #if [ "$AMOUNT" != "$OLD_AMOUNT" ]
- #then
- # exit_fail "Reported justified amount wrong: $AMOUNT"
- #fi
+ echo -n "Testing wire-out-inconsistency-claimed... "
check_report \
"wire-out-inconsistency" \
"claimed" \
"$NEW_AMOUNT"
- #AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
- #if [ "$AMOUNT" != "$NEW_AMOUNT" ]
- #then
- # exit_fail "Reported wired amount wrong: $AMOUNT"
- #fi
- #TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
- #if [ "$TOTAL_AMOUNT" != "TESTKUDOS:0" ]
- #then
- # exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT"
- #fi
echo -n "Testing bad_amount_minus balance reporting... "
- check_not_balance \
+ check_balance \
"total_bad_amount_out_minus" \
"TESTKUDOS:0" \
"reported total_bad_amount_minus wrong"
+ echo -n "Testing bad_amount_plus balance reporting... "
+ check_not_balance \
+ "total_bad_amount_out_plus" \
+ "TESTKUDOS:0" \
+ "reported total_bad_amount_plus wrong"
- #TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
- #if [ "$TOTAL_AMOUNT" = "TESTKUDOS:0" ]
- #then
- # exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT"
- #fi
- #echo "PASS"
+ stop_libeufin
+ echo "Second modification: wire nothing"
+ NEW_AMOUNT="TESTKUDOS:0"
+ echo "UPDATE libeufin_bank.bank_account_transactions SET amount=(0,0) WHERE debtor_name='Exchange Company';" \
+ | psql "${DB}" -q
+ launch_libeufin
+ audit_only
+ stop_libeufin
+ bash
+ echo -n "Testing wire-out-inconsistency-expected... "
+ check_report \
+ "wire-out-inconsistency" \
+ "expected" \
+ "$OLD_AMOUNT"
+ echo -n "Testing wire-out-inconsistency-claimed... "
+ check_report \
+ "wire-out-inconsistency" \
+ "claimed" \
+ "$NEW_AMOUNT"
+ echo -n "Testing bad_amount_minus balance reporting... "
+ check_balance \
+ "total_bad_amount_out_minus" \
+ "$OLD_AMOUNT" \
+ "reported total_bad_amount_minus wrong"
echo -n "Testing bad_amount_plus balance reporting... "
- check_not_balance \
+ check_balance \
"total_bad_amount_out_plus" \
"TESTKUDOS:0" \
"reported total_bad_amount_plus wrong"
- #stop_libeufin
- #echo "Second modification: wire nothing"
- #NEW_AMOUNT="TESTKUDOS:0"
- #echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" \
- # | psql "${DB}" -q
- #launch_libeufin
- #audit_only
- #stop_libeufin
- #echo -n "Testing inconsistency detection... "
-#
- #AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json)
- #if [ "$AMOUNT" != "$OLD_AMOUNT" ]
- #then
- # exit_fail "Reported justified amount wrong: $AMOUNT"
- #fi
- #AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
- #if [ "$AMOUNT" != "$NEW_AMOUNT" ]
- #then
- # exit_fail "Reported wired amount wrong: $AMOUNT"
- #fi
- #TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
- #if [ "$TOTAL_AMOUNT" != "$OLD_AMOUNT" ]
- #then
- # exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT (wanted $OLD_AMOUNT)"
- #fi
- #TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
- #if [ "$TOTAL_AMOUNT" != "TESTKUDOS:0" ]
- #then
- # exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT"
- #fi
- #echo "PASS"
-#
- #post_audit
+ post_audit
# cannot easily undo aggregator, hence full reload
full_reload
diff --git a/src/auditordb/restart.sql b/src/auditordb/restart.sql
@@ -32,13 +32,34 @@ SET search_path TO auditor;
-- latest requirements for dropping tables.
DELETE FROM auditor_amount_arithmetic_inconsistency;
+DELETE FROM auditor_bad_sig_losses;
DELETE FROM auditor_balances;
+DELETE FROM auditor_closure_lags;
+DELETE FROM auditor_coin_inconsistency;
+DELETE FROM auditor_denomination_key_validity_withdraw_inconsistency;
DELETE FROM auditor_denomination_pending;
+DELETE FROM auditor_denominations_without_sigs;
+DELETE FROM auditor_emergency;
+DELETE FROM auditor_emergency_by_count;
+DELETE FROM auditor_fee_time_inconsistency;
DELETE FROM auditor_historic_denomination_revenue;
DELETE FROM auditor_historic_reserve_summary;
+DELETE FROM auditor_misattribution_in_inconsistency;
+DELETE FROM auditor_pending_deposits;
DELETE FROM auditor_progress;
+DELETE FROM auditor_purse_not_closed_inconsistencies;
DELETE FROM auditor_purses;
+DELETE FROM auditor_refreshes_hanging;
+DELETE FROM auditor_reserve_balance_insufficient_inconsistency;
+DELETE FROM auditor_reserve_balance_summary_wrong_inconsistency;
+DELETE FROM auditor_reserve_in_inconsistency;
+DELETE FROM auditor_reserve_not_closed_inconsistency;
DELETE FROM auditor_reserves;
+DELETE FROM auditor_row_inconsistency;
+DELETE FROM auditor_row_minor_inconsistencies;
+DELETE FROM auditor_wire_format_inconsistency;
+DELETE FROM auditor_wire_out_inconsistency;
+
-- And we're out of here...
COMMIT;