break wait loop when payment fails
This commit is contained in:
parent
16dd9015c4
commit
bb94f38c2f
2 changed files with 39 additions and 0 deletions
8
tasks.py
8
tasks.py
|
|
@ -114,6 +114,14 @@ async def _process_invoice(
|
||||||
payment_status = await check_transaction_status(wallet_id, payment_hash)
|
payment_status = await check_transaction_status(wallet_id, payment_hash)
|
||||||
if payment_status.success:
|
if payment_status.success:
|
||||||
break
|
break
|
||||||
|
if payment_status.failed:
|
||||||
|
return {
|
||||||
|
"error": {
|
||||||
|
"code": "PAYMENT_FAILED",
|
||||||
|
"message": "Payment failed.",
|
||||||
|
},
|
||||||
|
"in_budget": in_budget,
|
||||||
|
}
|
||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
if not payment_status:
|
if not payment_status:
|
||||||
raise Exception("Payment status not found")
|
raise Exception("Payment status not found")
|
||||||
|
|
|
||||||
31
tests/unit/test_tasks.py
Normal file
31
tests/unit/test_tasks.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ... import tasks
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_process_invoice_returns_payment_failed_on_failed_status(monkeypatch):
|
||||||
|
async def fake_tracked_spend_nwc(*args, **kwargs):
|
||||||
|
return True, "a" * 64
|
||||||
|
|
||||||
|
async def fake_check_transaction_status(wallet_id: str, payment_hash: str):
|
||||||
|
return SimpleNamespace(success=False, failed=True)
|
||||||
|
|
||||||
|
monkeypatch.setattr(tasks, "tracked_spend_nwc", fake_tracked_spend_nwc)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
tasks, "check_transaction_status", fake_check_transaction_status
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await tasks._process_invoice(
|
||||||
|
wallet_id="wallet123",
|
||||||
|
pubkey="a" * 64,
|
||||||
|
invoice="lnbc1example",
|
||||||
|
amount_msats=1000,
|
||||||
|
description="test",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["error"]["code"] == "PAYMENT_FAILED"
|
||||||
|
assert result["error"]["message"] == "Payment failed."
|
||||||
|
assert result["in_budget"] is True
|
||||||
Loading…
Add table
Add a link
Reference in a new issue