Add test for double spending (still fails as expected)

This commit is contained in:
Torsten Grote 2020-05-07 15:33:43 -03:00
parent b7c75bd56a
commit 38601a1c63
No known key found for this signature in database
GPG Key ID: 3E5F77D92CF891FF
5 changed files with 36 additions and 8 deletions

View File

@ -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"
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"