2024-05-13 16:55:38 +02:00
|
|
|
import pytest
|
|
|
|
|
2024-10-29 09:58:22 +01:00
|
|
|
from lnbits.core.models import PaymentState
|
2024-05-13 16:55:38 +02:00
|
|
|
from lnbits.core.services import (
|
|
|
|
pay_invoice,
|
|
|
|
)
|
2024-10-29 09:58:22 +01:00
|
|
|
from lnbits.exceptions import PaymentError
|
2024-05-13 16:55:38 +02:00
|
|
|
|
|
|
|
description = "test pay invoice"
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2024-05-13 16:55:38 +02:00
|
|
|
async def test_services_pay_invoice(to_wallet, real_invoice):
|
2024-10-29 09:58:22 +01:00
|
|
|
payment = await pay_invoice(
|
2024-05-13 16:55:38 +02:00
|
|
|
wallet_id=to_wallet.id,
|
|
|
|
payment_request=real_invoice.get("bolt11"),
|
|
|
|
description=description,
|
|
|
|
)
|
|
|
|
assert payment
|
2024-10-29 09:58:22 +01:00
|
|
|
assert payment.status == PaymentState.SUCCESS
|
2024-05-13 16:55:38 +02:00
|
|
|
assert payment.memo == description
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2024-05-13 16:55:38 +02:00
|
|
|
async def test_services_pay_invoice_0_amount_invoice(
|
|
|
|
to_wallet, real_amountless_invoice
|
|
|
|
):
|
|
|
|
with pytest.raises(PaymentError):
|
|
|
|
await pay_invoice(
|
|
|
|
wallet_id=to_wallet.id,
|
|
|
|
payment_request=real_amountless_invoice,
|
|
|
|
)
|