refactor services

- add PaymentFiatAmount
- return Payment on api endpoints
This commit is contained in:
dni ⚡
2024-10-17 10:43:03 +02:00
parent 33bc380594
commit deee7d80be
11 changed files with 391 additions and 411 deletions
@@ -12,35 +12,35 @@ description = "test create invoice"
@pytest.mark.asyncio
async def test_create_invoice(from_wallet):
payment_hash, pr = await create_invoice(
payment = await create_invoice(
wallet_id=from_wallet.id,
amount=1000,
memo=description,
)
invoice = decode(pr)
assert invoice.payment_hash == payment_hash
invoice = decode(payment.bolt11)
assert invoice.payment_hash == payment.payment_hash
assert invoice.amount_msat == 1000000
assert invoice.description == description
funding_source = get_funding_source()
status = await funding_source.get_invoice_status(payment_hash)
status = await funding_source.get_invoice_status(payment.payment_hash)
assert isinstance(status, PaymentStatus)
assert status.pending
@pytest.mark.asyncio
async def test_create_internal_invoice(from_wallet):
payment_hash, pr = await create_invoice(
payment = await create_invoice(
wallet_id=from_wallet.id, amount=1000, memo=description, internal=True
)
invoice = decode(pr)
assert invoice.payment_hash == payment_hash
invoice = decode(payment.bolt11)
assert invoice.payment_hash == payment.payment_hash
assert invoice.amount_msat == 1000000
assert invoice.description == description
# Internal invoices are not on fundingsource. so we should get some kind of error
# that the invoice is not found, but we get status pending
funding_source = get_funding_source()
status = await funding_source.get_invoice_status(payment_hash)
status = await funding_source.get_invoice_status(payment.payment_hash)
assert isinstance(status, PaymentStatus)
assert status.pending
+1 -6
View File
@@ -1,8 +1,5 @@
import pytest
from lnbits.core.crud import (
get_standalone_payment,
)
from lnbits.core.services import (
PaymentError,
PaymentState,
@@ -14,13 +11,11 @@ description = "test pay invoice"
@pytest.mark.asyncio
async def test_services_pay_invoice(to_wallet, real_invoice):
payment_hash = await pay_invoice(
payment = await pay_invoice(
wallet_id=to_wallet.id,
payment_request=real_invoice.get("bolt11"),
description=description,
)
assert payment_hash
payment = await get_standalone_payment(payment_hash)
assert payment
assert not payment.status == PaymentState.SUCCESS
assert payment.memo == description