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

Function test_peerinfo

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

Source from the content-addressed store, hash-verified

2742@pytest.mark.openchannel('v1')
2743@pytest.mark.openchannel('v2')
2744def test_peerinfo(node_factory, bitcoind):
2745 l1, l2 = node_factory.line_graph(2, fundchannel=False, opts={'may_reconnect': True})
2746
2747 lfeatures = expected_peer_features()
2748 nfeatures = expected_node_features()
2749
2750 # Gossiping but no node announcement yet
2751 assert l1.rpc.getpeer(l2.info['id'])['connected']
2752 assert len(l1.rpc.listpeerchannels(l2.info['id'])['channels']) == 0
2753 assert l1.rpc.getpeer(l2.info['id'])['features'] == lfeatures
2754
2755 # Fund a channel to force a node announcement
2756 chan, _ = l1.fundchannel(l2, 10**6)
2757 # Now proceed to funding-depth and do a full gossip round
2758 bitcoind.generate_block(5)
2759 l1.daemon.wait_for_logs(['Received node_announcement for node ' + l2.info['id']])
2760 l2.daemon.wait_for_logs(['Received node_announcement for node ' + l1.info['id']])
2761
2762 # Should have announced the same features as told to peer.
2763 nodes1 = l1.rpc.listnodes(l2.info['id'])['nodes']
2764 nodes2 = l2.rpc.listnodes(l2.info['id'])['nodes']
2765 peer1 = l1.rpc.getpeer(l2.info['id'])
2766 peer2 = l2.rpc.getpeer(l1.info['id'])
2767 # peer features != to node features now because of keysend, which adds a node feature
2768 assert only_one(nodes1)['features'] == nfeatures
2769 assert only_one(nodes2)['features'] == nfeatures
2770 assert peer1['features'] == lfeatures
2771 assert peer2['features'] == lfeatures
2772
2773 # If it reconnects after db load, it should know features.
2774 l1.restart()
2775 wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'])
2776 wait_for(lambda: l2.rpc.getpeer(l1.info['id'])['connected'])
2777 assert l1.rpc.getpeer(l2.info['id'])['features'] == lfeatures
2778 assert l2.rpc.getpeer(l1.info['id'])['features'] == lfeatures
2779
2780 # Close the channel to forget the peer
2781 l1.rpc.close(chan)
2782
2783 # Make sure close tx hits mempool before we mine blocks.
2784 bitcoind.generate_block(100, wait_for_mempool=1)
2785 l1.daemon.wait_for_log('onchaind complete, forgetting peer')
2786 l2.daemon.wait_for_log('onchaind complete, forgetting peer')
2787 assert l1.rpc.listpeerchannels(l2.info['id'])['channels'] == []
2788 assert l2.rpc.listpeerchannels(l1.info['id'])['channels'] == []
2789
2790 # The only channel was closed, everybody should have forgotten the nodes
2791 assert l1.rpc.listnodes()['nodes'] == []
2792 assert l2.rpc.listnodes()['nodes'] == []
2793
2794
2795def test_disconnectpeer(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 14

expected_peer_featuresFunction · 0.90
expected_node_featuresFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
generate_blockMethod · 0.80
wait_for_logsMethod · 0.80
restartMethod · 0.80
wait_for_logMethod · 0.80
getpeerMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected