Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions tests/lightning/test_lightning_backends_mocked.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,79 @@ async def post(self, *args, **kwargs):
assert result.error_message == "mint does not support MPP"


@pytest.mark.asyncio
async def test_clnrest_pay_invoice_mpp_sends_partial_msat(monkeypatch):
wallet = object.__new__(CLNRestWallet)
wallet.unit = Unit.sat
wallet.supports_mpp = True

captured: dict = {}

class Client:
async def post(self, *args, **kwargs):
captured.update(kwargs.get("data", {}))
return _response(
200,
{
"payment_hash": "hash789",
"payment_preimage": "preimage_mpp",
"amount_sent_msat": 601,
"amount_msat": 600,
"status": "complete",
},
)

cast(Any, wallet).client = Client()
monkeypatch.setattr(
"cashu.lightning.clnrest.decode",
lambda request: SimpleNamespace(amount_msat=1000, payment_hash="hash789"),
)

result = await wallet.pay_invoice(
_quote("lnbc1fake", amount=600, unit="msat"), fee_limit_msat=1000
)
assert result.result == PaymentResult.SETTLED
assert result.preimage == "preimage_mpp"
assert "partial_msat" in captured, "partial_msat must be sent to CLN for MPP"
assert captured["partial_msat"] == 600


@pytest.mark.asyncio
async def test_clnrest_pay_invoice_full_amount_no_partial_msat(monkeypatch):
wallet = object.__new__(CLNRestWallet)
wallet.unit = Unit.sat
wallet.supports_mpp = True

captured: dict = {}

class Client:
async def post(self, *args, **kwargs):
captured.update(kwargs.get("data", {}))
return _response(
200,
{
"payment_hash": "full_hash",
"payment_preimage": "preimage123",
"amount_sent_msat": 1001,
"amount_msat": 1000,
"status": "complete",
},
)

cast(Any, wallet).client = Client()
monkeypatch.setattr(
"cashu.lightning.clnrest.decode",
lambda request: SimpleNamespace(amount_msat=1000, payment_hash="full_hash"),
)

result = await wallet.pay_invoice(
_quote("lnbc1fake", amount=1000, unit="msat"), fee_limit_msat=1000
)
assert result.result == PaymentResult.SETTLED
assert result.preimage == "preimage123"
assert "partial_msat" not in captured, "partial_msat must not be sent for full payments"


@pytest.mark.asyncio
async def test_clnrest_get_payment_status_not_found_is_unknown():
wallet = object.__new__(CLNRestWallet)
Expand Down
Loading