Skip to content

Commit f0ab4d7

Browse files
rustyrussellcdecker
authored andcommitted
pytest: add test that htlc_accepted hook only gets called after init.
We fail this. Signed-off-by: Rusty Russell <[email protected]>
1 parent 49496ab commit f0ab4d7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/plugins/hold_htlcs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ def on_htlc_accepted(htlc, onion, plugin, **kwargs):
3434
return {'result': 'continue'}
3535

3636

37+
@plugin.init()
38+
def init(options, configuration, plugin):
39+
plugin.log("hold_htlcs.py initializing")
40+
41+
3742
plugin.run()

tests/test_plugin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def test_htlc_accepted_hook_resolve(node_factory):
466466
assert len(inv) == 1 and inv[0]['status'] == 'unpaid'
467467

468468

469+
@pytest.mark.xfail(strict=True)
469470
def test_htlc_accepted_hook_direct_restart(node_factory, executor):
470471
"""l2 restarts while it is pondering what to do with an HTLC.
471472
"""
@@ -479,12 +480,19 @@ def test_htlc_accepted_hook_direct_restart(node_factory, executor):
479480
f1 = executor.submit(l1.rpc.pay, i1)
480481

481482
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
483+
needle = l2.daemon.logsearch_start
482484
l2.restart()
483485

486+
# Now it should try again, *after* initializing.
487+
# This may be before "Server started with public key" swallowed by restart()
488+
l2.daemon.logsearch_start = needle + 1
489+
l2.daemon.wait_for_log(r'hold_htlcs.py initializing')
490+
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
484491
f1.result()
485492

486493

487494
@unittest.skipIf(not DEVELOPER, "without DEVELOPER=1, gossip v slow")
495+
@pytest.mark.xfail(strict=True)
488496
def test_htlc_accepted_hook_forward_restart(node_factory, executor):
489497
"""l2 restarts while it is pondering what to do with an HTLC.
490498
"""
@@ -500,8 +508,15 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor):
500508

501509
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
502510

511+
needle = l2.daemon.logsearch_start
503512
l2.restart()
504513

514+
# Now it should try again, *after* initializing.
515+
# This may be before "Server started with public key" swallowed by restart()
516+
l2.daemon.logsearch_start = needle + 1
517+
l2.daemon.wait_for_log(r'hold_htlcs.py initializing')
518+
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
519+
505520
# Grab the file where the plugin wrote the onion and read it in for some
506521
# additional checks
507522
logline = l2.daemon.wait_for_log(r'Onion written to')

0 commit comments

Comments
 (0)