Merge #11726: Cleanups + nit fixes for walletdir PR
[bitcoinplatinum.git] / test / functional / node_network_limited.py
blob70415e0168dcf2fb34399d9102929640a4ae5039
1 #!/usr/bin/env python3
2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Tests NODE_NETWORK_LIMITED.
7 Tests that a node configured with -prune=550 signals NODE_NETWORK_LIMITED correctly
8 and that it responds to getdata requests for blocks correctly:
9 - send a block within 288 + 2 of the tip
10 - disconnect peers who request blocks older than that."""
11 from test_framework.messages import CInv, msg_getdata
12 from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface
13 from test_framework.test_framework import BitcoinTestFramework
14 from test_framework.util import assert_equal
16 class P2PIgnoreInv(P2PInterface):
17 def on_inv(self, message):
18 # The node will send us invs for other blocks. Ignore them.
19 pass
21 def send_getdata_for_block(self, blockhash):
22 getdata_request = msg_getdata()
23 getdata_request.inv.append(CInv(2, int(blockhash, 16)))
24 self.send_message(getdata_request)
26 class NodeNetworkLimitedTest(BitcoinTestFramework):
27 def set_test_params(self):
28 self.setup_clean_chain = True
29 self.num_nodes = 1
30 self.extra_args = [['-prune=550']]
32 def run_test(self):
33 node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
34 NetworkThread().start()
35 node.wait_for_verack()
37 expected_services = NODE_BLOOM | NODE_WITNESS | NODE_NETWORK_LIMITED
39 self.log.info("Check that node has signalled expected services.")
40 assert_equal(node.nServices, expected_services)
42 self.log.info("Check that the localservices is as expected.")
43 assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
45 self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
46 blocks = self.nodes[0].generate(292)
48 self.log.info("Make sure we can max retrive block at tip-288.")
49 node.send_getdata_for_block(blocks[1]) # last block in valid range
50 node.wait_for_block(int(blocks[1], 16), timeout=3)
52 self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
53 node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
54 node.wait_for_disconnect(5)
56 if __name__ == '__main__':
57 NodeNetworkLimitedTest().main()