summaryrefslogtreecommitdiff
path: root/tests/test_withdrawal.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_withdrawal.py')
-rw-r--r--tests/test_withdrawal.py62
1 files changed, 41 insertions, 21 deletions
diff --git a/tests/test_withdrawal.py b/tests/test_withdrawal.py
index 8a68807b6..0f5c8435b 100644
--- a/tests/test_withdrawal.py
+++ b/tests/test_withdrawal.py
@@ -6,17 +6,19 @@ from tests import check_single_balance
def test_withdrawal(exchange, bank, wallet):
+ bank_user = bank.register_random_user()
+
# assert that we start with no transactions
result = wallet.cmd("getTransactions")
assert not result["transactions"]
# test withdrawal
- amount_raw = "TESTKUDOS:5"
- wallet.testing_withdraw(amount_raw, exchange.url, bank.url)
+ amount_raw = Amount.parse("TESTKUDOS:5")
+ wallet.testing_withdraw(amount_raw.stringify(), exchange.url, bank.url)
# check that balance is correct
result = wallet.cmd("getBalances")
- amount_effective = Amount("TESTKUDOS", 4, 84000000).stringify()
+ amount_effective = Amount("TESTKUDOS", 4, 84000000)
check_single_balance(result["balances"], amount_effective)
# assert that withdrawal shows up properly in transactions
@@ -24,8 +26,8 @@ def test_withdrawal(exchange, bank, wallet):
assert len(result["transactions"]) == 1
transaction = result["transactions"][0]
assert transaction["type"] == "withdrawal"
- assert transaction["amountEffective"] == amount_effective
- assert transaction["amountRaw"] == amount_raw
+ assert Amount.parse(transaction["amountEffective"]) == amount_effective
+ assert Amount.parse(transaction["amountRaw"]) == amount_raw
assert transaction["exchangeBaseUrl"] == exchange.url
assert not transaction["pending"]
withdrawal_details = transaction["withdrawalDetails"]
@@ -34,12 +36,13 @@ def test_withdrawal(exchange, bank, wallet):
assert withdrawal_details["exchangePaytoUris"] == payto_list
# get a withdrawal URI
- uri = wallet.gen_withdraw_uri(amount_raw, bank.url)
+ bank_uri_resp = bank.generate_withdraw_uri(bank_user, "TESTKUDOS:5")
+ uri = bank_uri_resp.taler_withdraw_uri
assert uri.startswith("taler+http://withdraw")
# get withdrawal details from URI
result = wallet.cmd("getWithdrawalDetailsForUri", {"talerWithdrawUri": uri})
- assert result["amount"] == amount_raw
+ assert Amount.parse(result["amount"]) == amount_raw
assert result["defaultExchangeBaseUrl"] == exchange.url
assert len(result["possibleExchanges"]) == 1
assert result["possibleExchanges"][0]["exchangeBaseUrl"] == exchange.url
@@ -47,10 +50,10 @@ def test_withdrawal(exchange, bank, wallet):
assert result["possibleExchanges"][0]["paytoUris"] == payto_list
# check withdrawal details for amount
- request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw}
+ request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
result = wallet.cmd("getWithdrawalDetailsForAmount", request)
- assert result["amountRaw"] == amount_raw
- assert result["amountEffective"] == amount_effective
+ assert Amount.parse(result["amountRaw"]) == amount_raw
+ assert Amount.parse(result["amountEffective"]) == amount_effective
assert result["paytoUris"] == payto_list
assert not result["tosAccepted"]
@@ -64,29 +67,33 @@ def test_withdrawal(exchange, bank, wallet):
wallet.cmd("setExchangeTosAccepted", request)
# check that ToS are now shown as accepted
- request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw}
+ request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
result = wallet.cmd("getWithdrawalDetailsForAmount", request)
assert result["tosAccepted"]
# accept withdrawal
request = {"exchangeBaseUrl": exchange.url, "talerWithdrawUri": uri}
result = wallet.cmd("acceptBankIntegratedWithdrawal", request)
- assert result["confirmTransferUrl"].startswith(bank.url + "/confirm-withdrawal/")
+ assert result["confirmTransferUrl"].startswith(bank.url + "confirm-withdrawal/")
confirm_url = result["confirmTransferUrl"]
+ # Let the wallet do its work. At this point, the bank-integrated
+ # withdrawal won't have succeeded yet, as it's not confirmed at the bank
+ # side.
+ wallet.run_pending()
+
# check that balance is correct
result = wallet.cmd("getBalances")
- # TODO pendingIncoming and hasPendingTransactions are wrong, right?
print(result)
- # check_single_balance(result["balances"], amount_effective, amount_effective, has_pending=True)
+ check_single_balance(result["balances"], amount_effective, amount_effective)
# assert that 2nd withdrawal shows up properly in transactions
result = wallet.cmd("getTransactions")
assert len(result["transactions"]) == 2
transaction = result["transactions"][0]
assert transaction["type"] == "withdrawal"
- assert transaction["amountEffective"] == amount_effective
- assert transaction["amountRaw"] == amount_raw
+ assert Amount.parse(transaction["amountEffective"]) == amount_effective
+ assert Amount.parse(transaction["amountRaw"]) == amount_raw
assert transaction["exchangeBaseUrl"] == exchange.url
assert transaction["pending"]
withdrawal_details = transaction["withdrawalDetails"]
@@ -99,22 +106,35 @@ def test_withdrawal(exchange, bank, wallet):
timestamp1 = result["transactions"][1]["timestamp"]["t_ms"]
assert timestamp0 > timestamp1
+ # now we actually confirm the withdrawal
+ bank.confirm_withdrawal(bank_user, bank_uri_resp.withdrawal_id)
+ # It might take some time until the exchange knows about the reserve,
+ # so we'll try until it works.
+ wallet.run_until_done()
+
+ # check that balance is correct
+ result = wallet.cmd("getBalances")
+ print(result)
+ check_single_balance(
+ result["balances"], Amount.parse("TESTKUDOS:9.68"), Amount.parse("TESTKUDOS:0"),
+ )
+
# one more manual withdrawal
- request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw}
+ request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
result = wallet.cmd("acceptManualWithdrawal", request)
assert len(result["exchangePaytoUris"]) == 1
result["exchangePaytoUris"][0].startswith(payto_list[0])
# check that balance is correct
result = wallet.cmd("getBalances")
- # TODO pendingIncoming and hasPendingTransactions are wrong, right?
print(result)
- # check_single_balance(result["balances"], amount_effective, TODO, has_pending=True)
+ check_single_balance(
+ result["balances"], amount_effective + amount_effective, amount_effective
+ )
# assert that 3nd withdrawal shows up properly in transactions
result = wallet.cmd("getTransactions")
- # TODO where is the manual withdrawal!??
- # assert len(result["transactions"]) == 3
+ assert len(result["transactions"]) == 3
for t in result["transactions"]:
print(t)
print()