aboutsummaryrefslogtreecommitdiff
path: root/src/auditor/test-auditor.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/test-auditor.sh')
-rwxr-xr-xsrc/auditor/test-auditor.sh106
1 files changed, 89 insertions, 17 deletions
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh
index 5124999ed..d7ee79e96 100755
--- a/src/auditor/test-auditor.sh
+++ b/src/auditor/test-auditor.sh
@@ -9,7 +9,7 @@ set -eu
9 9
10# Set of numbers for all the testcases. 10# Set of numbers for all the testcases.
11# When adding new tests, increase the last number: 11# When adding new tests, increase the last number:
12ALL_TESTS=`seq 0 11` 12ALL_TESTS=`seq 0 13`
13 13
14# $TESTS determines which tests we should run. 14# $TESTS determines which tests we should run.
15# This construction is used to make it easy to 15# This construction is used to make it easy to
@@ -95,9 +95,9 @@ run_audit aggregator
95echo "Checking output" 95echo "Checking output"
96# if an emergency was detected, that is a bug and we should fail 96# if an emergency was detected, that is a bug and we should fail
97echo -n "Test for emergencies... " 97echo -n "Test for emergencies... "
98jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo OK 98jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
99echo -n "Test for emergencies by count... " 99echo -n "Test for emergencies by count... "
100jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo OK 100jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
101 101
102echo -n "Test for wire inconsistencies... " 102echo -n "Test for wire inconsistencies... "
103jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" 103jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
@@ -111,7 +111,7 @@ jq -e .wire_format_inconsistencies[0] < test-wire-audit.json > /dev/null && exit
111# FIXME: check operation balances are correct (once we have more transaction types) 111# FIXME: check operation balances are correct (once we have more transaction types)
112# FIXME: check revenue summaries are correct (once we have more transaction types) 112# FIXME: check revenue summaries are correct (once we have more transaction types)
113 113
114echo OK 114echo PASS
115 115
116echo -n "Test for wire amounts... " 116echo -n "Test for wire amounts... "
117WIRED=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` 117WIRED=`jq -r .total_wire_in_delta_plus < test-wire-audit.json`
@@ -161,9 +161,9 @@ run_audit
161echo "Checking output" 161echo "Checking output"
162# if an emergency was detected, that is a bug and we should fail 162# if an emergency was detected, that is a bug and we should fail
163echo -n "Test for emergencies... " 163echo -n "Test for emergencies... "
164jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo OK 164jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
165echo -n "Test for emergencies by count... " 165echo -n "Test for emergencies by count... "
166jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo OK 166jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
167 167
168echo -n "Test for wire inconsistencies... " 168echo -n "Test for wire inconsistencies... "
169jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" 169jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
@@ -177,7 +177,7 @@ jq -e .wire_format_inconsistencies[0] < test-wire-audit.json > /dev/null && exit
177# FIXME: check operation balances are correct (once we have more transaction types) 177# FIXME: check operation balances are correct (once we have more transaction types)
178# FIXME: check revenue summaries are correct (once we have more transaction types) 178# FIXME: check revenue summaries are correct (once we have more transaction types)
179 179
180echo OK 180echo PASS
181 181
182# FIXME: check wire transfer lag reported (no aggregator!) 182# FIXME: check wire transfer lag reported (no aggregator!)
183 183
@@ -220,7 +220,7 @@ echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql -
220 220
221run_audit 221run_audit
222 222
223echo -n "Test for inconsistency detection... " 223echo -n "Testing inconsistency detection... "
224ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-wire-audit.json` 224ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-wire-audit.json`
225if test $ROW != 1 225if test $ROW != 1
226then 226then
@@ -247,7 +247,7 @@ if test $DELTA != "TESTKUDOS:5"
247then 247then
248 exit_fail "Expected total wire delta plus wrong, got $DELTA" 248 exit_fail "Expected total wire delta plus wrong, got $DELTA"
249fi 249fi
250echo OK 250echo PASS
251 251
252# Undo database modification 252# Undo database modification
253echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt $DB 253echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt $DB
@@ -504,7 +504,7 @@ echo "UPDATE app_banktransaction SET subject='$NEW_WTID' WHERE id='$OLD_ID';" |
504 504
505run_audit 505run_audit
506 506
507echo -n "Test for inconsistency detection... " 507echo -n "Testing inconsistency detection... "
508DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-wire-audit.json` 508DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-wire-audit.json`
509if test "x$DIAG" != "xwire subject does not match" 509if test "x$DIAG" != "xwire subject does not match"
510then 510then
@@ -554,7 +554,7 @@ if test $DELTA != "TESTKUDOS:10"
554then 554then
555 exit_fail "Expected total wire delta plus wrong, got $DELTA" 555 exit_fail "Expected total wire delta plus wrong, got $DELTA"
556fi 556fi
557echo OK 557echo PASS
558 558
559# Undo database modification 559# Undo database modification
560echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB 560echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB
@@ -573,7 +573,7 @@ echo "UPDATE app_banktransaction SET debit_account_id=1;" | psql -Aqt $DB
573 573
574run_audit 574run_audit
575 575
576echo -n "Test for inconsistency detection... " 576echo -n "Testing inconsistency detection... "
577AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-wire-audit.json` 577AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-wire-audit.json`
578if test "x$AMOUNT" != "xTESTKUDOS:10" 578if test "x$AMOUNT" != "xTESTKUDOS:10"
579then 579then
@@ -584,7 +584,7 @@ if test "x$AMOUNT" != "xTESTKUDOS:10"
584then 584then
585 exit_fail "Reported total amount wrong: $AMOUNT" 585 exit_fail "Reported total amount wrong: $AMOUNT"
586fi 586fi
587echo OK 587echo PASS
588 588
589# Undo database modification 589# Undo database modification
590echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC;" | psql -Aqt $DB 590echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC;" | psql -Aqt $DB
@@ -602,7 +602,7 @@ echo "UPDATE app_banktransaction SET date=NOW() WHERE id=$OLD_ID;" | psql -Aqt $
602 602
603run_audit 603run_audit
604 604
605echo -n "Test for inconsistency detection... " 605echo -n "Testing inconsistency detection... "
606DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json` 606DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json`
607if test "x$DIAG" != "xexecution date missmatch" 607if test "x$DIAG" != "xexecution date missmatch"
608then 608then
@@ -613,7 +613,7 @@ if test "x$TABLE" != "xreserves_in"
613then 613then
614 exit_fail "Reported table wrong: $TABLE" 614 exit_fail "Reported table wrong: $TABLE"
615fi 615fi
616echo OK 616echo PASS
617 617
618# Undo database modification 618# Undo database modification
619echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql -Aqt $DB 619echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql -Aqt $DB
@@ -636,7 +636,7 @@ echo "UPDATE app_banktransaction SET debit_account_id=2,credit_account_id=1 WHER
636 636
637run_audit 637run_audit
638 638
639echo -n "Test for inconsistency detection... " 639echo -n "Testing inconsistency detection... "
640AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` 640AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json`
641if test "x$AMOUNT" != "xTESTKUDOS:10" 641if test "x$AMOUNT" != "xTESTKUDOS:10"
642then 642then
@@ -662,7 +662,7 @@ if test "x$DIAG" != "xjustification for wire transfer not found"
662then 662then
663 exit_fail "Reported diagnostic wrong: $DIAG" 663 exit_fail "Reported diagnostic wrong: $DIAG"
664fi 664fi
665echo OK 665echo PASS
666 666
667# Undo database modification (exchange always has account #2) 667# Undo database modification (exchange always has account #2)
668echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id=2 WHERE id=$OLD_ID;" | psql -Aqt $DB 668echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id=2 WHERE id=$OLD_ID;" | psql -Aqt $DB
@@ -670,6 +670,78 @@ echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id
670} 670}
671 671
672 672
673
674# Test for hanging/pending refresh.
675test_12() {
676
677echo "===========12: incomplete refresh ==========="
678OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt`
679
680run_audit
681
682echo -n "Testing hung refresh detection... "
683
684HANG=`jq -er .refresh_hanging[0].amount < test-audit.json`
685TOTAL_HANG=`jq -e .total_refresh_hanging < test-audit.json`
686if test x$HANG != x$TOTAL_HANG
687then
688 exit_fail "Hanging amount inconsistent, got $HANG and $TOTAL_HANG"
689fi
690if test x$TOTAL_HANG = TESTKUDOS:0
691then
692 exit_fail "Hanging amount zero"
693fi
694
695echo PASS
696
697
698# cannot easily undo DELETE, hence full reload
699echo -n "Reloading database ..."
700full_reload
701echo "DONE"
702}
703
704
705# Test for wrong signature on refresh.
706test_13() {
707
708echo "===========13: wrong melt signature ==========="
709# Modify denom_sig, so it is wrong
710COIN_PUB=`echo "SELECT old_coin_pub FROM refresh_commitments LIMIT 1;" | psql $DB -Aqt`
711OLD_SIG=`echo "SELECT old_coin_sig FROM refresh_commitments WHERE old_coin_pub='$COIN_PUB';" | psql $DB -Aqt`
712NEW_SIG="\xba588af7c13c477dca1ac458f65cc484db8fba53b969b873f4353ecbd815e6b4c03f42c0cb63a2b609c2d726e612fd8e0c084906a41f409b6a23a08a83c89a02"
713echo "UPDATE refresh_commitments SET old_coin_sig='$NEW_SIG' WHERE old_coin_pub='$COIN_PUB'" | psql -Aqt $DB
714
715run_audit
716
717echo -n "Testing inconsistency detection... "
718
719OP=`jq -er .bad_sig_losses[0].operation < test-audit.json`
720if test x$OP != xmelt
721then
722 exit_fail "Operation wrong, got $OP"
723fi
724
725LOSS=`jq -er .bad_sig_losses[0].loss < test-audit.json`
726TOTAL_LOSS=`jq -e .total_bad_sig_loss < test-audit.json`
727if test x$LOSS != x$TOTAL_LOSS
728then
729 exit_fail "Loss inconsistent, got $LOSS and $TOTAL_LOSS"
730fi
731if test x$TOTAL_LOSS = TESTKUDOS:0
732then
733 exit_fail "Loss zero"
734fi
735
736echo PASS
737
738# cannot easily undo DELETE, hence full reload
739echo -n "Reloading database ..."
740full_reload
741echo "DONE"
742}
743
744
673# FIXME: Test for wire fee disagreement 745# FIXME: Test for wire fee disagreement
674test_98() { 746test_98() {
675 747