Skip to content

Commit

Permalink
pytest: test pay during channel open
Browse files Browse the repository at this point in the history
Notably this parses the listpeerchannels output while the state is
still uncommitted, i.e., state = OPENINGD.
  • Loading branch information
endothermicdev committed Apr 30, 2024
1 parent dc099a0 commit 56d5d45
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/plugins/openchannel_hook_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""Plugin to test openchannel_hook
Will simply accept any channel. Useful fot testing chained hook.
"""

from pyln.client import Plugin
import time

plugin = Plugin()


@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin, **kwargs):
delaytime = float(plugin.get_option('delaytime'))
msg = f'delaying WIRE_ACCEPT_CHANNEL for {delaytime}s'
plugin.log(msg)
time.sleep(delaytime)
return {'result': 'continue'}


@plugin.hook('openchannel2')
def on_openchannel2(openchannel2, plugin, **kwargs):
delaytime = float(plugin.get_option('delaytime'))
msg = f'delaying WIRE_ACCEPT_CHANNEL for {delaytime}s'
plugin.log(msg)
time.sleep(delaytime)
return {'result': 'continue'}


plugin.add_option('delaytime', '10', 'How long to hold the WIRE_OPEN_CHANNEL.')
plugin.run()
17 changes: 17 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5588,3 +5588,20 @@ def test_pay_partial_msat(node_factory, executor):

l1pay.result(TIMEOUT)
l3pay.result(TIMEOUT)


@pytest.mark.xfail(strict=True)
def test_pay_while_opening_channel(node_factory, bitcoind, executor):
delay_plugin = {'plugin': os.path.join(os.getcwd(),
'tests/plugins/openchannel_hook_delay.py'),
'delaytime': '10'}
l1, l2 = node_factory.line_graph(2, fundamount=10**6, wait_for_announce=True)
l3 = node_factory.get_node(options=delay_plugin)
l1.connect(l3)
executor.submit(l1.rpc.fundchannel, l3.info['id'], 100000)
wait_for(lambda: l1.rpc.listpeerchannels(l3.info['id'])['channels'] != [])

# the uncommitted channel should now show up in listpeerchannels
assert only_one(l1.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'OPENINGD'
inv = l2.rpc.invoice(10000, "inv", "inv")
l1.rpc.pay(inv['bolt11'])

0 comments on commit 56d5d45

Please sign in to comment.