MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/p2p_node_network_limited.py:52–114  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

50 self.disconnect_all()
51
52 def run_test(self):
53 node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
54
55 expected_services = NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED
56
57 self.log.info("Check that node has signalled expected services.")
58 assert_equal(node.nServices, expected_services)
59
60 self.log.info("Check that the localservices is as expected.")
61 assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
62
63 self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
64 connect_nodes_bi(self.nodes, 0, 1)
65 blocks = self.nodes[1].generate(292)
66 sync_blocks([self.nodes[0], self.nodes[1]])
67
68 self.log.info("Make sure we can max retrieve block at tip-288.")
69 node.send_getdata_for_block(blocks[1]) # last block in valid range
70 node.wait_for_block(int(blocks[1], 16), timeout=3)
71
72 self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
73 node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
74 node.wait_for_disconnect(5)
75
76 self.log.info("Check local address relay, do a fresh connection.")
77 self.nodes[0].disconnect_p2ps()
78 node1 = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
79 node1.send_message(msg_verack())
80
81 node1.wait_for_addr()
82 #must relay address with NODE_NETWORK_LIMITED
83 assert_equal(node1.firstAddrnServices, 1036)
84
85 self.nodes[0].disconnect_p2ps()
86 node1.wait_for_disconnect()
87
88 # connect unsynced node 2 with pruned NODE_NETWORK_LIMITED peer
89 # because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible
90 connect_nodes_bi(self.nodes, 0, 2)
91 try:
92 sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
93 except:
94 pass
95 # node2 must remain at heigh 0
96 assert_equal(self.nodes[2].getblockheader(self.nodes[2].getbestblockhash())['height'], 0)
97
98 # now connect also to node 1 (non pruned)
99 connect_nodes_bi(self.nodes, 1, 2)
100
101 # sync must be possible
102 sync_blocks(self.nodes)
103
104 # disconnect all peers
105 self.disconnect_all()
106
107 # mine 10 blocks on node 0 (pruned node)
108 self.nodes[0].generate(10)
109

Callers

nothing calls this directly

Calls 14

disconnect_allMethod · 0.95
assert_equalFunction · 0.90
connect_nodes_biFunction · 0.90
sync_blocksFunction · 0.90
msg_verackClass · 0.90
P2PIgnoreInvClass · 0.85
add_p2p_connectionMethod · 0.80
infoMethod · 0.80
wait_for_disconnectMethod · 0.80
disconnect_p2psMethod · 0.80
send_messageMethod · 0.80

Tested by

no test coverage detected