2020-03-24 18:16:01 +01:00
|
|
|
#!/bin/bash
|
2020-03-26 17:21:41 +01:00
|
|
|
# Setup database which was generated from a exchange-wallet interaction
|
|
|
|
# with revocations and run the auditor against it.
|
2020-03-24 18:16:01 +01:00
|
|
|
#
|
2020-03-26 17:21:41 +01:00
|
|
|
# Check that the auditor report is as expected.
|
2020-03-24 18:16:01 +01:00
|
|
|
#
|
2020-03-26 17:21:41 +01:00
|
|
|
# Requires 'jq' tool and Postgres superuser rights!
|
2020-03-24 18:16:01 +01:00
|
|
|
set -eu
|
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Set of numbers for all the testcases.
|
|
|
|
# When adding new tests, increase the last number:
|
2020-03-27 09:35:48 +01:00
|
|
|
ALL_TESTS=`seq 0 4`
|
2020-03-26 17:21:41 +01:00
|
|
|
|
|
|
|
# $TESTS determines which tests we should run.
|
|
|
|
# This construction is used to make it easy to
|
|
|
|
# only run a subset of the tests. To only run a subset,
|
|
|
|
# pass the numbers of the tests to run as the FIRST
|
|
|
|
# argument to test-auditor.sh, i.e.:
|
|
|
|
#
|
|
|
|
# $ test-revocation.sh "1 3"
|
|
|
|
#
|
|
|
|
# to run tests 1 and 3 only. By default, all tests are run.
|
|
|
|
#
|
|
|
|
TESTS=${1:-$ALL_TESTS}
|
|
|
|
|
|
|
|
# Global variable to run the auditor processes under valgrind
|
|
|
|
# VALGRIND=valgrind
|
|
|
|
VALGRIND=""
|
|
|
|
|
2020-03-24 18:16:01 +01:00
|
|
|
# Exit, with status code "skip" (no 'real' failure)
|
|
|
|
function exit_skip() {
|
|
|
|
echo $1
|
|
|
|
exit 77
|
|
|
|
}
|
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Exit, with error message (hard failure)
|
|
|
|
function exit_fail() {
|
|
|
|
echo $1
|
2020-08-19 18:03:45 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cleanup to run whenever we exit
|
|
|
|
function cleanup()
|
|
|
|
{
|
2020-08-28 18:01:50 +02:00
|
|
|
for n in `jobs -p`
|
|
|
|
do
|
|
|
|
kill $n 2> /dev/null || true
|
|
|
|
done
|
2020-03-26 17:21:41 +01:00
|
|
|
wait
|
2022-08-06 13:25:54 +02:00
|
|
|
# kill euFin
|
|
|
|
echo Killing euFin..
|
|
|
|
kill `cat libeufin-sandbox.pid 2> /dev/null` &> /dev/null || true
|
|
|
|
kill `cat libeufin-nexus.pid 2> /dev/null` &> /dev/null || true
|
|
|
|
# So far only Sandbox gave exit issues / delays ..
|
|
|
|
count=0
|
|
|
|
while ps xo pid | grep `cat libeufin-sandbox.pid`; do
|
2022-09-09 22:26:11 +02:00
|
|
|
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`
|
2022-08-06 13:25:54 +02:00
|
|
|
done
|
2020-03-26 17:21:41 +01:00
|
|
|
}
|
|
|
|
|
2020-08-19 18:03:45 +02:00
|
|
|
# Install cleanup handler (except for kill -9)
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2022-08-06 13:25:54 +02:00
|
|
|
# Downloads new transactions from the bank.
|
|
|
|
function nexus_fetch_transactions () {
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2022-08-06 13:25:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Instruct Nexus to all the prepared payments (= those
|
|
|
|
# POSTed to /transfer by the exchange).
|
|
|
|
function nexus_submit_to_sandbox () {
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2022-08-06 13:25:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_payto_uri() {
|
|
|
|
export LIBEUFIN_SANDBOX_USERNAME=$1
|
|
|
|
export LIBEUFIN_SANDBOX_PASSWORD=$2
|
|
|
|
export LIBEUFIN_SANDBOX_URL=http://localhost:18082/demobanks/default
|
|
|
|
libeufin-cli sandbox demobank info --bank-account $1 | jq --raw-output '.paytoUri'
|
|
|
|
}
|
|
|
|
|
|
|
|
function launch_libeufin () {
|
|
|
|
export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$DB.sqlite3"
|
|
|
|
libeufin-nexus serve --port 8082 \
|
2022-09-09 22:26:11 +02:00
|
|
|
2> libeufin-nexus-stderr.log \
|
|
|
|
> libeufin-nexus-stdout.log &
|
2022-08-06 13:25:54 +02:00
|
|
|
echo $! > libeufin-nexus.pid
|
|
|
|
export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$DB.sqlite3"
|
|
|
|
export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret
|
|
|
|
libeufin-sandbox serve --port 18082 \
|
2022-09-09 22:26:11 +02:00
|
|
|
> libeufin-sandbox-stdout.log \
|
|
|
|
2> libeufin-sandbox-stderr.log &
|
2022-08-06 13:25:54 +02:00
|
|
|
echo $! > libeufin-sandbox.pid
|
|
|
|
}
|
2020-03-26 17:21:41 +01:00
|
|
|
|
|
|
|
# Operations to run before the actual audit
|
|
|
|
function pre_audit () {
|
|
|
|
# Launch bank
|
|
|
|
echo -n "Launching bank "
|
2022-08-06 13:25:54 +02:00
|
|
|
EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
|
|
|
|
launch_libeufin
|
|
|
|
for n in `seq 1 80`
|
|
|
|
do
|
|
|
|
echo -n "."
|
|
|
|
sleep 0.1
|
|
|
|
OK=1
|
|
|
|
wget http://localhost:18082/ -o /dev/null -O /dev/null >/dev/null && break
|
|
|
|
OK=0
|
|
|
|
done
|
|
|
|
if [ 1 != $OK ]
|
|
|
|
then
|
|
|
|
exit_skip "Failed to launch Sandbox"
|
|
|
|
fi
|
2020-09-12 12:08:00 +02:00
|
|
|
for n in `seq 1 80`
|
2020-03-26 17:21:41 +01:00
|
|
|
do
|
|
|
|
echo -n "."
|
|
|
|
sleep 0.1
|
|
|
|
OK=1
|
|
|
|
wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null && break
|
|
|
|
OK=0
|
|
|
|
done
|
|
|
|
if [ 1 != $OK ]
|
|
|
|
then
|
2022-08-06 13:25:54 +02:00
|
|
|
exit_skip "Failed to launch Nexus"
|
2020-03-26 17:21:41 +01:00
|
|
|
fi
|
|
|
|
echo " DONE"
|
|
|
|
if test ${1:-no} = "aggregator"
|
|
|
|
then
|
2022-03-18 08:54:08 +01:00
|
|
|
export CONF
|
2022-09-09 22:26:11 +02:00
|
|
|
echo -n "Running exchange aggregator ... (config: $CONF)"
|
2022-03-18 08:54:08 +01:00
|
|
|
taler-exchange-aggregator -L INFO -t -c $CONF -y 2> aggregator.log || exit_fail "FAIL"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo " DONE"
|
|
|
|
echo -n "Running exchange closer ..."
|
|
|
|
taler-exchange-closer -L INFO -t -c $CONF 2> closer.log || exit_fail "FAIL"
|
|
|
|
echo " DONE"
|
|
|
|
echo -n "Running exchange transfer ..."
|
|
|
|
taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL"
|
|
|
|
echo " DONE"
|
2022-09-09 22:26:11 +02:00
|
|
|
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"
|
2020-03-26 17:21:41 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# actual audit run
|
|
|
|
function audit_only () {
|
|
|
|
# Run the auditor!
|
2022-08-06 13:25:54 +02:00
|
|
|
echo -n "Running audit(s) ... (conf is $CONF)"
|
2020-03-26 17:21:41 +01:00
|
|
|
|
|
|
|
# Restart so that first run is always fresh, and second one is incremental
|
|
|
|
taler-auditor-dbinit -r -c $CONF
|
|
|
|
$VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> test-audit-aggregation.log || exit_fail "aggregation audit failed"
|
2020-03-26 16:07:34 +01:00
|
|
|
echo -n "."
|
2020-03-26 17:21:41 +01:00
|
|
|
$VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed"
|
2020-03-24 18:16:01 +01:00
|
|
|
echo -n "."
|
2020-03-26 17:21:41 +01:00
|
|
|
$VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> test-audit-coins.log || exit_fail "coin audit failed"
|
|
|
|
echo -n "."
|
|
|
|
$VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> test-audit-coins-inc.log || exit_fail "incremental coin audit failed"
|
|
|
|
echo -n "."
|
|
|
|
$VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> test-audit-deposits.log || exit_fail "deposits audit failed"
|
|
|
|
echo -n "."
|
|
|
|
$VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed"
|
|
|
|
echo -n "."
|
2021-01-07 22:24:19 +01:00
|
|
|
$VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> test-audit-reserves.log || exit_fail "reserves audit failed"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "."
|
2021-01-07 22:24:19 +01:00
|
|
|
$VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "."
|
2021-01-07 22:24:19 +01:00
|
|
|
$VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> test-wire-audit.log || exit_fail "wire audit failed"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "."
|
2021-01-07 22:24:19 +01:00
|
|
|
$VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> test-wire-audit-inc.log || exit_fail "wire audit failed"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "."
|
|
|
|
|
|
|
|
echo " DONE"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Cleanup to run after the auditor
|
|
|
|
function post_audit () {
|
2021-09-27 11:32:54 +02:00
|
|
|
echo -n "Cleanup ..."
|
2020-08-28 18:01:50 +02:00
|
|
|
cleanup
|
2021-09-27 11:32:54 +02:00
|
|
|
echo " DONE"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "TeXing ."
|
|
|
|
taler-helper-auditor-render.py test-audit-aggregation.json test-audit-coins.json test-audit-deposits.json test-audit-reserves.json test-audit-wire.json < ../../contrib/auditor-report.tex.j2 > test-report.tex || exit_fail "Renderer failed"
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
echo -n "."
|
|
|
|
timeout 10 pdflatex test-report.tex >/dev/null || exit_fail "pdflatex failed"
|
|
|
|
echo -n "."
|
|
|
|
timeout 10 pdflatex test-report.tex >/dev/null
|
|
|
|
echo " DONE"
|
|
|
|
}
|
2020-03-24 18:23:08 +01:00
|
|
|
|
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Run audit process on current database, including report
|
|
|
|
# generation. Pass "aggregator" as $1 to run
|
|
|
|
# $ taler-exchange-aggregator
|
|
|
|
# before auditor (to trigger pending wire transfers).
|
|
|
|
function run_audit () {
|
|
|
|
pre_audit ${1:-no}
|
|
|
|
audit_only
|
|
|
|
post_audit
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
}
|
2020-03-24 18:16:01 +01:00
|
|
|
|
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Do a full reload of the (original) database
|
|
|
|
full_reload()
|
|
|
|
{
|
|
|
|
echo -n "Doing full reload of the database... "
|
|
|
|
dropdb $DB 2> /dev/null || true
|
2022-08-06 13:25:54 +02:00
|
|
|
rm -f $DB.sqlite3 || true # libeufin
|
2020-03-26 17:21:41 +01:00
|
|
|
createdb -T template0 $DB || exit_skip "could not create database"
|
|
|
|
# Import pre-generated database, -q(ietly) using single (-1) transaction
|
|
|
|
psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database"
|
2022-08-06 13:25:54 +02:00
|
|
|
sqlite3 $DB.sqlite3 < ${BASEDB}-libeufin.sql || exit_skip "Failed to load libEufin database"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo "DONE"
|
2022-08-06 13:25:54 +02:00
|
|
|
# Exchange payto URI contains the (dynamically generated)
|
|
|
|
# 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 || (
|
2022-09-09 22:26:11 +02:00
|
|
|
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"
|
2022-08-06 13:25:54 +02:00
|
|
|
)
|
2020-03-26 17:21:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function test_0() {
|
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "===========0: normal run with aggregator==========="
|
|
|
|
run_audit aggregator
|
2020-03-26 17:21:41 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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"
|
2020-03-24 18:16:01 +01:00
|
|
|
|
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# 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)
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo PASS
|
2020-03-26 17:21:41 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# cannot easily undo aggregator, hence full reload
|
|
|
|
full_reload
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
}
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Run without aggregator, hence auditor should detect wire
|
|
|
|
# transfer lag!
|
|
|
|
function test_1() {
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "===========1: normal run==========="
|
|
|
|
run_audit
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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"
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# 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)
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo PASS
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# Database was unmodified, no need to undo
|
|
|
|
echo "OK"
|
2020-03-26 17:21:41 +01:00
|
|
|
}
|
2020-03-26 16:07:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-27 09:35:48 +01:00
|
|
|
# Change recoup amount
|
|
|
|
function test_2() {
|
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "===========2: recoup amount inconsistency==========="
|
|
|
|
echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt $DB
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
run_audit
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# 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
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# Undo database modification
|
|
|
|
echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB
|
2020-03-27 09:35:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Change recoup-refresh amount
|
|
|
|
function test_3() {
|
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "===========3: recoup-refresh amount inconsistency==========="
|
|
|
|
echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
run_audit
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# Undo database modification
|
|
|
|
echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB
|
2020-03-27 09:35:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Void recoup-refresh entry by 'unrevoking' denomination
|
|
|
|
function test_4() {
|
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "===========4: invalid recoup==========="
|
|
|
|
echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt $DB
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
run_audit
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-27 09:35:48 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
# Undo database modification (can't easily undo DELETE, so full reload)
|
|
|
|
full_reload
|
2020-03-27 09:35:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-26 16:07:34 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# *************** Main test loop starts here **************
|
|
|
|
|
|
|
|
|
|
|
|
# Run all the tests against the database given in $1.
|
|
|
|
# Sets $fail to 0 on success, non-zero on failure.
|
|
|
|
check_with_database()
|
|
|
|
{
|
|
|
|
BASEDB=$1
|
|
|
|
echo "Running test suite with database $BASEDB using configuration $CONF"
|
|
|
|
|
|
|
|
# Setup database-specific globals
|
|
|
|
MASTER_PUB=`cat ${BASEDB}.mpub`
|
|
|
|
|
|
|
|
# Load database
|
|
|
|
full_reload
|
|
|
|
# Run test suite
|
|
|
|
fail=0
|
|
|
|
for i in $TESTS
|
|
|
|
do
|
|
|
|
test_$i
|
|
|
|
if test 0 != $fail
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# echo "Cleanup (disabled, leaving database $DB behind)"
|
|
|
|
dropdb $DB
|
|
|
|
rm -f test-audit.log test-wire-audit.log
|
|
|
|
}
|
2020-03-26 16:07:34 +01:00
|
|
|
|
|
|
|
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# *************** Main logic starts here **************
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# ####### Setup globals ######
|
2022-02-28 20:37:19 +01:00
|
|
|
# Postgres database to use (must match revoke-basedb.conf)
|
2020-03-26 17:21:41 +01:00
|
|
|
DB=taler-auditor-test
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# Configuration file to use
|
2022-02-28 20:37:19 +01:00
|
|
|
CONF=revoke-basedb.conf
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2020-03-26 17:21:41 +01:00
|
|
|
# test required commands exist
|
|
|
|
echo "Testing for jq"
|
|
|
|
jq -h > /dev/null || exit_skip "jq required"
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "Testing for faketime"
|
|
|
|
faketime -h > /dev/null || exit_skip "faketime required"
|
2022-08-06 13:25:54 +02:00
|
|
|
echo "Testing for libeufin(-cli)"
|
|
|
|
libeufin-cli --help >/dev/null </dev/null || exit_skip "libeufin required"
|
2020-03-26 17:21:41 +01:00
|
|
|
echo "Testing for pdflatex"
|
|
|
|
which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2022-09-11 07:44:14 +02:00
|
|
|
echo "Testing for taler-wallet-cli"
|
2022-09-09 22:26:11 +02:00
|
|
|
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
|
2020-03-26 17:21:41 +01:00
|
|
|
then
|
2022-09-09 22:26:11 +02:00
|
|
|
check_with_database $MYDIR/basedb
|
|
|
|
if test x$fail != x0
|
2020-03-26 17:21:41 +01:00
|
|
|
then
|
2022-09-09 22:26:11 +02:00
|
|
|
exit $fail
|
2020-03-26 17:21:41 +01:00
|
|
|
else
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "Cleaning up $MYDIR..."
|
|
|
|
rm -rf $MYDIR || echo "Removing $MYDIR failed"
|
2020-03-26 17:21:41 +01:00
|
|
|
fi
|
2020-05-01 19:48:11 +02:00
|
|
|
else
|
2022-09-09 22:26:11 +02:00
|
|
|
echo "Generation failed"
|
2020-05-01 19:48:11 +02:00
|
|
|
fi
|
2020-03-24 18:16:01 +01:00
|
|
|
|
2022-09-09 22:26:11 +02:00
|
|
|
exit 0
|