|
|
@ -19,12 +19,15 @@ import tempfile |
|
|
|
import time |
|
|
|
import time |
|
|
|
import re |
|
|
|
import re |
|
|
|
import errno |
|
|
|
import errno |
|
|
|
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
from . import coverage |
|
|
|
from . import coverage |
|
|
|
from .authproxy import AuthServiceProxy, JSONRPCException |
|
|
|
from .authproxy import AuthServiceProxy, JSONRPCException |
|
|
|
|
|
|
|
|
|
|
|
COVERAGE_DIR = None |
|
|
|
COVERAGE_DIR = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("TestFramework.utils") |
|
|
|
|
|
|
|
|
|
|
|
# The maximum number of nodes a single test can spawn |
|
|
|
# The maximum number of nodes a single test can spawn |
|
|
|
MAX_NODES = 8 |
|
|
|
MAX_NODES = 8 |
|
|
|
# Don't assign rpc or p2p ports lower than this |
|
|
|
# Don't assign rpc or p2p ports lower than this |
|
|
@ -237,6 +240,7 @@ def initialize_chain(test_dir, num_nodes, cachedir): |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
if create_cache: |
|
|
|
if create_cache: |
|
|
|
|
|
|
|
logger.debug("Creating data directories from cached datadir") |
|
|
|
|
|
|
|
|
|
|
|
#find and delete old cache directories if any exist |
|
|
|
#find and delete old cache directories if any exist |
|
|
|
for i in range(MAX_NODES): |
|
|
|
for i in range(MAX_NODES): |
|
|
@ -250,11 +254,9 @@ def initialize_chain(test_dir, num_nodes, cachedir): |
|
|
|
if i > 0: |
|
|
|
if i > 0: |
|
|
|
args.append("-connect=127.0.0.1:"+str(p2p_port(0))) |
|
|
|
args.append("-connect=127.0.0.1:"+str(p2p_port(0))) |
|
|
|
bitcoind_processes[i] = subprocess.Popen(args) |
|
|
|
bitcoind_processes[i] = subprocess.Popen(args) |
|
|
|
if os.getenv("PYTHON_DEBUG", ""): |
|
|
|
logger.debug("initialize_chain: bitcoind started, waiting for RPC to come up") |
|
|
|
print("initialize_chain: bitcoind started, waiting for RPC to come up") |
|
|
|
|
|
|
|
wait_for_bitcoind_start(bitcoind_processes[i], rpc_url(i), i) |
|
|
|
wait_for_bitcoind_start(bitcoind_processes[i], rpc_url(i), i) |
|
|
|
if os.getenv("PYTHON_DEBUG", ""): |
|
|
|
logger.debug("initialize_chain: RPC successfully started") |
|
|
|
print("initialize_chain: RPC successfully started") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rpcs = [] |
|
|
|
rpcs = [] |
|
|
|
for i in range(MAX_NODES): |
|
|
|
for i in range(MAX_NODES): |
|
|
@ -316,12 +318,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= |
|
|
|
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-mocktime="+str(get_mocktime()) ] |
|
|
|
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-mocktime="+str(get_mocktime()) ] |
|
|
|
if extra_args is not None: args.extend(extra_args) |
|
|
|
if extra_args is not None: args.extend(extra_args) |
|
|
|
bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr) |
|
|
|
bitcoind_processes[i] = subprocess.Popen(args, stderr=stderr) |
|
|
|
if os.getenv("PYTHON_DEBUG", ""): |
|
|
|
logger.debug("initialize_chain: bitcoind started, waiting for RPC to come up") |
|
|
|
print("start_node: bitcoind started, waiting for RPC to come up") |
|
|
|
|
|
|
|
url = rpc_url(i, rpchost) |
|
|
|
url = rpc_url(i, rpchost) |
|
|
|
wait_for_bitcoind_start(bitcoind_processes[i], url, i) |
|
|
|
wait_for_bitcoind_start(bitcoind_processes[i], url, i) |
|
|
|
if os.getenv("PYTHON_DEBUG", ""): |
|
|
|
logger.debug("initialize_chain: RPC successfully started") |
|
|
|
print("start_node: RPC successfully started") |
|
|
|
|
|
|
|
proxy = get_rpc_proxy(url, i, timeout=timewait) |
|
|
|
proxy = get_rpc_proxy(url, i, timeout=timewait) |
|
|
|
|
|
|
|
|
|
|
|
if COVERAGE_DIR: |
|
|
|
if COVERAGE_DIR: |
|
|
@ -367,10 +367,11 @@ def log_filename(dirname, n_node, logname): |
|
|
|
return os.path.join(dirname, "node"+str(n_node), "regtest", logname) |
|
|
|
return os.path.join(dirname, "node"+str(n_node), "regtest", logname) |
|
|
|
|
|
|
|
|
|
|
|
def stop_node(node, i): |
|
|
|
def stop_node(node, i): |
|
|
|
|
|
|
|
logger.debug("Stopping node %d" % i) |
|
|
|
try: |
|
|
|
try: |
|
|
|
node.stop() |
|
|
|
node.stop() |
|
|
|
except http.client.CannotSendRequest as e: |
|
|
|
except http.client.CannotSendRequest as e: |
|
|
|
print("WARN: Unable to stop node: " + repr(e)) |
|
|
|
logger.exception("Unable to stop node") |
|
|
|
return_code = bitcoind_processes[i].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT) |
|
|
|
return_code = bitcoind_processes[i].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT) |
|
|
|
assert_equal(return_code, 0) |
|
|
|
assert_equal(return_code, 0) |
|
|
|
del bitcoind_processes[i] |
|
|
|
del bitcoind_processes[i] |
|
|
|