diff options
Diffstat (limited to 'src/auditor/test-revocation.sh')
| -rwxr-xr-x | src/auditor/test-revocation.sh | 562 | 
1 files changed, 269 insertions, 293 deletions
diff --git a/src/auditor/test-revocation.sh b/src/auditor/test-revocation.sh index 5aea5c78..f0224ca6 100755 --- a/src/auditor/test-revocation.sh +++ b/src/auditor/test-revocation.sh @@ -54,13 +54,13 @@ function cleanup()      # So far only Sandbox gave exit issues / delays ..      count=0      while ps xo pid | grep `cat libeufin-sandbox.pid`; do -      if test $count = 5; then -        echo "Sandbox unkillable, failing now .." -	exit 1 -      fi -      echo "Sandbox didn't exit yet.." -      sleep 1; -      count=`expr $count + 1` +        if test $count = 5; then +            echo "Sandbox unkillable, failing now .." +	        exit 1 +        fi +        echo "Sandbox didn't exit yet.." +        sleep 1; +        count=`expr $count + 1`      done  } @@ -69,26 +69,26 @@ trap cleanup EXIT  # Downloads new transactions from the bank.  function nexus_fetch_transactions () { -  export LIBEUFIN_NEXUS_USERNAME=exchange -  export LIBEUFIN_NEXUS_PASSWORD=x -  export LIBEUFIN_NEXUS_URL=http://localhost:8082/ -  libeufin-cli accounts fetch-transactions \ -    --range-type since-last --level report exchange-nexus > /dev/null -  unset LIBEUFIN_NEXUS_USERNAME -  unset LIBEUFIN_NEXUS_PASSWORD -  unset LIBEUFIN_NEXUS_URL +    export LIBEUFIN_NEXUS_USERNAME=exchange +    export LIBEUFIN_NEXUS_PASSWORD=x +    export LIBEUFIN_NEXUS_URL=http://localhost:8082/ +    libeufin-cli accounts fetch-transactions \ +                 --range-type since-last --level report exchange-nexus > /dev/null +    unset LIBEUFIN_NEXUS_USERNAME +    unset LIBEUFIN_NEXUS_PASSWORD +    unset LIBEUFIN_NEXUS_URL  }  # Instruct Nexus to all the prepared payments (= those  # POSTed to /transfer by the exchange).  function nexus_submit_to_sandbox () { -  export LIBEUFIN_NEXUS_USERNAME=exchange -  export LIBEUFIN_NEXUS_PASSWORD=x -  export LIBEUFIN_NEXUS_URL=http://localhost:8082/ -  libeufin-cli accounts submit-payments exchange-nexus -  unset LIBEUFIN_NEXUS_USERNAME -  unset LIBEUFIN_NEXUS_PASSWORD -  unset LIBEUFIN_NEXUS_URL +    export LIBEUFIN_NEXUS_USERNAME=exchange +    export LIBEUFIN_NEXUS_PASSWORD=x +    export LIBEUFIN_NEXUS_URL=http://localhost:8082/ +    libeufin-cli accounts submit-payments exchange-nexus +    unset LIBEUFIN_NEXUS_USERNAME +    unset LIBEUFIN_NEXUS_PASSWORD +    unset LIBEUFIN_NEXUS_URL  }  function get_payto_uri() { @@ -101,14 +101,14 @@ function get_payto_uri() {  function launch_libeufin () {      export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$DB.sqlite3"      libeufin-nexus serve --port 8082 \ -      2> libeufin-nexus-stderr.log \ -      > libeufin-nexus-stdout.log & +                   2> libeufin-nexus-stderr.log \ +                   > libeufin-nexus-stdout.log &      echo $! > libeufin-nexus.pid      export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$DB.sqlite3"      export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret      libeufin-sandbox serve --port 18082 \ -      > libeufin-sandbox-stdout.log \ -      2> libeufin-sandbox-stderr.log & +                     > libeufin-sandbox-stdout.log \ +                     2> libeufin-sandbox-stderr.log &      echo $! > libeufin-sandbox.pid  } @@ -146,7 +146,7 @@ function pre_audit () {      if test ${1:-no} = "aggregator"      then          export CONF -	echo -n "Running exchange aggregator ... (config: $CONF)" +	    echo -n "Running exchange aggregator ... (config: $CONF)"          taler-exchange-aggregator -L INFO -t -c $CONF -y 2> aggregator.log || exit_fail "FAIL"          echo " DONE"          echo -n "Running exchange closer ..." @@ -155,13 +155,13 @@ function pre_audit () {          echo -n "Running exchange transfer ..."          taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL"          echo " DONE" -	echo -n "Running Nexus payment submitter ..." -	nexus_submit_to_sandbox -	echo " DONE" -	# Make outgoing transactions appear in the TWG: -	echo -n "Download bank transactions ..." -	nexus_fetch_transactions -	echo " DONE" +	    echo -n "Running Nexus payment submitter ..." +	    nexus_submit_to_sandbox +	    echo " DONE" +	    # Make outgoing transactions appear in the TWG: +	    echo -n "Download bank transactions ..." +	    nexus_fetch_transactions +	    echo " DONE"      fi  } @@ -240,132 +240,132 @@ full_reload()      # IBAN, that can only be written in CONF after libeufin is      # setup.      taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI &> /dev/null || ( -    echo -n "Specifying exchange payto URI in the configuration ($CONF) (grab IBAN from $DB.sqlite3)..."; -      EXCHANGE_IBAN=`echo "SELECT iban FROM BankAccounts WHERE label='exchange'" | sqlite3 $DB.sqlite3`; -      taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI \ -        -V "payto://iban/SANDBOXX/$EXCHANGE_IBAN?receiver-name=Exchange+Company" -      echo " DONE" +        echo -n "Specifying exchange payto URI in the configuration ($CONF) (grab IBAN from $DB.sqlite3)..."; +        EXCHANGE_IBAN=`echo "SELECT iban FROM BankAccounts WHERE label='exchange'" | sqlite3 $DB.sqlite3`; +        taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI \ +                     -V "payto://iban/SANDBOXX/$EXCHANGE_IBAN?receiver-name=Exchange+Company" +        echo " DONE"      )  }  function test_0() { -echo "===========0: normal run with aggregator===========" -run_audit aggregator +    echo "===========0: normal run with aggregator===========" +    run_audit aggregator -echo "Checking output" -# if an emergency was detected, that is a bug and we should fail -echo -n "Test for emergencies... " -jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS -echo -n "Test for deposit confirmation emergencies... " -jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS -echo -n "Test for emergencies by count... " -jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS +    echo "Checking output" +    # if an emergency was detected, that is a bug and we should fail +    echo -n "Test for emergencies... " +    jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS +    echo -n "Test for deposit confirmation emergencies... " +    jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS +    echo -n "Test for emergencies by count... " +    jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS -echo -n "Test for wire inconsistencies... " -jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" -jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" -jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run" -jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" -jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run" -jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" -jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run" -jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" +    echo -n "Test for wire inconsistencies... " +    jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" +    jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" +    jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run" +    jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" +    jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run" +    jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" +    jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run" +    jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" -# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic) -# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic) +    # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic) +    # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic) -echo PASS +    echo PASS -LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS" -fi -LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS" -fi -LOSS=`jq -r .total_bad_sig_loss < test-audit-reserves.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS" -fi +    LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS" +    fi +    LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS" +    fi +    LOSS=`jq -r .total_bad_sig_loss < test-audit-reserves.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS" +    fi -echo -n "Test for wire amounts... " -WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta plus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta minus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta plus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta minus wrong, got $WIRED" -fi -WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total misattribution in wrong, got $WIRED" -fi -echo PASS +    echo -n "Test for wire amounts... " +    WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta plus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta minus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta plus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta minus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total misattribution in wrong, got $WIRED" +    fi +    echo PASS -echo -n "Checking for unexpected arithmetic differences " -LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS" -fi -LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS" -fi -LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS" -fi -LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS" -fi -LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-reserves.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS" -fi -LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-reserves.json` -if test $LOSS != "TESTKUDOS:0" -then -    exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS" -fi +    echo -n "Checking for unexpected arithmetic differences " +    LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS" +    fi +    LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS" +    fi +    LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS" +    fi +    LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS" +    fi +    LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-reserves.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS" +    fi +    LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-reserves.json` +    if test $LOSS != "TESTKUDOS:0" +    then +        exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS" +    fi -jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run" -jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run" -jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run" -echo PASS +    jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run" +    jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run" +    jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run" +    echo PASS -echo -n "Checking for unexpected wire out differences " -jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run" -echo PASS +    echo -n "Checking for unexpected wire out differences " +    jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run" +    echo PASS -# cannot easily undo aggregator, hence full reload -full_reload +    # cannot easily undo aggregator, hence full reload +    full_reload  } @@ -374,58 +374,58 @@ full_reload  # transfer lag!  function test_1() { -echo "===========1: normal run===========" -run_audit +    echo "===========1: normal run===========" +    run_audit -echo "Checking output" -# if an emergency was detected, that is a bug and we should fail -echo -n "Test for emergencies... " -jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS -echo -n "Test for emergencies by count... " -jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS +    echo "Checking output" +    # if an emergency was detected, that is a bug and we should fail +    echo -n "Test for emergencies... " +    jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS +    echo -n "Test for emergencies by count... " +    jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS -echo -n "Test for wire inconsistencies... " -jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" -jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" -jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run" -jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" -jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" -jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" +    echo -n "Test for wire inconsistencies... " +    jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run" +    jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run" +    jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run" +    jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run" +    jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run" +    jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run" -# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic) -# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic) +    # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic) +    # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic) -echo PASS +    echo PASS -echo -n "Test for wire amounts... " -WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta plus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta minus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta plus wrong, got $WIRED" -fi -WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total wire delta minus wrong, got $WIRED" -fi -WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` -if test $WIRED != "TESTKUDOS:0" -then -    exit_fail "Expected total misattribution in wrong, got $WIRED" -fi +    echo -n "Test for wire amounts... " +    WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta plus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta minus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta plus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total wire delta minus wrong, got $WIRED" +    fi +    WIRED=`jq -r .total_misattribution_in < test-audit-wire.json` +    if test $WIRED != "TESTKUDOS:0" +    then +        exit_fail "Expected total misattribution in wrong, got $WIRED" +    fi -# Database was unmodified, no need to undo -echo "OK" +    # Database was unmodified, no need to undo +    echo "OK"  } @@ -433,38 +433,38 @@ echo "OK"  # Change recoup amount  function test_2() { -echo "===========2: recoup amount inconsistency===========" -echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt $DB +    echo "===========2: recoup amount inconsistency===========" +    echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt $DB -run_audit +    run_audit -# Reserve balance is now wrong -echo -n "Testing inconsistency detection... " -AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json` -if test $AMOUNT != "TESTKUDOS:3" -then -    exit_fail "Reserve auditor amount $AMOUNT is wrong" -fi -AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json` -if test $AMOUNT != "TESTKUDOS:0" -then -    exit_fail "Reserve exchange amount $AMOUNT is wrong" -fi -# Coin spent exceeded coin's value -AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json` -if test $AMOUNT != "TESTKUDOS:2" -then -    exit_fail "Coin auditor amount $AMOUNT is wrong" -fi -AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json` -if test $AMOUNT != "TESTKUDOS:5" -then -    exit_fail "Coin exchange amount $AMOUNT is wrong" -fi -echo OK +    # Reserve balance is now wrong +    echo -n "Testing inconsistency detection... " +    AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json` +    if test $AMOUNT != "TESTKUDOS:3" +    then +        exit_fail "Reserve auditor amount $AMOUNT is wrong" +    fi +    AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json` +    if test $AMOUNT != "TESTKUDOS:0" +    then +        exit_fail "Reserve exchange amount $AMOUNT is wrong" +    fi +    # Coin spent exceeded coin's value +    AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json` +    if test $AMOUNT != "TESTKUDOS:2" +    then +        exit_fail "Coin auditor amount $AMOUNT is wrong" +    fi +    AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json` +    if test $AMOUNT != "TESTKUDOS:5" +    then +        exit_fail "Coin exchange amount $AMOUNT is wrong" +    fi +    echo OK -# Undo database modification -echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB +    # Undo database modification +    echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB  } @@ -472,27 +472,27 @@ echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $  # Change recoup-refresh amount  function test_3() { -echo "===========3: recoup-refresh amount inconsistency===========" -echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB +    echo "===========3: recoup-refresh amount inconsistency===========" +    echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB -run_audit +    run_audit -echo -n "Testing inconsistency detection... " -# Coin spent exceeded coin's value -AMOUNT=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` -if test $AMOUNT != "TESTKUDOS:5" -then -    exit_fail "Arithmetic delta minus amount $AMOUNT is wrong" -fi -AMOUNT=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` -if test $AMOUNT != "TESTKUDOS:0" -then -    exit_fail "Arithmetic delta plus amount $AMOUNT is wrong" -fi -echo OK +    echo -n "Testing inconsistency detection... " +    # Coin spent exceeded coin's value +    AMOUNT=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json` +    if test $AMOUNT != "TESTKUDOS:5" +    then +        exit_fail "Arithmetic delta minus amount $AMOUNT is wrong" +    fi +    AMOUNT=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json` +    if test $AMOUNT != "TESTKUDOS:0" +    then +        exit_fail "Arithmetic delta plus amount $AMOUNT is wrong" +    fi +    echo OK -# Undo database modification -echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB +    # Undo database modification +    echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB  } @@ -500,28 +500,28 @@ echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=  # Void recoup-refresh entry by 'unrevoking' denomination  function test_4() { -echo "===========4: invalid recoup===========" -echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt $DB +    echo "===========4: invalid recoup===========" +    echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt $DB -run_audit +    run_audit -echo -n "Testing inconsistency detection... " -# Coin spent exceeded coin's value -jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad recoup not detected" -AMOUNT=`jq -r .total_bad_sig_losses < test-audit-coins.json` -if test $AMOUNT == "TESTKUDOS:0" -then -    exit_fail "Total bad sig losses are wrong" -fi -TAB=`jq -r .row_inconsistencies[0].table < test-audit-reserves.json` -if test $TAB != "recoup" -then -    exit_fail "Wrong table for row inconsistency, got $TAB" -fi -echo OK +    echo -n "Testing inconsistency detection... " +    # Coin spent exceeded coin's value +    jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad recoup not detected" +    AMOUNT=`jq -r .total_bad_sig_losses < test-audit-coins.json` +    if test $AMOUNT == "TESTKUDOS:0" +    then +        exit_fail "Total bad sig losses are wrong" +    fi +    TAB=`jq -r .row_inconsistencies[0].table < test-audit-reserves.json` +    if test $TAB != "recoup" +    then +        exit_fail "Wrong table for row inconsistency, got $TAB" +    fi +    echo OK -# Undo database modification (can't easily undo DELETE, so full reload) -full_reload +    # Undo database modification (can't easily undo DELETE, so full reload) +    full_reload  } @@ -542,14 +542,6 @@ check_with_database()      # Setup database-specific globals      MASTER_PUB=`cat ${BASEDB}.mpub` -    # Determine database age -    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` -    echo "Database age is ${DATABASE_AGE} seconds" -      # Load database      full_reload      # Run test suite @@ -581,45 +573,29 @@ CONF=revoke-basedb.conf  # test required commands exist  echo "Testing for jq"  jq -h > /dev/null || exit_skip "jq required" +echo "Testing for faketime" +faketime -h > /dev/null || exit_skip "faketime required"  echo "Testing for libeufin(-cli)"  libeufin-cli --help >/dev/null </dev/null || exit_skip "libeufin required"  echo "Testing for pdflatex"  which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required" -# check if we should regenerate the database -if test -n "${1:-}" +echo -n "Testing for taler-wallet-cli" +taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required" +MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` +echo "Generating fresh database at $MYDIR" +if faketime -f '-1 d' ./generate-revoke-basedb.sh $MYDIR/basedb  then -    echo "Custom run, will only run on existing DB." -else -    echo -n "Testing for taler-wallet-cli" -    if taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null +    check_with_database $MYDIR/basedb +    if test x$fail != x0      then -        MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` -        echo " FOUND. Generating fresh database at $MYDIR" -        if ./generate-revoke-basedb.sh $MYDIR/basedb -        then -            check_with_database $MYDIR/basedb -            if test x$fail != x0 -            then -                exit $fail -            else -                echo "Cleaning up $MYDIR..." -                rm -rf $MYDIR || echo "Removing $MYDIR failed" -            fi -        else -            echo "Generation failed, running only on existing DB" -        fi +        exit $fail      else -        echo " NOT FOUND, running only on existing DB" +        echo "Cleaning up $MYDIR..." +        rm -rf $MYDIR || echo "Removing $MYDIR failed"      fi -fi - -# run tests with pre-build database, if one is available -if test -r revoke-basedb.mpub -then -  check_with_database "revoke-basedb"  else -  fail=77 +    echo "Generation failed"  fi -exit $fail +exit 0  | 
