Skip to content

Commit 84190af

Browse files
committed
pytest: Add test that we can redo closing negotiation even after onchain.
Signed-off-by: Rusty Russell <[email protected]>
1 parent ca0358f commit 84190af

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/test_closing.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,7 @@ def test_htlc_rexmit_while_closing(node_factory, executor):
27892789
@pytest.mark.openchannel('v1')
27902790
@pytest.mark.developer("needs dev_disconnect")
27912791
def test_you_forgot_closed_channel(node_factory, executor):
2792-
"""Ideally you'd keep talking to us about closed channels"""
2792+
"""Ideally you'd keep talking to us about closed channels: simple"""
27932793
disconnects = ['@WIRE_CLOSING_SIGNED']
27942794

27952795
l1, l2 = node_factory.line_graph(2, opts=[{'may_reconnect': True,
@@ -2811,6 +2811,41 @@ def test_you_forgot_closed_channel(node_factory, executor):
28112811
fut.result(TIMEOUT)
28122812

28132813

2814+
@pytest.mark.developer("needs dev_disconnect")
2815+
def test_you_forgot_closed_channel_onchain(node_factory, bitcoind, executor):
2816+
"""Ideally you'd keep talking to us about closed channels: even if close is mined"""
2817+
disconnects = ['@WIRE_CLOSING_SIGNED']
2818+
2819+
l1, l2 = node_factory.line_graph(2, opts=[{'may_reconnect': True,
2820+
'dev-no-reconnect': None},
2821+
{'may_reconnect': True,
2822+
'dev-no-reconnect': None,
2823+
'disconnect': disconnects}])
2824+
2825+
l1.pay(l2, 200000)
2826+
2827+
fut = executor.submit(l1.rpc.close, l2.info['id'])
2828+
2829+
# l2 considers the closing done, l1 does not
2830+
wait_for(lambda: only_one(only_one(l2.rpc.listpeers()['peers'])['channels'])['state'] == 'CLOSINGD_COMPLETE')
2831+
assert only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['state'] == 'CLOSINGD_SIGEXCHANGE'
2832+
2833+
# l1 does not see any new blocks.
2834+
def no_new_blocks(req):
2835+
return {"result": {"blockhash": None, "block": None}}
2836+
2837+
l1.daemon.rpcproxy.mock_rpc('getrawblockbyheight', no_new_blocks)
2838+
2839+
# Close transaction mined
2840+
bitcoind.generate_block(1, wait_for_mempool=1)
2841+
2842+
wait_for(lambda: only_one(only_one(l2.rpc.listpeers()['peers'])['channels'])['state'] == 'ONCHAIN')
2843+
2844+
# l1 reconnects, it should succeed.
2845+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
2846+
fut.result(TIMEOUT)
2847+
2848+
28142849
@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', "Uses regtest addresses")
28152850
@pytest.mark.developer("too slow without fast polling for blocks")
28162851
def test_segwit_anyshutdown(node_factory, bitcoind, executor):

0 commit comments

Comments
 (0)