Skip to content

Commit faaee1e

Browse files
author
MarcoFalke
committedSep 17, 2019
test: Use connect_nodes when connecting nodes in the test_framework
1 parent 1111bb9 commit faaee1e

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed
 

‎test/functional/p2p_disconnect_ban.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def set_test_params(self):
1818
self.num_nodes = 2
1919

2020
def run_test(self):
21+
self.log.info("Connect nodes both way")
22+
connect_nodes(self.nodes[0], 1)
23+
connect_nodes(self.nodes[1], 0)
24+
2125
self.log.info("Test setban and listbanned RPCs")
2226

2327
self.log.info("setban: successfully ban single IP address")
@@ -74,7 +78,9 @@ def run_test(self):
7478

7579
# Clear ban lists
7680
self.nodes[1].clearbanned()
77-
connect_nodes_bi(self.nodes, 0, 1)
81+
self.log.info("Connect nodes both way")
82+
connect_nodes(self.nodes[0], 1)
83+
connect_nodes(self.nodes[1], 0)
7884

7985
self.log.info("Test disconnectnode RPCs")
8086

‎test/functional/p2p_tx_download.py

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def test_inv_block(self):
121121
# peer, plus
122122
# * the first time it is re-requested from the outbound peer, plus
123123
# * 2 seconds to avoid races
124+
assert self.nodes[1].getpeerinfo()[0]['inbound'] == False
124125
timeout = 2 + (MAX_GETDATA_RANDOM_DELAY + INBOUND_PEER_TX_DELAY) + (
125126
GETDATA_TX_INTERVAL + MAX_GETDATA_RANDOM_DELAY)
126127
self.log.info("Tx should be received at node 1 after {} seconds".format(timeout))

‎test/functional/rpc_net.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def set_test_params(self):
5454
self.extra_args = [["-minrelaytxfee=0.00001000"],["-minrelaytxfee=0.00000500"]]
5555

5656
def run_test(self):
57+
self.log.info('Connect nodes both way')
58+
connect_nodes(self.nodes[0], 1)
59+
connect_nodes(self.nodes[1], 0)
60+
5761
self._test_connection_count()
5862
self._test_getnettotals()
5963
self._test_getnetworkinfo()
@@ -105,7 +109,10 @@ def _test_getnetworkinfo(self):
105109
wait_until(lambda: self.nodes[0].getnetworkinfo()['connections'] == 0, timeout=3)
106110

107111
self.nodes[0].setnetworkactive(state=True)
108-
connect_nodes_bi(self.nodes, 0, 1)
112+
self.log.info('Connect nodes both way')
113+
connect_nodes(self.nodes[0], 1)
114+
connect_nodes(self.nodes[1], 0)
115+
109116
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
110117
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
111118

‎test/functional/test_framework/test_framework.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,18 @@ def setup_network(self):
281281
# Connect the nodes as a "chain". This allows us
282282
# to split the network between nodes 1 and 2 to get
283283
# two halves that can work on competing chains.
284+
#
285+
# Topology looks like this:
286+
# node0 <-- node1 <-- node2 <-- node3
287+
#
288+
# If all nodes are in IBD (clean chain from genesis), node0 is assumed to be the source of blocks (miner). To
289+
# ensure block propagation, all nodes will establish outgoing connections toward node0.
290+
# See fPreferredDownload in net_processing.
291+
#
292+
# If further outbound connections are needed, they can be added at the beginning of the test with e.g.
293+
# connect_nodes(self.nodes[1], 2)
284294
for i in range(self.num_nodes - 1):
285-
connect_nodes_bi(self.nodes, i, i + 1)
295+
connect_nodes(self.nodes[i + 1], i)
286296
self.sync_all()
287297

288298
def setup_nodes(self):

‎test/functional/wallet_listsinceblock.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
"""Test the listsincelast RPC."""
66

77
from test_framework.test_framework import BitcoinTestFramework
8-
from test_framework.util import assert_equal, assert_array_result, assert_raises_rpc_error
8+
from test_framework.util import (
9+
assert_array_result,
10+
assert_equal,
11+
assert_raises_rpc_error,
12+
connect_nodes,
13+
)
914

10-
class ListSinceBlockTest (BitcoinTestFramework):
15+
16+
class ListSinceBlockTest(BitcoinTestFramework):
1117
def set_test_params(self):
1218
self.num_nodes = 4
1319
self.setup_clean_chain = True
@@ -16,6 +22,9 @@ def skip_test_if_missing_module(self):
1622
self.skip_if_no_wallet()
1723

1824
def run_test(self):
25+
# All nodes are in IBD from genesis, so they'll need the miner (node2) to be an outbound connection, or have
26+
# only one connection. (See fPreferredDownload in net_processing)
27+
connect_nodes(self.nodes[1], 2)
1928
self.nodes[2].generate(101)
2029
self.sync_all()
2130

0 commit comments

Comments
 (0)
Please sign in to comment.