Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | def setup_network(self): | ||||
# Topology looks like this: | # Topology looks like this: | ||||
# node0 <-- node1 <-- node2 <-- node3 | # node0 <-- node1 <-- node2 <-- node3 | ||||
# | # | ||||
# If all nodes are in IBD (clean chain from genesis), node0 is assumed to be the source of blocks (miner). To | # If all nodes are in IBD (clean chain from genesis), node0 is assumed to be the source of blocks (miner). To | ||||
# ensure block propagation, all nodes will establish outgoing connections toward node0. | # ensure block propagation, all nodes will establish outgoing connections toward node0. | ||||
# See fPreferredDownload in net_processing. | # See fPreferredDownload in net_processing. | ||||
# | # | ||||
# If further outbound connections are needed, they can be added at the beginning of the test with e.g. | # If further outbound connections are needed, they can be added at the beginning of the test with e.g. | ||||
# connect_nodes(self.nodes[1], 2) | # self.connect_nodes(1, 2) | ||||
for i in range(self.num_nodes - 1): | for i in range(self.num_nodes - 1): | ||||
connect_nodes(self.nodes[i + 1], self.nodes[i]) | self.connect_nodes(i + 1, i) | ||||
self.sync_all() | self.sync_all() | ||||
def setup_nodes(self): | def setup_nodes(self): | ||||
"""Override this method to customize test node setup""" | """Override this method to customize test node setup""" | ||||
extra_args = None | extra_args = None | ||||
if hasattr(self, "extra_args"): | if hasattr(self, "extra_args"): | ||||
extra_args = self.extra_args | extra_args = self.extra_args | ||||
self.add_nodes(self.num_nodes, extra_args) | self.add_nodes(self.num_nodes, extra_args) | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): | ||||
def restart_node(self, i, extra_args=None): | def restart_node(self, i, extra_args=None): | ||||
"""Stop and start a test node""" | """Stop and start a test node""" | ||||
self.stop_node(i) | self.stop_node(i) | ||||
self.start_node(i, extra_args) | self.start_node(i, extra_args) | ||||
def wait_for_node_exit(self, i, timeout): | def wait_for_node_exit(self, i, timeout): | ||||
self.nodes[i].process.wait(timeout) | self.nodes[i].process.wait(timeout) | ||||
def connect_nodes(self, a, b): | |||||
connect_nodes(self.nodes[a], self.nodes[b]) | |||||
def disconnect_nodes(self, a, b): | |||||
disconnect_nodes(self.nodes[a], self.nodes[b]) | |||||
def split_network(self): | def split_network(self): | ||||
""" | """ | ||||
Split the network of four nodes into nodes 0/1 and 2/3. | Split the network of four nodes into nodes 0/1 and 2/3. | ||||
""" | """ | ||||
disconnect_nodes(self.nodes[1], self.nodes[2]) | self.disconnect_nodes(1, 2) | ||||
self.sync_all(self.nodes[:2]) | self.sync_all(self.nodes[:2]) | ||||
self.sync_all(self.nodes[2:]) | self.sync_all(self.nodes[2:]) | ||||
def join_network(self): | def join_network(self): | ||||
""" | """ | ||||
Join the (previously split) network halves together. | Join the (previously split) network halves together. | ||||
""" | """ | ||||
connect_nodes(self.nodes[1], self.nodes[2]) | self.connect_nodes(1, 2) | ||||
self.sync_all() | self.sync_all() | ||||
def sync_blocks(self, nodes=None, wait=1, timeout=60): | def sync_blocks(self, nodes=None, wait=1, timeout=60): | ||||
""" | """ | ||||
Wait until everybody has the same tip. | Wait until everybody has the same tip. | ||||
sync_blocks needs to be called with an rpc_connections set that has least | sync_blocks needs to be called with an rpc_connections set that has least | ||||
one node already synced to the latest, stable tip, otherwise there's a | one node already synced to the latest, stable tip, otherwise there's a | ||||
chance it might return before all nodes are stably synced. | chance it might return before all nodes are stably synced. | ||||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |