Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / test / functional / p2p-timeouts.py
blob6d21095cc66e990d489f99612cb94248079d2732
1 #!/usr/bin/env python3
2 # Copyright (c) 2016-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 """Test various net timeouts.
7 - Create three bitcoind nodes:
9 no_verack_node - we never send a verack in response to their version
10 no_version_node - we never send a version (only a ping)
11 no_send_node - we never send any P2P message.
13 - Start all three nodes
14 - Wait 1 second
15 - Assert that we're connected
16 - Send a ping to no_verack_node and no_version_node
17 - Wait 30 seconds
18 - Assert that we're still connected
19 - Send a ping to no_verack_node and no_version_node
20 - Wait 31 seconds
21 - Assert that we're no longer connected (timeout to receive version/verack is 60 seconds)
22 """
24 from time import sleep
26 from test_framework.mininode import *
27 from test_framework.test_framework import BitcoinTestFramework
28 from test_framework.util import *
30 class TestNode(P2PInterface):
31 def on_version(self, message):
32 # Don't send a verack in response
33 pass
35 class TimeoutsTest(BitcoinTestFramework):
36 def set_test_params(self):
37 self.setup_clean_chain = True
38 self.num_nodes = 1
40 def run_test(self):
41 # Setup the p2p connections and start up the network thread.
42 no_verack_node = self.nodes[0].add_p2p_connection(TestNode())
43 no_version_node = self.nodes[0].add_p2p_connection(TestNode(), send_version=False)
44 no_send_node = self.nodes[0].add_p2p_connection(TestNode(), send_version=False)
46 network_thread_start()
48 sleep(1)
50 assert no_verack_node.connected
51 assert no_version_node.connected
52 assert no_send_node.connected
54 no_verack_node.send_message(msg_ping())
55 no_version_node.send_message(msg_ping())
57 sleep(30)
59 assert "version" in no_verack_node.last_message
61 assert no_verack_node.connected
62 assert no_version_node.connected
63 assert no_send_node.connected
65 no_verack_node.send_message(msg_ping())
66 no_version_node.send_message(msg_ping())
68 sleep(31)
70 assert not no_verack_node.connected
71 assert not no_version_node.connected
72 assert not no_send_node.connected
74 if __name__ == '__main__':
75 TimeoutsTest().main()