From 38601a1c63840bc85eae166f771a974e0629db28 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 7 May 2020 15:33:43 -0300 Subject: Add test for double spending (still fails as expected) --- integrationtests/common.sh | 6 +++++- integrationtests/test-base.sh | 1 + integrationtests/test-double-link.sh | 5 +---- integrationtests/test-double-spend.sh | 28 ++++++++++++++++++++++++++++ integrationtests/test-recoup.sh | 4 +--- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100755 integrationtests/test-double-spend.sh diff --git a/integrationtests/common.sh b/integrationtests/common.sh index 0104dbc9c..4b42531b8 100644 --- a/integrationtests/common.sh +++ b/integrationtests/common.sh @@ -14,7 +14,6 @@ function setup_config() { [[ "$(taler-merchant-httpd -v)" =~ "taler-merchant-httpd v" ]] || exit_skip " MISSING" echo " FOUND" - trap shutdown_services ERR trap shutdown_services EXIT SCRIPT_NAME=$1 @@ -32,6 +31,9 @@ function setup_config() { export CONF=test-${SCRIPT_NAME}.conf cp template.conf "$CONF" + export WALLET_DB=wallet-${SCRIPT_NAME}.json + rm "$WALLET_DB" 2> /dev/null || true + # Clean up DATA_DIR=$(taler-config -f -c "$CONF" -s PATHS -o TALER_HOME) rm -rf "$DATA_DIR" || true @@ -142,6 +144,8 @@ function shutdown_services() { echo "Final clean up" dropdb "$TARGET_DB" >/dev/null 2>/dev/null || true + rm "$WALLET_DB" 2> /dev/null || true + rm -rf "$DATA_DIR" || true rm "$CONF" } diff --git a/integrationtests/test-base.sh b/integrationtests/test-base.sh index 337d8b131..80ac466f7 100755 --- a/integrationtests/test-base.sh +++ b/integrationtests/test-base.sh @@ -13,4 +13,5 @@ wait_for_services echo "Running wallet" taler-wallet-cli testing integrationtest -e "$EXCHANGE_URL" -m "$MERCHANT_URL" -b "$BANK_URL" +echo "SUCCESS" exit 0 diff --git a/integrationtests/test-double-link.sh b/integrationtests/test-double-link.sh index 75de484c3..5522b94e7 100755 --- a/integrationtests/test-double-link.sh +++ b/integrationtests/test-double-link.sh @@ -7,8 +7,6 @@ setup_services launch_services wait_for_services -WALLET_DB=wallet-double-link.json - echo "Getting pay taler:// Uri" PAY_URI=$(taler-wallet-cli testing gen-pay-uri -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:1" -s "foo" | grep -E -o 'taler://.*') echo "Trying to pay without balance" @@ -21,6 +19,5 @@ echo "Trying to pay what was paid already should throw error" taler-wallet-cli --wallet-db=$WALLET_DB --no-throttle handle-uri --yes "$PAY_URI" 2>&1 | grep -q "already paid" || exit_error "not reporting already paid" echo "Already paid properly detected" -rm $WALLET_DB || true - +echo "SUCCESS" exit 0 diff --git a/integrationtests/test-double-spend.sh b/integrationtests/test-double-spend.sh new file mode 100755 index 000000000..ee2a966f7 --- /dev/null +++ b/integrationtests/test-double-spend.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Script to check that the wallet can not double spend coins and handles this error well + +source "common.sh" +setup_config "double-spend" +setup_services +launch_services +wait_for_services + +echo "Withdraw TESTKUDOS" +taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" >/dev/null +# Copy wallet database before spending coins +cp "$WALLET_DB" "$WALLET_DB.bak" +echo "Spend all the money" +taler-wallet-cli --wallet-db="$WALLET_DB" testing test-pay -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:9.5" -s "foo" +echo "New balance:" +taler-wallet-cli --wallet-db="$WALLET_DB" balance +# Restore old wallet database +mv "$WALLET_DB.bak" "$WALLET_DB" +echo "Balance after getting old coins back:" +taler-wallet-cli --wallet-db="$WALLET_DB" balance +echo "Try to double-spend" +# TODO this should probably fail more gracefully +# "exchange_reply: { hint: 'insufficient funds', code: 1200 } +taler-wallet-cli --wallet-db="$WALLET_DB" testing test-pay -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:9.5" -s "foo" + +echo "SUCCESS" +exit 0 diff --git a/integrationtests/test-recoup.sh b/integrationtests/test-recoup.sh index 938a8506a..72f7e1ad5 100755 --- a/integrationtests/test-recoup.sh +++ b/integrationtests/test-recoup.sh @@ -14,8 +14,6 @@ source "common.sh" setup_config "recoup" TMP_DIR=$(mktemp -d revocation-tmp-XXXXXX) -export WALLET_DB=wallet-revocation.wallet.json -rm -f $WALLET_DB taler-config -c "$CONF" -s exchange -o KEYDIR -V "${TMP_DIR}/keydir/" taler-config -c "$CONF" -s exchange -o REVOCATION_DIR -V "${TMP_DIR}/revdir/" @@ -173,7 +171,7 @@ taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB testing test-pay \ -a "TESTKUDOS:0.02" -s "bar" taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB run-until-done -echo "Bought something with refresh-recouped coin" +echo "SUCCESS: Bought something with refresh-recouped coin" rm -r "$TMP_DIR" -- cgit v1.2.3