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

Function test_connect_basic

tests/test_connection.py:36–78  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

34
35
36def test_connect_basic(node_factory):
37 l1, l2 = node_factory.line_graph(2, fundchannel=False)
38 l1id = l1.info['id']
39 l2id = l2.info['id']
40
41 # These should be in connectd.
42 assert l1.rpc.getpeer(l2id)['connected']
43 wait_for(lambda: l2.rpc.getpeer(l1id)['connected'])
44 assert len(l1.rpc.listpeerchannels(l2id)['channels']) == 0
45 assert len(l2.rpc.listpeerchannels(l1id)['channels']) == 0
46
47 # Reconnect should be a noop
48 ret = l1.rpc.connect(l2id, 'localhost', port=l2.port)
49 assert ret['id'] == l2id
50 assert ret['address'] == {'type': 'ipv4', 'address': '127.0.0.1', 'port': l2.port}
51
52 ret = l2.rpc.connect(l1id, host='localhost', port=l1.port)
53 assert ret['id'] == l1id
54 # FIXME: This gives a bogus address (since they connected to us): better to give none!
55 assert 'address' in ret
56
57 # Should still only have one peer!
58 assert len(l1.rpc.listpeers()['peers']) == 1
59 assert len(l2.rpc.listpeers()['peers']) == 1
60
61 # Should get reasonable error if unknown addr for peer.
62 with pytest.raises(RpcError, match=r'Unable to connect, no address known'):
63 l1.rpc.connect('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e')
64
65 # Should get reasonable error if connection refuse.
66 with pytest.raises(RpcError, match=r'Connection establishment: Connection refused'):
67 l1.rpc.connect('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', 1)
68
69 # Should get reasonable error if wrong key for peer.
70 with pytest.raises(RpcError, match=r'Cryptographic handshake: peer closed connection \(wrong key\?\)'):
71 l1.rpc.connect('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', l2.port)
72
73 # test new `num_channels` param
74 assert l1.rpc.listpeers(l2id)['peers'][0]['num_channels'] == 0
75 l1.fundchannel(l2)
76 assert l1.rpc.listpeers(l2id)['peers'][0]['num_channels'] == 1
77 l1.fundchannel(l2)
78 assert l1.rpc.listpeers(l2id)['peers'][0]['num_channels'] == 2
79
80
81def test_remote_addr(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 7

wait_forFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
getpeerMethod · 0.45
connectMethod · 0.45
listpeersMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected