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
15 - Assert that we're connected
16 - Send a ping to no_verack_node and no_version_node
18 - Assert that we're still connected
19 - Send a ping to no_verack_node and no_version_node
21 - Assert that we're no longer connected (timeout to receive version/verack is 60 seconds)
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
35 class TimeoutsTest(BitcoinTestFramework
):
36 def set_test_params(self
):
37 self
.setup_clean_chain
= True
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()
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())
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())
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__':