From 11180e7aa1745af0cd23ca818b03ae767fbf4dc2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 May 2021 10:06:12 +0930 Subject: [PATCH] pytest: add test for HTLC timeout on failed htlcs. Signed-off-by: Rusty Russell --- tests/test_connection.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 160755ead..aa90dc95f 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -11,7 +11,7 @@ from utils import ( scriptpubkey_addr, EXPERIMENTAL_FEATURES ) -from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND +from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT import os import pytest @@ -3284,3 +3284,30 @@ def test_openchannel_init_alternate(node_factory, executor): fut = executor.submit(l2.rpc.openchannel_init, l1.info['id'], '1000000msat', psbt2) with pytest.raises(RpcError): fut.result(10) + + +@pytest.mark.xfail(strict=True) +def test_htlc_failed_noclose(node_factory): + """Test a bug where the htlc timeout would kick in even if the HTLC failed""" + l1, l2 = node_factory.line_graph(2) + + payment_hash = l2.rpc.invoice(1000, "test", "test")['payment_hash'] + routestep = { + 'msatoshi': FUNDAMOUNT * 1000, + 'id': l2.info['id'], + 'delay': 5, + 'channel': '1x1x1' # note: can be bogus for 1-hop direct payments + } + + # This fails at channeld + l1.rpc.sendpay([routestep], payment_hash) + with pytest.raises(RpcError, match="Capacity exceeded"): + l1.rpc.waitsendpay(payment_hash) + + # Send a second one, too: make sure we don't crash. + l1.rpc.sendpay([routestep], payment_hash) + with pytest.raises(RpcError, match="Capacity exceeded"): + l1.rpc.waitsendpay(payment_hash) + + time.sleep(35) + assert l1.rpc.getpeer(l2.info['id'])['connected']