fix: reduce pending payment polling rate
This commit is contained in:
parent
d432d74c88
commit
f4b96107fa
2 changed files with 51 additions and 1 deletions
|
|
@ -29,3 +29,51 @@ async def test_process_invoice_returns_payment_failed_on_failed_status(monkeypat
|
|||
assert result["error"]["code"] == "PAYMENT_FAILED"
|
||||
assert result["error"]["message"] == "Payment failed."
|
||||
assert result["in_budget"] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_invoice_polls_pending_payment_at_sustainable_interval(
|
||||
monkeypatch,
|
||||
):
|
||||
async def fake_tracked_spend_nwc(*args, **kwargs):
|
||||
return True, "a" * 64
|
||||
|
||||
statuses = iter(
|
||||
[
|
||||
SimpleNamespace(success=False, failed=False),
|
||||
SimpleNamespace(
|
||||
success=True,
|
||||
failed=False,
|
||||
preimage="b" * 64,
|
||||
fee_msat=10,
|
||||
paid=True,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
async def fake_check_transaction_status(wallet_id: str, payment_hash: str):
|
||||
return next(statuses)
|
||||
|
||||
sleep_calls = []
|
||||
|
||||
async def fake_sleep(delay: float):
|
||||
sleep_calls.append(delay)
|
||||
|
||||
monkeypatch.setattr(tasks, "tracked_spend_nwc", fake_tracked_spend_nwc)
|
||||
monkeypatch.setattr(
|
||||
tasks, "check_transaction_status", fake_check_transaction_status
|
||||
)
|
||||
monkeypatch.setattr(tasks.asyncio, "sleep", fake_sleep)
|
||||
|
||||
result = await tasks._process_invoice(
|
||||
wallet_id="wallet123",
|
||||
pubkey="a" * 64,
|
||||
invoice="lnbc1example",
|
||||
amount_msats=1000,
|
||||
description="test",
|
||||
)
|
||||
|
||||
assert sleep_calls == [tasks.PAYMENT_STATUS_POLL_INTERVAL_SECONDS]
|
||||
assert result["preimage"] == "b" * 64
|
||||
assert result["fee_msats"] == 10
|
||||
assert result["paid"] is True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue