summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-05-07 15:33:43 -0300
committerTorsten Grote <t@grobox.de>2020-05-07 15:33:43 -0300
commit38601a1c63840bc85eae166f771a974e0629db28 (patch)
tree1cba1f2300e4b752ffd8726d9d4b3bf1cd0d61ea
parentb7c75bd56a484efcf77210f1541cda67e2a90f61 (diff)
downloadwallet-core-38601a1c63840bc85eae166f771a974e0629db28.tar.gz
wallet-core-38601a1c63840bc85eae166f771a974e0629db28.tar.bz2
wallet-core-38601a1c63840bc85eae166f771a974e0629db28.zip
Add test for double spending (still fails as expected)
-rw-r--r--integrationtests/common.sh6
-rwxr-xr-xintegrationtests/test-base.sh1
-rwxr-xr-xintegrationtests/test-double-link.sh5
-rwxr-xr-xintegrationtests/test-double-spend.sh28
-rwxr-xr-xintegrationtests/test-recoup.sh4
5 files changed, 36 insertions, 8 deletions
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"