Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | def p2p_port(n): | ||||
assert(n <= MAX_NODES) | assert(n <= MAX_NODES) | ||||
return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | ||||
def rpc_port(n): | def rpc_port(n): | ||||
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | ||||
def rpc_url(datadir, i, rpchost=None): | def rpc_url(datadir, i, rpchost, rpc_port): | ||||
rpc_u, rpc_p = get_auth_cookie(datadir) | rpc_u, rpc_p = get_auth_cookie(datadir) | ||||
host = '127.0.0.1' | host = '127.0.0.1' | ||||
port = rpc_port(i) | |||||
if rpchost: | if rpchost: | ||||
parts = rpchost.split(':') | |||||
if len(parts) == 2: | |||||
host, port = parts | |||||
else: | |||||
host = rpchost | host = rpchost | ||||
return "http://%s:%s@%s:%d" % (rpc_u, rpc_p, host, int(port)) | return "http://%s:%s@%s:%d" % (rpc_u, rpc_p, host, int(rpc_port)) | ||||
# Node functions | # Node functions | ||||
################ | ################ | ||||
def initialize_datadir(dirname, n): | def initialize_datadir(dirname, n): | ||||
datadir = os.path.join(dirname, "node" + str(n)) | datadir = os.path.join(dirname, "node" + str(n)) | ||||
if not os.path.isdir(datadir): | if not os.path.isdir(datadir): | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def get_bip9_status(node, key): | ||||
return info['bip9_softforks'][key] | return info['bip9_softforks'][key] | ||||
def set_node_times(nodes, t): | def set_node_times(nodes, t): | ||||
for node in nodes: | for node in nodes: | ||||
node.setmocktime(t) | node.setmocktime(t) | ||||
def disconnect_nodes(from_connection, node_num): | def disconnect_nodes(from_connection, node): | ||||
for peer_id in [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']]: | for peer_id in [peer['id'] for peer in from_connection.getpeerinfo() if node.nodename in peer['subver']]: | ||||
from_connection.disconnectnode(nodeid=peer_id) | from_connection.disconnectnode(nodeid=peer_id) | ||||
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 node.nodename 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_connection, node): | ||||
ip_port = "127.0.0.1:" + str(p2p_port(node_num)) | ip_port = "{}:{}".format(node.host, node.p2p_port) | ||||
from_connection.addnode(ip_port, "onetry") | from_connection.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_connection.getpeerinfo()): | ||||
time.sleep(0.1) | time.sleep(0.1) | ||||
def connect_nodes_bi(nodes, a, b): | def connect_nodes_bi(a, b): | ||||
connect_nodes(nodes[a], b) | connect_nodes(a, b) | ||||
connect_nodes(nodes[b], a) | connect_nodes(b, 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 |