test: more payment tests (#2738)

* test: pay_invoice
This commit is contained in:
Vlad Stan
2024-10-17 10:27:36 +02:00
committed by GitHub
parent 13f2dd732f
commit ae4eda04ba
6 changed files with 602 additions and 25 deletions
+1 -1
View File
@@ -999,7 +999,7 @@ async def update_payment_details(
set_clause: list[str] = []
if new_checking_id is not None:
set_clause.append("checking_id = :checking_id")
set_clause.append("checking_id = :new_checking_id")
if status is not None:
set_clause.append("status = :status")
if fee is not None:
+4 -3
View File
@@ -220,6 +220,7 @@ async def pay_invoice(
if not invoice.amount_msat or not invoice.amount_msat > 0:
raise PaymentError("Amountless invoices not supported.", status="failed")
if max_sat and invoice.amount_msat > max_sat * 1000:
raise PaymentError("Amount in invoice is too high.", status="failed")
@@ -270,7 +271,7 @@ async def pay_invoice(
fee_reserve_total_msat = fee_reserve_total(
invoice.amount_msat, internal=True
)
create_payment_model.fee = abs(fee_reserve_total_msat)
create_payment_model.fee = service_fee(invoice.amount_msat, True)
new_payment = await create_payment(
checking_id=internal_id,
data=create_payment_model,
@@ -356,7 +357,7 @@ async def pay_invoice(
updated = await get_wallet_payment(
wallet_id, payment.checking_id, conn=conn
)
if wallet and updated:
if wallet and updated and updated.success:
await send_payment_notification(wallet, updated)
logger.success(f"payment successful {payment.checking_id}")
elif payment.checking_id is None and payment.ok is False:
@@ -403,7 +404,6 @@ async def _create_external_payment(
conn: Optional[Connection],
) -> Payment:
fee_reserve_total_msat = fee_reserve_total(amount_msat, internal=False)
# check if there is already a payment with the same checking_id
old_payment = await get_standalone_payment(temp_id, conn=conn)
if old_payment:
@@ -678,6 +678,7 @@ def fee_reserve(amount_msat: int, internal: bool = False) -> int:
def service_fee(amount_msat: int, internal: bool = False) -> int:
amount_msat = abs(amount_msat)
service_fee_percent = settings.lnbits_service_fee
fee_max = settings.lnbits_service_fee_max * 1000
if settings.lnbits_service_fee_wallet:
+13 -11
View File
@@ -30,17 +30,19 @@ from .base import (
class FakeWallet(Wallet):
queue: asyncio.Queue = asyncio.Queue(0)
payment_secrets: Dict[str, str] = {}
paid_invoices: Set[str] = set()
secret: str = settings.fake_wallet_secret
privkey: str = hashlib.pbkdf2_hmac(
"sha256",
secret.encode(),
b"FakeWallet",
2048,
32,
).hex()
def __init__(self) -> None:
self.queue: asyncio.Queue = asyncio.Queue(0)
self.payment_secrets: Dict[str, str] = {}
self.paid_invoices: Set[str] = set()
self.secret: str = settings.fake_wallet_secret
self.privkey: str = hashlib.pbkdf2_hmac(
"sha256",
self.secret.encode(),
b"FakeWallet",
2048,
32,
).hex()
async def cleanup(self):
pass