diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-04 04:06:16 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-04 04:06:16 +0200 |
commit | 97ca10d8353a003deb0f460cd99d938639750368 (patch) | |
tree | d4352662a413bffa9276280541a015bfe9317939 /src | |
parent | 161958a2bb5a61346c3e1a48aa551b6f05dea42a (diff) | |
download | exchange-97ca10d8353a003deb0f460cd99d938639750368.tar.xz |
more auditor tests, misc auditor bugfixes
Diffstat (limited to 'src')
-rw-r--r-- | src/auditor/taler-auditor.c | 4 | ||||
-rw-r--r-- | src/auditor/taler-wire-auditor.c | 71 | ||||
-rwxr-xr-x | src/auditor/test-auditor.sh | 229 |
3 files changed, 258 insertions, 46 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index 0563ff70d..94369547b 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -5222,8 +5222,10 @@ run (void *cls, /* block */ "reserve_balance_insufficient_inconsistencies", report_reserve_balance_insufficient_inconsistencies, + /* Tested in test-auditor.sh #3 */ "total_loss_balance_insufficient", TALER_JSON_from_amount (&total_balance_insufficient_loss), + /* Tested in test-auditor.sh #3 */ "reserve_balance_summary_wrong_inconsistencies", report_reserve_balance_summary_wrong_inconsistencies, "total_balance_summary_delta_plus", @@ -5264,9 +5266,11 @@ run (void *cls, TALER_JSON_from_amount (&total_wire_out_delta_plus), "total_wire_out_delta_minus", TALER_JSON_from_amount (&total_wire_out_delta_minus), + /* Tested in test-auditor.sh #4/#5/#6/#7 */ "bad_sig_losses", report_bad_sig_losses, /* block */ + /* Tested in test-auditor.sh #4/#5/#6/#7 */ "total_bad_sig_loss", TALER_JSON_from_amount (&total_bad_sig_loss), "row_inconsistencies", diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c index 8eec0dcf7..c52afc0f3 100644 --- a/src/auditor/taler-wire-auditor.c +++ b/src/auditor/taler-wire-auditor.c @@ -320,6 +320,20 @@ struct ReserveOutInfo /** + * Convert absolute time to human-readable JSON string. + * + * @param at time to convert + * @return human-readable string representing the time + */ +static json_t * +json_from_time_abs (struct GNUNET_TIME_Absolute at) +{ + return json_string + (GNUNET_STRINGS_absolute_time_to_string (at)); +} + + +/** * Free entry in #in_map. * * @param cls NULL @@ -390,25 +404,33 @@ do_shutdown (void *cls) " s:o, s:o, s:o, s:o, s:o," " s:o, s:o, s:o, s:o }", /* blocks of 5 */ + /* Tested in test-auditor.sh #11 */ "wire_out_amount_inconsistencies", report_wire_out_inconsistencies, "total_wire_out_delta_plus", TALER_JSON_from_amount (&total_bad_amount_out_plus), + /* Tested in test-auditor.sh #11 */ "total_wire_out_delta_minus", TALER_JSON_from_amount (&total_bad_amount_out_minus), + /* Tested in test-auditor.sh #2 */ "reserve_in_amount_inconsistencies", report_reserve_in_inconsistencies, + /* Tested in test-auditor.sh #2 */ "total_wire_in_delta_plus", TALER_JSON_from_amount (&total_bad_amount_in_plus), /* block */ + /* Tested in test-auditor.sh #3 */ "total_wire_in_delta_minus", TALER_JSON_from_amount (&total_bad_amount_in_minus), + /* Tested in test-auditor.sh #9 */ "missattribution_in_inconsistencies", report_missattribution_in_inconsistencies, + /* Tested in test-auditor.sh #9 */ "total_missattribution_in", TALER_JSON_from_amount (&total_missattribution_in), "row_inconsistencies", report_row_inconsistencies, + /* Tested in test-auditor.sh #10 */ "row_minor_inconsistencies", report_row_minor_inconsistencies, /* block */ @@ -649,11 +671,10 @@ wire_missing_cb (void *cls, &tiny_amount)) ) return; /* acceptable, amount was tiny */ report (report_lags, - json_pack ("{s:I, s:o, s:s, s:s, s:o, s:O}", + json_pack ("{s:I, s:o, s:o, s:s, s:o, s:O}", "row", (json_int_t) rowid, "amount", TALER_JSON_from_amount (amount), - "deadline", GNUNET_STRINGS_absolute_time_to_string ( - deadline), + "deadline", json_from_time_abs (deadline), "claimed_done", (done) ? "yes" : "no", "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), "account", wire)); @@ -757,13 +778,12 @@ wire_out_cb (void *cls, This is moderately harmless, it might just be that the aggreator has not yet fully caught up with the transfers it should do. */ report (report_wire_out_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rowid, "amount_wired", TALER_JSON_from_amount (&zero), "amount_justified", TALER_JSON_from_amount (amount), "wtid", GNUNET_JSON_from_data_auto (wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( - date), + "timestamp", json_from_time_abs (date), "diagnostic", "wire transfer not made (yet?)")); GNUNET_break (GNUNET_OK == TALER_amount_add (&total_bad_amount_out_minus, @@ -782,27 +802,25 @@ wire_out_cb (void *cls, we should count the wire transfer as entirely spurious, and additionally consider the justified wire transfer as missing. */ report (report_wire_out_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rowid, "amount_wired", TALER_JSON_from_amount ( &roi->details.amount), "amount_justified", TALER_JSON_from_amount (&zero), "wtid", GNUNET_JSON_from_data_auto (wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( - date), + "timestamp", json_from_time_abs (date), "diagnostic", "recevier account missmatch")); GNUNET_break (GNUNET_OK == TALER_amount_add (&total_bad_amount_out_plus, &total_bad_amount_out_plus, &roi->details.amount)); report (report_wire_out_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rowid, "amount_wired", TALER_JSON_from_amount (&zero), "amount_justified", TALER_JSON_from_amount (amount), "wtid", GNUNET_JSON_from_data_auto (wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( - date), + "timestamp", json_from_time_abs (date), "diagnostic", "receiver account missmatch")); GNUNET_break (GNUNET_OK == TALER_amount_add (&total_bad_amount_out_minus, @@ -817,14 +835,13 @@ wire_out_cb (void *cls, amount)) { report (report_wire_out_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rowid, "amount_justified", TALER_JSON_from_amount (amount), "amount_wired", TALER_JSON_from_amount ( &roi->details.amount), "wtid", GNUNET_JSON_from_data_auto (wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( - date), + "timestamp", json_from_time_abs (date), "diagnostic", "wire amount does not match")); if (0 < TALER_amount_cmp (amount, &roi->details.amount)) @@ -899,7 +916,7 @@ complain_out_not_found (void *cls, (void) wa; // FIXME: log which account is affected... report (report_wire_out_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) 0, "amount_wired", TALER_JSON_from_amount ( &roi->details.amount), @@ -907,7 +924,7 @@ complain_out_not_found (void *cls, "wtid", (NULL == roi->details.wtid_s) ? GNUNET_JSON_from_data_auto (&roi->details.wtid) : json_string (roi->details.wtid_s), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( + "timestamp", json_from_time_abs ( roi->details.execution_date), "diagnostic", "justification for wire transfer not found")); @@ -1258,13 +1275,13 @@ complain_in_not_found (void *cls, struct ReserveInInfo *rii = value; report (report_reserve_in_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:s, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s, s:s}", "row", (json_int_t) rii->rowid, - "amount_expected", TALER_JSON_from_amount ( + "amount_exchange_expected", TALER_JSON_from_amount ( &rii->details.amount), "amount_wired", TALER_JSON_from_amount (&zero), "wtid", GNUNET_JSON_from_data_auto (&rii->details.wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( + "timestamp", json_from_time_abs ( rii->details.execution_date), "account", wa->section_name, "diagnostic", @@ -1393,7 +1410,7 @@ history_credit_cb (void *cls, &rii->details.wtid)) { report (report_reserve_in_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rii->rowid, "raw_bank_row", GNUNET_JSON_from_data (row_off, row_off_size), @@ -1401,7 +1418,7 @@ history_credit_cb (void *cls, &rii->details.amount), "amount_wired", TALER_JSON_from_amount (&zero), "wtid", GNUNET_JSON_from_data_auto (&rii->details.wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( + "timestamp", json_from_time_abs ( rii->details.execution_date), "diagnostic", "wire subject does not match")); GNUNET_break (GNUNET_OK == @@ -1409,7 +1426,7 @@ history_credit_cb (void *cls, &total_bad_amount_in_minus, &rii->details.amount)); report (report_reserve_in_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rii->rowid, "raw_bank_row", GNUNET_JSON_from_data (row_off, row_off_size), @@ -1418,7 +1435,7 @@ history_credit_cb (void *cls, "amount_wired", TALER_JSON_from_amount ( &details->amount), "wtid", GNUNET_JSON_from_data_auto (&details->wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( + "timestamp", json_from_time_abs ( details->execution_date), "diagnostic", "wire subject does not match")); @@ -1432,7 +1449,7 @@ history_credit_cb (void *cls, &details->amount)) { report (report_reserve_in_inconsistencies, - json_pack ("{s:I, s:o, s:o, s:o, s:o, s:s, s:s}", + json_pack ("{s:I, s:o, s:o, s:o, s:o, s:o, s:s}", "row", (json_int_t) rii->rowid, "raw_bank_row", GNUNET_JSON_from_data (row_off, row_off_size), @@ -1441,7 +1458,7 @@ history_credit_cb (void *cls, "amount_wired", TALER_JSON_from_amount ( &details->amount), "wtid", GNUNET_JSON_from_data_auto (&details->wtid), - "timestamp", GNUNET_STRINGS_absolute_time_to_string ( + "timestamp", json_from_time_abs ( details->execution_date), "diagnostic", "wire amount does not match")); if (0 < TALER_amount_cmp (&details->amount, @@ -1479,7 +1496,7 @@ history_credit_cb (void *cls, rii->details.account_url)) { report (report_missattribution_in_inconsistencies, - json_pack ("{s:s, s:I, s:o, s:o}", + json_pack ("{s:o, s:I, s:o, s:o}", "amount", TALER_JSON_from_amount (&rii->details.amount), "row", (json_int_t) rii->rowid, "raw_bank_row", GNUNET_JSON_from_data (row_off, diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index 5dacaf195..da9faee64 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 7` +ALL_TESTS=`seq 0 10` # $TESTS determines which tests we should run. # This construction is used to make it easy to @@ -32,7 +32,7 @@ function exit_skip() { # Exit, with error message (hard failure) function exit_fail() { echo $1 - kill `jobs -p` + kill `jobs -p` >/dev/null 2>/dev/null || true exit 1 } @@ -54,7 +54,7 @@ function run_audit () { if test ${1:-no} = "aggregator" then - echo -e "Running exchange aggregator ..." + echo -n "Running exchange aggregator ..." taler-exchange-aggregator -t -c test-auditor.conf echo " DONE" fi @@ -65,7 +65,7 @@ function run_audit () { taler-wire-auditor -r -c test-auditor.conf -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" echo " DONE" - + kill `jobs -p` || true echo -n "TeXing ..." @@ -245,7 +245,7 @@ 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" + exit_fail "Expected total wire delta plus wrong, got $DELTA" fi echo OK @@ -324,7 +324,7 @@ test_4() { echo "===========4: deposit wire target wrong=================" # Original target bank account was 43, changing to 44 -OLD_WIRE=`echo 'SELECT wire FROM deposits WHERE deposit_serial_id=1;' | psql taler-auditor-test -Aqt` +OLD_WIRE=`echo 'SELECT wire FROM deposits WHERE deposit_serial_id=1;' | psql $DB -Aqt` echo "UPDATE deposits SET wire='{\"url\":\"payto://x-taler-bank/localhost:8082/44\",\"salt\":\"test-salt\"}' WHERE deposit_serial_id=1" | psql -Aqt $DB run_audit @@ -365,7 +365,7 @@ echo "UPDATE deposits SET wire='$OLD_WIRE' WHERE deposit_serial_id=1" | psql -Aq test_5() { echo "===========5: deposit contract hash wrong=================" # Modify h_wire hash, so it is inconsistent with 'wire' -OLD_H=`echo 'SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=1;' | psql taler-auditor-test -Aqt` +OLD_H=`echo 'SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=1;' | psql $DB -Aqt` echo "UPDATE deposits SET h_contract_terms='\x12bb676444955c98789f219148aa31899d8c354a63330624d3d143222cf3bb8b8e16f69accd5a8773127059b804c1955696bf551dd7be62719870613332aa8d5' WHERE deposit_serial_id=1" | psql -Aqt $DB run_audit @@ -405,8 +405,8 @@ echo "UPDATE deposits SET h_contract_terms='${OLD_H}' WHERE deposit_serial_id=1" test_6() { echo "===========6: known_coins signature wrong=================" # Modify denom_sig, so it is wrong -OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql taler-auditor-test -Aqt` -COIN_PUB=`echo "SELECT coin_pub FROM known_coins WHERE denom_sig='$OLD_SIG';" | psql taler-auditor-test -Aqt` +OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt` +COIN_PUB=`echo "SELECT coin_pub FROM known_coins WHERE denom_sig='$OLD_SIG';" | psql $DB -Aqt` echo "UPDATE known_coins SET denom_sig='\x287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" | psql -Aqt $DB run_audit @@ -446,10 +446,10 @@ echo "UPDATE known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" | test_7() { echo "===========7: reserves_out signature wrong=================" # Modify reserve_sig, so it is bogus -HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql taler-auditor-test -Aqt` -OLD_SIG=`echo "SELECT reserve_sig FROM reserves_out WHERE h_blind_ev='$HBE';" | psql taler-auditor-test -Aqt` -A_VAL=`echo "SELECT amount_with_fee_val FROM reserves_out WHERE h_blind_ev='$HBE';" | psql taler-auditor-test -Aqt` -A_FRAC=`echo "SELECT amount_with_fee_frac FROM reserves_out WHERE h_blind_ev='$HBE';" | psql taler-auditor-test -Aqt` +HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql $DB -Aqt` +OLD_SIG=`echo "SELECT reserve_sig FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt` +A_VAL=`echo "SELECT amount_with_fee_val FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt` +A_FRAC=`echo "SELECT amount_with_fee_frac FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt` # Normalize, we only deal with cents in this test-case A_FRAC=`expr $A_FRAC / 1000000` echo "UPDATE reserves_out SET reserve_sig='\x9ef381a84aff252646a157d88eded50f708b2c52b7120d5a232a5b628f9ced6d497e6652d986b581188fb014ca857fd5e765a8ccc4eb7e2ce9edcde39accaa4b' WHERE h_blind_ev='$HBE'" | psql -Aqt $DB @@ -493,12 +493,202 @@ echo "UPDATE reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" | } -# NEXT: wire transfer subject disagreement! (for wire-auditor!) +# Test wire transfer subject disagreement! +test_8() { -# NEXT: wire fee disagreement! (for wire-auditor!) +echo "===========8: wire-transfer-subject disagreement===========" +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_WTID=`echo "SELECT subject FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt` +NEW_WTID="CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG" +echo "UPDATE app_banktransaction SET subject='$NEW_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB +run_audit -# Test where h_wire in the deposit table is wrong +echo -n "Test for inconsistency detection... " +DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-wire-audit.json` +if test "x$DIAG" != "xwire subject does not match" +then + exit_fail "Diagnostic wrong: $DIAG (0)" +fi +WTID=`jq -r .reserve_in_amount_inconsistencies[0].wtid < test-wire-audit.json` +if test x$WTID != x"$OLD_WTID" -a x$WTID != x"$NEW_WTID" +then + exit_fail "WTID reported wrong: $WTID" +fi +EX_A=`jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-wire-audit.json` +if test x$WTID = x$OLD_WTID -a x$EX_A != x"TESTKUDOS:10" +then + exit_fail "Amount reported wrong: $EX_A" +fi +if test x$WTID = x$NEW_WTID -a x$EX_A != x"TESTKUDOS:0" +then + exit_fail "Amount reported wrong: $EX_A" +fi +DIAG=`jq -r .reserve_in_amount_inconsistencies[1].diagnostic < test-wire-audit.json` +if test "x$DIAG" != "xwire subject does not match" +then + exit_fail "Diagnostic wrong: $DIAG (1)" +fi +WTID=`jq -r .reserve_in_amount_inconsistencies[1].wtid < test-wire-audit.json` +if test $WTID != "$OLD_WTID" -a $WTID != "$NEW_WTID" +then + exit_fail "WTID reported wrong: $WTID" +fi +EX_A=`jq -r .reserve_in_amount_inconsistencies[1].amount_exchange_expected < test-wire-audit.json` +if test $WTID = "$OLD_WTID" -a $EX_A != "TESTKUDOS:10" +then + exit_fail "Amount reported wrong: $EX_A" +fi +if test $WTID = "$NEW_WTID" -a $EX_A != "TESTKUDOS:0" +then + exit_fail "Amount reported wrong: $EX_A" +fi + +WIRED=`jq -r .total_wire_in_delta_minus < test-wire-audit.json` +if test $WIRED != "TESTKUDOS:10" +then + exit_fail "Wrong total wire_in_delta_minus, got $WIRED" +fi +DELTA=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` +if test $DELTA != "TESTKUDOS:10" +then + exit_fail "Expected total wire delta plus wrong, got $DELTA" +fi +echo OK + +# Undo database modification +echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB + +} + + + +# Test wire origin disagreement! +test_9() { + +echo "===========9: wire-origin disagreement===========" +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_ACC=`echo "SELECT debit_account_id FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt` +echo "UPDATE app_banktransaction SET debit_account_id=1;" | psql -Aqt $DB + +run_audit + +echo -n "Test for inconsistency detection... " +AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-wire-audit.json` +if test "x$AMOUNT" != "xTESTKUDOS:10" +then + exit_fail "Reported amount wrong: $AMOUNT" +fi +AMOUNT=`jq -r .total_missattribution_in < test-wire-audit.json` +if test "x$AMOUNT" != "xTESTKUDOS:10" +then + exit_fail "Reported total amount wrong: $AMOUNT" +fi +echo OK + +# Undo database modification +echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC;" | psql -Aqt $DB + +} + + +# Test wire_in timestamp disagreement! +test_10() { + +echo "===========10: wire-timestamp disagreement===========" +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_DATE=`echo "SELECT date FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt` +echo "UPDATE app_banktransaction SET date=NOW() WHERE id=$OLD_ID;" | psql -Aqt $DB + +run_audit + +echo -n "Test for inconsistency detection... " +DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json` +if test "x$DIAG" != "xexecution date missmatch" +then + exit_fail "Reported diagnostic wrong: $DIAG" +fi +TABLE=`jq -r .row_minor_inconsistencies[0].table < test-wire-audit.json` +if test "x$TABLE" != "xreserves_in" +then + exit_fail "Reported table wrong: $TABLE" +fi +echo OK + +# Undo database modification +echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql -Aqt $DB + +} + + +# Test for extra outgoing wire transfer. +test_11() { + +echo "===========11: spurious outgoing transfer ===========" +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_ACC=`echo "SELECT debit_account_id FROM app_banktransaction WHERE id=$OLD_ID;" | psql $DB -Aqt` +# Change wire transfer to be FROM the exchange (#2) to elsewhere! +# (Note: this change also causes a missing incoming wire transfer, but +# this test is only concerned about the outgoing wire transfer +# being detected as such, and we simply ignore the other +# errors being reported.) +echo "UPDATE app_banktransaction SET debit_account_id=2,credit_account_id=1 WHERE id=$OLD_ID;" | psql -Aqt $DB + +run_audit + +echo -n "Test for inconsistency detection... " +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` +if test "x$AMOUNT" != "xTESTKUDOS:10" +then + exit_fail "Reported amount wrong: $AMOUNT" +fi +AMOUNT=`jq -r .total_wire_out_delta_minus < test-wire-audit.json` +if test "x$AMOUNT" != "xTESTKUDOS:10" +then + exit_fail "Reported amount wrong: $AMOUNT" +fi +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-wire-audit.json` +if test "x$AMOUNT" != "xTESTKUDOS:0" +then + exit_fail "Reported amount wrong: $AMOUNT" +fi +DIAG=`jq -r .wire_out_amount_inconsistencies[0].diagnostic < test-wire-audit.json` +if test "x$DIAG" != "xjustification for wire transfer not found" +then + exit_fail "Reported diagnostic wrong: $DIAG" +fi +echo OK + +# Undo database modification (exchange always has account #2) +echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id=2 WHERE id=$OLD_ID;" | psql -Aqt $DB + +} + + +# FIXME: Test for wire fee disagreement +test_98() { + +echo "===========11: wire-fee disagreement===========" +echo "UPDATE wire_fee SET wire_fee_frac='100';" | psql -Aqt $DB + +# Wire fees are only checked/generated once there are +# actual outgoing wire transfers, so we need to run the +# aggregator here. +run_audit aggregator + +# FIXME: needs new DB where aggregator does stuff! +# FIXME: check report generation! + +# cannot easily undo aggregator, hence full reload +echo -n "Reloading database ..." +full_reload +echo "DONE" + +} + + + +# FIXME: Test where h_wire in the deposit table is wrong test_99() { echo "===========99: deposit wire hash wrong=================" # Modify h_wire hash, so it is inconsistent with 'wire' @@ -515,9 +705,10 @@ run_audit aggregator # FIXME: check for the respective inconsistency in the report! -# Undo: -# echo "UPDATE deposits SET h_wire='\x973e52d193a357940be9ef2939c19b0575ee1101f52188c3c01d9005b7d755c397e92624f09cfa709104b3b65605fe5130c90d7e1b7ee30f8fc570f39c16b852' WHERE deposit_serial_id=1" | psql -Aqt $DB - +# cannot easily undo aggregator, hence full reload +echo -n "Reloading database ..." +full_reload +echo "DONE" } |