Add functions for getting and comparing balances to integration tests

This commit is contained in:
Torsten Grote 2020-05-08 15:02:07 -03:00
parent 1cf48054c4
commit 7e947ca2cd
No known key found for this signature in database
GPG Key ID: 3E5F77D92CF891FF
5 changed files with 44 additions and 20 deletions

View File

@ -13,6 +13,7 @@ function setup_config() {
# TODO "taler-merchant-httpd -v" should not return an error # TODO "taler-merchant-httpd -v" should not return an error
[[ "$(taler-merchant-httpd -v)" =~ "taler-merchant-httpd v" ]] || exit_skip " MISSING" [[ "$(taler-merchant-httpd -v)" =~ "taler-merchant-httpd v" ]] || exit_skip " MISSING"
echo " FOUND" echo " FOUND"
bc -v >/dev/null </dev/null || exit_error "Please install bc"
trap shutdown_services EXIT trap shutdown_services EXIT
@ -149,6 +150,26 @@ function wait_for_service() {
done done
} }
function get_balance() {
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
}
function assert_less_than() {
AMOUNT_1=${1//TESTKUDOS:/}
AMOUNT_2=${2//TESTKUDOS:/}
if (($(echo "$AMOUNT_1 >= $AMOUNT_2" | bc -l))); then
exit_error "$1 is not lower than $2"
fi
}
function assert_greater_than() {
AMOUNT_1=${1//TESTKUDOS:/}
AMOUNT_2=${2//TESTKUDOS:/}
if (($(echo "$AMOUNT_1 <= $AMOUNT_2" | bc -l))); then
exit_error "$1 is not greater than $2"
fi
}
function shutdown_services() { function shutdown_services() {
echo "Shutting down services" echo "Shutting down services"
jobs -p | xargs --no-run-if-empty kill || true jobs -p | xargs --no-run-if-empty kill || true
@ -171,7 +192,7 @@ function exit_skip() {
} }
function exit_error() { function exit_error() {
echo "\033[0;31mError: $1\033[0m" echo -e "\033[0;31mError: $1\033[0m"
exit 1 exit 1
} }

View File

@ -7,13 +7,13 @@ normal_start_and_wait "double-link"
echo "Getting pay taler:// Uri" 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://.*') 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" echo "Trying to pay without balance"
taler-wallet-cli --wallet-db=$WALLET_DB --no-throttle handle-uri --yes "$PAY_URI" 2>&1 | grep -q "insufficient balance" || exit_error "not reporting insufficient balance" taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>&1 | grep -q "insufficient balance" || exit_error "not reporting insufficient balance"
echo "Withdrawing" echo "Withdrawing"
taler-wallet-cli --wallet-db=$WALLET_DB --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" > /dev/null taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" > /dev/null
echo "Trying to pay again, should work this time" echo "Trying to pay again, should work this time"
taler-wallet-cli --wallet-db=$WALLET_DB --no-throttle handle-uri --yes "$PAY_URI" > /dev/null taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" > /dev/null
echo "Trying to pay what was paid already should throw error" 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" 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" echo "Already paid properly detected"
exit_success exit_success

View File

@ -10,12 +10,10 @@ taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EX
cp "$WALLET_DB" "$WALLET_DB.bak" cp "$WALLET_DB" "$WALLET_DB.bak"
echo "Spend all the money" 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" taler-wallet-cli --wallet-db="$WALLET_DB" testing test-pay -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:9.5" -s "foo"
echo "New balance:" echo "New balance: $(get_balance)"
taler-wallet-cli --wallet-db="$WALLET_DB" balance
# Restore old wallet database # Restore old wallet database
mv "$WALLET_DB.bak" "$WALLET_DB" mv "$WALLET_DB.bak" "$WALLET_DB"
echo "Balance after getting old coins back:" echo "Balance after getting old coins back: $(get_balance)"
taler-wallet-cli --wallet-db="$WALLET_DB" balance
echo "Try to double-spend" echo "Try to double-spend"
# TODO this should probably fail more gracefully # TODO this should probably fail more gracefully
# "exchange_reply: { hint: 'insufficient funds', code: 1200 } # "exchange_reply: { hint: 'insufficient funds', code: 1200 }

View File

@ -6,18 +6,21 @@ normal_start_and_wait "refund"
echo "Withdraw TESTKUDOS" echo "Withdraw TESTKUDOS"
taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" >>"$LOG" 2>>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" >>"$LOG" 2>>"$LOG"
echo -n "Balance after withdrawal: " BALANCE_1=$(get_balance)
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" echo "Balance after withdrawal: $BALANCE_1"
REFUND_URI=$(taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing gen-refund-uri \ REFUND_URI=$(taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing gen-refund-uri \
-m "$MERCHANT_URL" -k sandbox \ -m "$MERCHANT_URL" -k sandbox \
-s "first refund" -a "TESTKUDOS:8" -r "TESTKUDOS:2" 2>>"$LOG" | grep -E -m 1 -o "taler://refund.*insecure=1") -s "first refund" -a "TESTKUDOS:8" -r "TESTKUDOS:2" 2>>"$LOG" | grep -E -m 1 -o "taler://refund.*insecure=1")
echo -n "Balance after payment: " BALANCE_2=$(get_balance)
echo "Balance after payment: $BALANCE_2"
assert_less_than "$BALANCE_2" "$BALANCE_1"
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
echo "Handling refund: $REFUND_URI" echo "Handling refund: $REFUND_URI"
taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri "$REFUND_URI" 2>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri "$REFUND_URI" 2>"$LOG"
taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG"
echo -n "Balance after first refund: " BALANCE_3=$(get_balance)
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" echo "Balance after first refund: $BALANCE_3"
assert_greater_than "$BALANCE_3" "$BALANCE_2"
# TODO how to test second refund for same purchase? # TODO how to test second refund for same purchase?
exit_success exit_success

View File

@ -8,8 +8,8 @@ normal_start_and_wait "retries"
echo "Withdraw TESTKUDOS" echo "Withdraw TESTKUDOS"
taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" 2>>"$LOG" >>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" 2>>"$LOG" >>"$LOG"
echo -n "Balance after withdrawal: " BALANCE_1=$(get_balance)
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" echo "Balance after withdrawal: $BALANCE_1"
echo "Getting pay taler:// Uri" 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://.*') 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 with exchange down, will fail" echo "Trying to pay with exchange down, will fail"
@ -23,8 +23,9 @@ echo -n "Wait for exchange to start"
wait_for_service "$EXCHANGE_URL" wait_for_service "$EXCHANGE_URL"
echo "Retrying operations with exchange up" echo "Retrying operations with exchange up"
taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG"
echo -n "Balance after re-tried payment: " BALANCE_2=$(get_balance)
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" echo "Balance after re-tried payment: $BALANCE_2"
assert_less_than "$BALANCE_2" "$BALANCE_1"
echo "Getting pay taler:// Uri" 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://.*') PAY_URI=$(taler-wallet-cli testing gen-pay-uri -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:1" -s "foo" | grep -E -o 'taler://.*')
@ -39,7 +40,8 @@ echo -n "Wait for merchant to start"
wait_for_service "$MERCHANT_URL" wait_for_service "$MERCHANT_URL"
echo "Retrying payment with merchant up" echo "Retrying payment with merchant up"
taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG" taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG"
echo -n "Balance after re-tried payment: " BALANCE_3=$(get_balance)
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG" echo "Balance after re-tried payment: $BALANCE_3"
assert_less_than "$BALANCE_3" "$BALANCE_2"
exit_success exit_success