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

Function test_disconnectpeer

tests/test_connection.py:2795–2826  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2793
2794
2795def test_disconnectpeer(node_factory, bitcoind):
2796 l1, l2, l3 = node_factory.get_nodes(3, opts={'may_reconnect': False})
2797 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
2798 l1.rpc.connect(l3.info['id'], 'localhost', l3.port)
2799
2800 # Gossiping
2801 assert l1.rpc.getpeer(l2.info['id'])['connected']
2802 assert len(l1.rpc.listpeerchannels(l2.info['id'])['channels']) == 0
2803 assert l1.rpc.getpeer(l3.info['id'])['connected']
2804 assert len(l1.rpc.listpeerchannels(l3.info['id'])['channels']) == 0
2805 wait_for(lambda: l2.rpc.getpeer(l1.info['id']) is not None)
2806
2807 # Disconnect l2 from l1
2808 l1.rpc.disconnect(l2.info['id'])
2809
2810 # Make sure listpeers no longer returns the disconnected node
2811 assert l1.rpc.getpeer(l2.info['id']) is None
2812 wait_for(lambda: l2.rpc.getpeer(l1.info['id']) is None)
2813
2814 # Make sure you cannot disconnect after disconnecting
2815 with pytest.raises(RpcError, match=r'Unknown peer'):
2816 l1.rpc.disconnect(l2.info['id'])
2817 with pytest.raises(RpcError, match=r'Unknown peer'):
2818 l2.rpc.disconnect(l1.info['id'])
2819
2820 # Fund channel l1 -> l3
2821 l1.fundchannel(l3, 10**6)
2822 mine_funding_to_announce(bitcoind, [l1, l2, l3])
2823
2824 # disconnecting a non gossiping peer results in error
2825 with pytest.raises(RpcError, match=r'Peer has \(at least one\) channel in state CHANNELD_NORMAL'):
2826 l1.rpc.disconnect(l3.info['id'])
2827
2828
2829@pytest.mark.openchannel('v1')

Callers

nothing calls this directly

Calls 8

wait_forFunction · 0.90
mine_funding_to_announceFunction · 0.90
get_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
connectMethod · 0.45
getpeerMethod · 0.45
disconnectMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected