summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-07-29 09:33:41 -0300
committerTorsten Grote <t@grobox.de>2020-07-29 09:33:41 -0300
commit9a4cbcd9549fee9865a537ed5236e2a2ebe52cf1 (patch)
tree168d5b606dfab4e12629d13ecb6ee5a23dd70c17 /tests
parent7e34b6699a77620b148b167e6aa12d50cc7456e5 (diff)
downloadwallet-core-9a4cbcd9549fee9865a537ed5236e2a2ebe52cf1.tar.gz
wallet-core-9a4cbcd9549fee9865a537ed5236e2a2ebe52cf1.tar.bz2
wallet-core-9a4cbcd9549fee9865a537ed5236e2a2ebe52cf1.zip
Add more checks to new withdrawal API test
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py14
-rw-r--r--tests/components/bank.py15
-rw-r--r--tests/test_withdrawal.py32
3 files changed, 41 insertions, 20 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 9f0dc11da..333953b9d 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,11 +1,13 @@
+import json
+
from taler.util.amount import Amount
def check_single_balance(
- balances,
- available,
- pending_in=Amount.parse("TESTKUDOS:0"),
- pending_out=Amount.parse("TESTKUDOS:0"),
+ balances,
+ available,
+ pending_in=Amount.parse("TESTKUDOS:0"),
+ pending_out=Amount.parse("TESTKUDOS:0"),
):
assert len(balances) == 1
assert Amount.parse(balances[0]["available"]) == available
@@ -15,3 +17,7 @@ def check_single_balance(
def json_to_amount(d):
return Amount(d["currency"], d["value"], d["fraction"])
+
+
+def print_json(obj):
+ print(json.dumps(obj, indent=2))
diff --git a/tests/components/bank.py b/tests/components/bank.py
index ee2d6e923..f6551b491 100644
--- a/tests/components/bank.py
+++ b/tests/components/bank.py
@@ -1,21 +1,20 @@
import os
+import secrets
+from dataclasses import dataclass
from subprocess import run
import psutil
-
import requests
-import secrets
-
from .taler_service import TalerService
-from dataclasses import dataclass
@dataclass
class BankUser:
username: str
password: str
+
@dataclass
class WithdrawUriResponse:
taler_withdraw_uri: str
@@ -71,10 +70,10 @@ class Bank(TalerService):
withdrawal_id=rj["withdrawal_id"],
)
- def confirm_withdrawal(self, bankuser, withdrawal_id):
- auth = (bankuser.username, bankuser.password)
- resp = requests.post(
- f"{self.url}accounts/{bankuser.username}/withdrawals/{withdrawal_id}/confirm",
+ def confirm_withdrawal(self, bank_user, withdrawal_id):
+ auth = (bank_user.username, bank_user.password)
+ requests.post(
+ f"{self.url}accounts/{bank_user.username}/withdrawals/{withdrawal_id}/confirm",
auth=auth
)
diff --git a/tests/test_withdrawal.py b/tests/test_withdrawal.py
index 0f5c8435b..6392891f1 100644
--- a/tests/test_withdrawal.py
+++ b/tests/test_withdrawal.py
@@ -78,13 +78,11 @@ def test_withdrawal(exchange, bank, wallet):
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.
+ # 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")
- print(result)
check_single_balance(result["balances"], amount_effective, amount_effective)
# assert that 2nd withdrawal shows up properly in transactions
@@ -114,11 +112,18 @@ def test_withdrawal(exchange, bank, wallet):
# 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"),
)
+ # check that transaction is no longer pending, but confirmed
+ result = wallet.cmd("getTransactions")
+ assert len(result["transactions"]) == 2
+ transaction = result["transactions"][1] # TODO this transaction should be at the top now
+ assert transaction["type"] == "withdrawal"
+ assert not transaction["pending"]
+ assert transaction["withdrawalDetails"]["confirmed"]
+
# one more manual withdrawal
request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
result = wallet.cmd("acceptManualWithdrawal", request)
@@ -127,7 +132,6 @@ def test_withdrawal(exchange, bank, wallet):
# check that balance is correct
result = wallet.cmd("getBalances")
- print(result)
check_single_balance(
result["balances"], amount_effective + amount_effective, amount_effective
)
@@ -135,6 +139,18 @@ def test_withdrawal(exchange, bank, wallet):
# assert that 3nd withdrawal shows up properly in transactions
result = wallet.cmd("getTransactions")
assert len(result["transactions"]) == 3
- for t in result["transactions"]:
- print(t)
- print()
+ transaction = result["transactions"][0]
+ assert transaction["type"] == "withdrawal"
+ 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"]
+ assert withdrawal_details["type"] == "manual-transfer"
+ assert len(withdrawal_details["exchangePaytoUris"]) == 1
+ assert withdrawal_details["exchangePaytoUris"][0].startswith(payto_list[0])
+
+ # last withdrawal is newest
+ timestamp3 = transaction["timestamp"]["t_ms"]
+ assert timestamp3 > timestamp0
+ assert timestamp3 > timestamp1