MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_openchannel_hook_chaining

Function test_openchannel_hook_chaining

tests/test_plugin.py:821–854  ·  view source on GitHub ↗

l2 uses a set of plugin that all use the openchannel_hook. We test that chaining works by using multiple plugins in a way that we check for the first plugin that rejects prevents from evaluating further plugin responses down the chain.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

819@pytest.mark.openchannel('v1')
820@pytest.mark.openchannel('v2')
821def test_openchannel_hook_chaining(node_factory, bitcoind):
822 """ l2 uses a set of plugin that all use the openchannel_hook.
823
824 We test that chaining works by using multiple plugins in a way
825 that we check for the first plugin that rejects prevents from evaluating
826 further plugin responses down the chain.
827
828 """
829 opts = [{}, {'plugin': [
830 os.path.join(os.path.dirname(__file__), '..', 'tests/plugins/openchannel_hook_accept.py'),
831 os.path.join(os.path.dirname(__file__), '..', 'tests/plugins/openchannel_hook_accepter.py'),
832 os.path.join(os.path.dirname(__file__), '..', 'tests/plugins/openchannel_hook_reject.py')
833 ]}]
834 l1, l2 = node_factory.line_graph(2, fundchannel=False, opts=opts)
835 l1.fundwallet(10**6)
836
837 hook_msg = "openchannel2? hook rejects and says '"
838 # 100005sat fundchannel should fail fatal() for l2
839 # because hook_accepter.py rejects on that amount 'for a reason'
840 with pytest.raises(RpcError, match=r'reject for a reason'):
841 l1.rpc.fundchannel(l2.info['id'], 100005)
842
843 assert l2.daemon.wait_for_log(hook_msg + "reject for a reason")
844 # first plugin in the chain was called
845 assert l2.daemon.is_in_log("accept on principle")
846 # the third plugin must now not be called anymore
847 assert not l2.daemon.is_in_log("reject on principle")
848
849 assert only_one(l1.rpc.listpeers()['peers'])['connected']
850 # 100000sat is good for hook_accepter, so it should fail 'on principle'
851 # at third hook openchannel_reject.py
852 with pytest.raises(RpcError, match=r'reject on principle'):
853 l1.rpc.fundchannel(l2.info['id'], 100000)
854 assert l2.daemon.wait_for_log(hook_msg + "reject on principle")
855
856
857@pytest.mark.openchannel('v1')

Callers

nothing calls this directly

Calls 8

only_oneFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
fundwalletMethod · 0.80
wait_for_logMethod · 0.80
is_in_logMethod · 0.80
fundchannelMethod · 0.45
listpeersMethod · 0.45

Tested by

no test coverage detected