diff options
Diffstat (limited to 'src/auditor/test-auditor.sh')
-rwxr-xr-x | src/auditor/test-auditor.sh | 106 |
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: |
12 | ALL_TESTS=`seq 0 11` | 12 | ALL_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 | |||
95 | echo "Checking output" | 95 | echo "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 |
97 | echo -n "Test for emergencies... " | 97 | echo -n "Test for emergencies... " |
98 | jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo OK | 98 | jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS |
99 | echo -n "Test for emergencies by count... " | 99 | echo -n "Test for emergencies by count... " |
100 | jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo OK | 100 | jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS |
101 | 101 | ||
102 | echo -n "Test for wire inconsistencies... " | 102 | echo -n "Test for wire inconsistencies... " |
103 | jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" | 103 | jq -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 | ||
114 | echo OK | 114 | echo PASS |
115 | 115 | ||
116 | echo -n "Test for wire amounts... " | 116 | echo -n "Test for wire amounts... " |
117 | WIRED=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` | 117 | WIRED=`jq -r .total_wire_in_delta_plus < test-wire-audit.json` |
@@ -161,9 +161,9 @@ run_audit | |||
161 | echo "Checking output" | 161 | echo "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 |
163 | echo -n "Test for emergencies... " | 163 | echo -n "Test for emergencies... " |
164 | jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo OK | 164 | jq -e .emergencies[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS |
165 | echo -n "Test for emergencies by count... " | 165 | echo -n "Test for emergencies by count... " |
166 | jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo OK | 166 | jq -e .emergencies_by_count[0] < test-audit.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS |
167 | 167 | ||
168 | echo -n "Test for wire inconsistencies... " | 168 | echo -n "Test for wire inconsistencies... " |
169 | jq -e .wire_out_amount_inconsistencies[0] < test-wire-audit.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" | 169 | jq -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 | ||
180 | echo OK | 180 | echo 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 | ||
221 | run_audit | 221 | run_audit |
222 | 222 | ||
223 | echo -n "Test for inconsistency detection... " | 223 | echo -n "Testing inconsistency detection... " |
224 | ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-wire-audit.json` | 224 | ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-wire-audit.json` |
225 | if test $ROW != 1 | 225 | if test $ROW != 1 |
226 | then | 226 | then |
@@ -247,7 +247,7 @@ if test $DELTA != "TESTKUDOS:5" | |||
247 | then | 247 | then |
248 | exit_fail "Expected total wire delta plus wrong, got $DELTA" | 248 | exit_fail "Expected total wire delta plus wrong, got $DELTA" |
249 | fi | 249 | fi |
250 | echo OK | 250 | echo PASS |
251 | 251 | ||
252 | # Undo database modification | 252 | # Undo database modification |
253 | echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt $DB | 253 | echo "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 | ||
505 | run_audit | 505 | run_audit |
506 | 506 | ||
507 | echo -n "Test for inconsistency detection... " | 507 | echo -n "Testing inconsistency detection... " |
508 | DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-wire-audit.json` | 508 | DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-wire-audit.json` |
509 | if test "x$DIAG" != "xwire subject does not match" | 509 | if test "x$DIAG" != "xwire subject does not match" |
510 | then | 510 | then |
@@ -554,7 +554,7 @@ if test $DELTA != "TESTKUDOS:10" | |||
554 | then | 554 | then |
555 | exit_fail "Expected total wire delta plus wrong, got $DELTA" | 555 | exit_fail "Expected total wire delta plus wrong, got $DELTA" |
556 | fi | 556 | fi |
557 | echo OK | 557 | echo PASS |
558 | 558 | ||
559 | # Undo database modification | 559 | # Undo database modification |
560 | echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB | 560 | echo "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 | ||
574 | run_audit | 574 | run_audit |
575 | 575 | ||
576 | echo -n "Test for inconsistency detection... " | 576 | echo -n "Testing inconsistency detection... " |
577 | AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-wire-audit.json` | 577 | AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-wire-audit.json` |
578 | if test "x$AMOUNT" != "xTESTKUDOS:10" | 578 | if test "x$AMOUNT" != "xTESTKUDOS:10" |
579 | then | 579 | then |
@@ -584,7 +584,7 @@ if test "x$AMOUNT" != "xTESTKUDOS:10" | |||
584 | then | 584 | then |
585 | exit_fail "Reported total amount wrong: $AMOUNT" | 585 | exit_fail "Reported total amount wrong: $AMOUNT" |
586 | fi | 586 | fi |
587 | echo OK | 587 | echo PASS |
588 | 588 | ||
589 | # Undo database modification | 589 | # Undo database modification |
590 | echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC;" | psql -Aqt $DB | 590 | echo "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 | ||
603 | run_audit | 603 | run_audit |
604 | 604 | ||
605 | echo -n "Test for inconsistency detection... " | 605 | echo -n "Testing inconsistency detection... " |
606 | DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json` | 606 | DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json` |
607 | if test "x$DIAG" != "xexecution date missmatch" | 607 | if test "x$DIAG" != "xexecution date missmatch" |
608 | then | 608 | then |
@@ -613,7 +613,7 @@ if test "x$TABLE" != "xreserves_in" | |||
613 | then | 613 | then |
614 | exit_fail "Reported table wrong: $TABLE" | 614 | exit_fail "Reported table wrong: $TABLE" |
615 | fi | 615 | fi |
616 | echo OK | 616 | echo PASS |
617 | 617 | ||
618 | # Undo database modification | 618 | # Undo database modification |
619 | echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql -Aqt $DB | 619 | echo "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 | ||
637 | run_audit | 637 | run_audit |
638 | 638 | ||
639 | echo -n "Test for inconsistency detection... " | 639 | echo -n "Testing inconsistency detection... " |
640 | AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` | 640 | AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` |
641 | if test "x$AMOUNT" != "xTESTKUDOS:10" | 641 | if test "x$AMOUNT" != "xTESTKUDOS:10" |
642 | then | 642 | then |
@@ -662,7 +662,7 @@ if test "x$DIAG" != "xjustification for wire transfer not found" | |||
662 | then | 662 | then |
663 | exit_fail "Reported diagnostic wrong: $DIAG" | 663 | exit_fail "Reported diagnostic wrong: $DIAG" |
664 | fi | 664 | fi |
665 | echo OK | 665 | echo PASS |
666 | 666 | ||
667 | # Undo database modification (exchange always has account #2) | 667 | # Undo database modification (exchange always has account #2) |
668 | echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id=2 WHERE id=$OLD_ID;" | psql -Aqt $DB | 668 | echo "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. | ||
675 | test_12() { | ||
676 | |||
677 | echo "===========12: incomplete refresh ===========" | ||
678 | OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt` | ||
679 | |||
680 | run_audit | ||
681 | |||
682 | echo -n "Testing hung refresh detection... " | ||
683 | |||
684 | HANG=`jq -er .refresh_hanging[0].amount < test-audit.json` | ||
685 | TOTAL_HANG=`jq -e .total_refresh_hanging < test-audit.json` | ||
686 | if test x$HANG != x$TOTAL_HANG | ||
687 | then | ||
688 | exit_fail "Hanging amount inconsistent, got $HANG and $TOTAL_HANG" | ||
689 | fi | ||
690 | if test x$TOTAL_HANG = TESTKUDOS:0 | ||
691 | then | ||
692 | exit_fail "Hanging amount zero" | ||
693 | fi | ||
694 | |||
695 | echo PASS | ||
696 | |||
697 | |||
698 | # cannot easily undo DELETE, hence full reload | ||
699 | echo -n "Reloading database ..." | ||
700 | full_reload | ||
701 | echo "DONE" | ||
702 | } | ||
703 | |||
704 | |||
705 | # Test for wrong signature on refresh. | ||
706 | test_13() { | ||
707 | |||
708 | echo "===========13: wrong melt signature ===========" | ||
709 | # Modify denom_sig, so it is wrong | ||
710 | COIN_PUB=`echo "SELECT old_coin_pub FROM refresh_commitments LIMIT 1;" | psql $DB -Aqt` | ||
711 | OLD_SIG=`echo "SELECT old_coin_sig FROM refresh_commitments WHERE old_coin_pub='$COIN_PUB';" | psql $DB -Aqt` | ||
712 | NEW_SIG="\xba588af7c13c477dca1ac458f65cc484db8fba53b969b873f4353ecbd815e6b4c03f42c0cb63a2b609c2d726e612fd8e0c084906a41f409b6a23a08a83c89a02" | ||
713 | echo "UPDATE refresh_commitments SET old_coin_sig='$NEW_SIG' WHERE old_coin_pub='$COIN_PUB'" | psql -Aqt $DB | ||
714 | |||
715 | run_audit | ||
716 | |||
717 | echo -n "Testing inconsistency detection... " | ||
718 | |||
719 | OP=`jq -er .bad_sig_losses[0].operation < test-audit.json` | ||
720 | if test x$OP != xmelt | ||
721 | then | ||
722 | exit_fail "Operation wrong, got $OP" | ||
723 | fi | ||
724 | |||
725 | LOSS=`jq -er .bad_sig_losses[0].loss < test-audit.json` | ||
726 | TOTAL_LOSS=`jq -e .total_bad_sig_loss < test-audit.json` | ||
727 | if test x$LOSS != x$TOTAL_LOSS | ||
728 | then | ||
729 | exit_fail "Loss inconsistent, got $LOSS and $TOTAL_LOSS" | ||
730 | fi | ||
731 | if test x$TOTAL_LOSS = TESTKUDOS:0 | ||
732 | then | ||
733 | exit_fail "Loss zero" | ||
734 | fi | ||
735 | |||
736 | echo PASS | ||
737 | |||
738 | # cannot easily undo DELETE, hence full reload | ||
739 | echo -n "Reloading database ..." | ||
740 | full_reload | ||
741 | echo "DONE" | ||
742 | } | ||
743 | |||
744 | |||
673 | # FIXME: Test for wire fee disagreement | 745 | # FIXME: Test for wire fee disagreement |
674 | test_98() { | 746 | test_98() { |
675 | 747 | ||