Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | def disconnect_nodes(from_connection, node_num): | ||||
for _ in range(50): | for _ in range(50): | ||||
if [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == []: | if [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == []: | ||||
break | break | ||||
time.sleep(0.1) | time.sleep(0.1) | ||||
else: | else: | ||||
raise AssertionError("timed out waiting for disconnect") | raise AssertionError("timed out waiting for disconnect") | ||||
def connect_nodes(from_connection, node_num): | def connect_nodes(from_node, to_node): | ||||
ip_port = "127.0.0.1:" + str(p2p_port(node_num)) | ip_port = "127.0.0.1:" + str(p2p_port(to_node.index)) | ||||
from_connection.addnode(ip_port, "onetry") | from_node.addnode(ip_port, "onetry") | ||||
# poll until version handshake complete to avoid race conditions | # poll until version handshake complete to avoid race conditions | ||||
# with transaction relaying | # with transaction relaying | ||||
while any(peer['version'] == 0 for peer in from_connection.getpeerinfo()): | while any(peer['version'] == 0 for peer in from_node.getpeerinfo()): | ||||
time.sleep(0.1) | time.sleep(0.1) | ||||
def connect_nodes_bi(nodes, a, b): | def connect_nodes_bi(nodes, a, b): | ||||
connect_nodes(nodes[a], b) | connect_nodes(nodes[a], nodes[b]) | ||||
connect_nodes(nodes[b], a) | connect_nodes(nodes[b], nodes[a]) | ||||
def sync_blocks(rpc_connections, *, wait=1, timeout=60): | def sync_blocks(rpc_connections, *, 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 | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |