Add more checks to new withdrawal API test
This commit is contained in:
parent
7e34b6699a
commit
9a4cbcd954
@ -1,3 +1,5 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
from taler.util.amount import Amount
|
from taler.util.amount import Amount
|
||||||
|
|
||||||
|
|
||||||
@ -15,3 +17,7 @@ def check_single_balance(
|
|||||||
|
|
||||||
def json_to_amount(d):
|
def json_to_amount(d):
|
||||||
return Amount(d["currency"], d["value"], d["fraction"])
|
return Amount(d["currency"], d["value"], d["fraction"])
|
||||||
|
|
||||||
|
|
||||||
|
def print_json(obj):
|
||||||
|
print(json.dumps(obj, indent=2))
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
import os
|
import os
|
||||||
|
import secrets
|
||||||
|
from dataclasses import dataclass
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import secrets
|
|
||||||
|
|
||||||
from .taler_service import TalerService
|
from .taler_service import TalerService
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BankUser:
|
class BankUser:
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WithdrawUriResponse:
|
class WithdrawUriResponse:
|
||||||
taler_withdraw_uri: str
|
taler_withdraw_uri: str
|
||||||
@ -71,10 +70,10 @@ class Bank(TalerService):
|
|||||||
withdrawal_id=rj["withdrawal_id"],
|
withdrawal_id=rj["withdrawal_id"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def confirm_withdrawal(self, bankuser, withdrawal_id):
|
def confirm_withdrawal(self, bank_user, withdrawal_id):
|
||||||
auth = (bankuser.username, bankuser.password)
|
auth = (bank_user.username, bank_user.password)
|
||||||
resp = requests.post(
|
requests.post(
|
||||||
f"{self.url}accounts/{bankuser.username}/withdrawals/{withdrawal_id}/confirm",
|
f"{self.url}accounts/{bank_user.username}/withdrawals/{withdrawal_id}/confirm",
|
||||||
auth=auth
|
auth=auth
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,13 +78,11 @@ def test_withdrawal(exchange, bank, wallet):
|
|||||||
confirm_url = result["confirmTransferUrl"]
|
confirm_url = result["confirmTransferUrl"]
|
||||||
|
|
||||||
# Let the wallet do its work. At this point, the bank-integrated
|
# 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
|
# withdrawal won't have succeeded yet, as it's not confirmed at the bank side.
|
||||||
# side.
|
|
||||||
wallet.run_pending()
|
wallet.run_pending()
|
||||||
|
|
||||||
# check that balance is correct
|
# check that balance is correct
|
||||||
result = wallet.cmd("getBalances")
|
result = wallet.cmd("getBalances")
|
||||||
print(result)
|
|
||||||
check_single_balance(result["balances"], amount_effective, amount_effective)
|
check_single_balance(result["balances"], amount_effective, amount_effective)
|
||||||
|
|
||||||
# assert that 2nd withdrawal shows up properly in transactions
|
# assert that 2nd withdrawal shows up properly in transactions
|
||||||
@ -114,11 +112,18 @@ def test_withdrawal(exchange, bank, wallet):
|
|||||||
|
|
||||||
# check that balance is correct
|
# check that balance is correct
|
||||||
result = wallet.cmd("getBalances")
|
result = wallet.cmd("getBalances")
|
||||||
print(result)
|
|
||||||
check_single_balance(
|
check_single_balance(
|
||||||
result["balances"], Amount.parse("TESTKUDOS:9.68"), Amount.parse("TESTKUDOS:0"),
|
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
|
# one more manual withdrawal
|
||||||
request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
|
request = {"exchangeBaseUrl": exchange.url, "amount": amount_raw.stringify()}
|
||||||
result = wallet.cmd("acceptManualWithdrawal", request)
|
result = wallet.cmd("acceptManualWithdrawal", request)
|
||||||
@ -127,7 +132,6 @@ def test_withdrawal(exchange, bank, wallet):
|
|||||||
|
|
||||||
# check that balance is correct
|
# check that balance is correct
|
||||||
result = wallet.cmd("getBalances")
|
result = wallet.cmd("getBalances")
|
||||||
print(result)
|
|
||||||
check_single_balance(
|
check_single_balance(
|
||||||
result["balances"], amount_effective + amount_effective, amount_effective
|
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
|
# assert that 3nd withdrawal shows up properly in transactions
|
||||||
result = wallet.cmd("getTransactions")
|
result = wallet.cmd("getTransactions")
|
||||||
assert len(result["transactions"]) == 3
|
assert len(result["transactions"]) == 3
|
||||||
for t in result["transactions"]:
|
transaction = result["transactions"][0]
|
||||||
print(t)
|
assert transaction["type"] == "withdrawal"
|
||||||
print()
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user