Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show All 16 Lines | |||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from . import coverage | from . import coverage | ||||
from .test_node import TestNode | from .test_node import TestNode | ||||
from .mininode import NetworkThread | from .mininode import NetworkThread | ||||
from .util import ( | from .util import ( | ||||
assert_equal, | assert_equal, | ||||
check_json_precision, | check_json_precision, | ||||
connect_nodes_bi, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
get_datadir_path, | get_datadir_path, | ||||
initialize_datadir, | initialize_datadir, | ||||
MAX_NODES, | MAX_NODES, | ||||
p2p_port, | p2p_port, | ||||
PortSeed, | PortSeed, | ||||
rpc_port, | rpc_port, | ||||
sync_blocks, | sync_blocks, | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): | ||||
def setup_network(self): | def setup_network(self): | ||||
"""Override this method to customize test network topology""" | """Override this method to customize test network topology""" | ||||
self.setup_nodes() | self.setup_nodes() | ||||
# Connect the nodes as a "chain". This allows us | # Connect the nodes as a "chain". This allows us | ||||
# to split the network between nodes 1 and 2 to get | # to split the network between nodes 1 and 2 to get | ||||
# two halves that can work on competing chains. | # two halves that can work on competing chains. | ||||
# | |||||
# Topology looks like this: | |||||
# 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 | |||||
# ensure block propagation, all nodes will establish outgoing connections toward node0. | |||||
# See fPreferredDownload in net_processing. | |||||
# | |||||
# 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) | |||||
for i in range(self.num_nodes - 1): | for i in range(self.num_nodes - 1): | ||||
connect_nodes_bi(self.nodes[i], self.nodes[i + 1]) | connect_nodes(self.nodes[i + 1], self.nodes[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 133 Lines • ▼ Show 20 Lines | def split_network(self): | ||||
disconnect_nodes(self.nodes[2], self.nodes[1]) | disconnect_nodes(self.nodes[2], self.nodes[1]) | ||||
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_bi(self.nodes[1], self.nodes[2]) | connect_nodes(self.nodes[1], self.nodes[2]) | ||||
self.sync_all() | self.sync_all() | ||||
def sync_blocks(self, nodes=None, **kwargs): | def sync_blocks(self, nodes=None, **kwargs): | ||||
sync_blocks(nodes or self.nodes, **kwargs) | sync_blocks(nodes or self.nodes, **kwargs) | ||||
def sync_mempools(self, nodes=None, **kwargs): | def sync_mempools(self, nodes=None, **kwargs): | ||||
sync_mempools(nodes or self.nodes, **kwargs) | sync_mempools(nodes or self.nodes, **kwargs) | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |