Add functions for getting and comparing balances to integration tests
This commit is contained in:
parent
1cf48054c4
commit
7e947ca2cd
@ -13,6 +13,7 @@ function setup_config() {
|
||||
# TODO "taler-merchant-httpd -v" should not return an error
|
||||
[[ "$(taler-merchant-httpd -v)" =~ "taler-merchant-httpd v" ]] || exit_skip " MISSING"
|
||||
echo " FOUND"
|
||||
bc -v >/dev/null </dev/null || exit_error "Please install bc"
|
||||
|
||||
trap shutdown_services EXIT
|
||||
|
||||
@ -149,6 +150,26 @@ function wait_for_service() {
|
||||
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() {
|
||||
echo "Shutting down services"
|
||||
jobs -p | xargs --no-run-if-empty kill || true
|
||||
@ -171,7 +192,7 @@ function exit_skip() {
|
||||
}
|
||||
|
||||
function exit_error() {
|
||||
echo "\033[0;31mError: $1\033[0m"
|
||||
echo -e "\033[0;31mError: $1\033[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,13 @@ normal_start_and_wait "double-link"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
|
||||
exit_success
|
||||
|
@ -10,12 +10,10 @@ taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EX
|
||||
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
|
||||
echo "New balance: $(get_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 "Balance after getting old coins back: $(get_balance)"
|
||||
echo "Try to double-spend"
|
||||
# TODO this should probably fail more gracefully
|
||||
# "exchange_reply: { hint: 'insufficient funds', code: 1200 }
|
||||
|
@ -6,18 +6,21 @@ normal_start_and_wait "refund"
|
||||
|
||||
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"
|
||||
echo -n "Balance after withdrawal: "
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
|
||||
BALANCE_1=$(get_balance)
|
||||
echo "Balance after withdrawal: $BALANCE_1"
|
||||
REFUND_URI=$(taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing gen-refund-uri \
|
||||
-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")
|
||||
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"
|
||||
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" run-until-done 2>>"$LOG" >>"$LOG"
|
||||
echo -n "Balance after first refund: "
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
|
||||
BALANCE_3=$(get_balance)
|
||||
echo "Balance after first refund: $BALANCE_3"
|
||||
assert_greater_than "$BALANCE_3" "$BALANCE_2"
|
||||
# TODO how to test second refund for same purchase?
|
||||
|
||||
exit_success
|
||||
|
@ -8,8 +8,8 @@ normal_start_and_wait "retries"
|
||||
|
||||
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"
|
||||
echo -n "Balance after withdrawal: "
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
|
||||
BALANCE_1=$(get_balance)
|
||||
echo "Balance after withdrawal: $BALANCE_1"
|
||||
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 with exchange down, will fail"
|
||||
@ -23,8 +23,9 @@ echo -n "Wait for exchange to start"
|
||||
wait_for_service "$EXCHANGE_URL"
|
||||
echo "Retrying operations with exchange up"
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG"
|
||||
echo -n "Balance after re-tried payment: "
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
|
||||
BALANCE_2=$(get_balance)
|
||||
echo "Balance after re-tried payment: $BALANCE_2"
|
||||
assert_less_than "$BALANCE_2" "$BALANCE_1"
|
||||
|
||||
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://.*')
|
||||
@ -39,7 +40,8 @@ echo -n "Wait for merchant to start"
|
||||
wait_for_service "$MERCHANT_URL"
|
||||
echo "Retrying payment with merchant up"
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG"
|
||||
echo -n "Balance after re-tried payment: "
|
||||
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
|
||||
BALANCE_3=$(get_balance)
|
||||
echo "Balance after re-tried payment: $BALANCE_3"
|
||||
assert_less_than "$BALANCE_3" "$BALANCE_2"
|
||||
|
||||
exit_success
|
||||
|
Loading…
Reference in New Issue
Block a user