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

Function test_sendcustommsg

tests/test_misc.py:2910–2980  ·  view source on GitHub ↗

Check that we can send custommsgs to peers in various states. `l2` is the node under test. `l1` has a channel with `l2` and should therefore be attached to `channeld`. `l4` is just connected, so it should be attached to `openingd`. `l3` has a channel open, but is disconnected and we

(node_factory)

Source from the content-addressed store, hash-verified

2908
2909
2910def test_sendcustommsg(node_factory):
2911 """Check that we can send custommsgs to peers in various states.
2912
2913 `l2` is the node under test. `l1` has a channel with `l2` and should
2914 therefore be attached to `channeld`. `l4` is just connected, so it should
2915 be attached to `openingd`. `l3` has a channel open, but is disconnected
2916 and we can't send to it.
2917
2918 """
2919 opts = {'log-level': 'io', 'plugin': [
2920 os.path.join(os.path.dirname(__file__), "plugins", "custommsg_b.py"),
2921 os.path.join(os.path.dirname(__file__), "plugins", "custommsg_a.py")
2922 ]}
2923 l1, l2, l3, l4 = node_factory.get_nodes(4, opts=opts)
2924 node_factory.join_nodes([l1, l2, l3])
2925 l2.connect(l4)
2926 l3.stop()
2927 msg = 'aa' + ('ff' * 30) + 'bb'
2928
2929 # This address doesn't exist so we should get an error when we try sending
2930 # a message to it.
2931 node_id = '02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f'
2932 with pytest.raises(RpcError, match=r'No such peer'):
2933 l1.rpc.sendcustommsg(node_id, msg)
2934
2935 # `l3` is disconnected and we can't send messages to it
2936 wait_for(lambda: l2.rpc.listpeers(l3.info['id'])['peers'][0]['connected'] is False)
2937 with pytest.raises(RpcError, match=r'Peer is not connected'):
2938 l2.rpc.sendcustommsg(l3.info['id'], msg)
2939
2940 # We should not be able to send a bogus `ping` message, since it collides
2941 # with a message defined in the spec, and could potentially mess up our
2942 # internal state.
2943 with pytest.raises(RpcError, match=r'Cannot send messages of type 18 .WIRE_PING.'):
2944 l2.rpc.sendcustommsg(l2.info['id'], r'0012')
2945
2946 # This should work since the peer is currently owned by `channeld`
2947 l2.rpc.sendcustommsg(l1.info['id'], msg)
2948 l2.daemon.wait_for_log(
2949 r'{peer_id}-{owner}: \[OUT\] {msg}'.format(
2950 owner='connectd', msg=msg, peer_id=l1.info['id']
2951 )
2952 )
2953 l1.daemon.wait_for_log(r'\[IN\] {}'.format(msg))
2954 l1.daemon.wait_for_logs([
2955 r'Got custommessage_a {msg} from peer {peer_id}'.format(
2956 msg=msg, peer_id=l2.info['id']),
2957 r'Got custommessage_b {msg} from peer {peer_id}'.format(
2958 msg=msg, peer_id=l2.info['id'])
2959 ])
2960
2961 # This should work since the peer is currently owned by `openingd`
2962 l2.rpc.sendcustommsg(l4.info['id'], msg)
2963 l2.daemon.wait_for_log(
2964 r'{peer_id}-{owner}: \[OUT\] {msg}'.format(
2965 owner='connectd', msg=msg, peer_id=l4.info['id']
2966 )
2967 )

Callers

nothing calls this directly

Calls 11

wait_forFunction · 0.90
joinMethod · 0.80
get_nodesMethod · 0.80
join_nodesMethod · 0.80
sendcustommsgMethod · 0.80
wait_for_logMethod · 0.80
wait_for_logsMethod · 0.80
is_in_logMethod · 0.80
connectMethod · 0.45
stopMethod · 0.45
listpeersMethod · 0.45

Tested by

no test coverage detected