Skip to content

Commit

Permalink
MERGE FIX: Adapt bitcoin_functional sync to regtest2
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Jan 31, 2019
1 parent 7c97d6a commit 9d9ee3d
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 200 deletions.
1 change: 1 addition & 0 deletions test/bitcoin_functional/functional/combine_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def main():
parser = argparse.ArgumentParser(usage='%(prog)s [options] <test temporary directory>', description=__doc__)
parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2')
parser.add_argument('--chain', dest='chain', help='selected chain in the tests (default: regtest2)', default='regtest2')
args, unknown_args = parser.parse_known_args()

if args.color and os.name != 'posix':
Expand Down
270 changes: 135 additions & 135 deletions test/bitcoin_functional/functional/data/rpc_getblockstats.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/bitcoin_functional/functional/feature_blocksdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def skip_test_if_missing_module(self):
def run_test(self):
self.stop_node(0)
shutil.rmtree(self.nodes[0].datadir)
initialize_datadir(self.options.tmpdir, 0)
initialize_datadir(self.options.tmpdir, 0, self.chain)
self.log.info("Starting with nonexistent blocksdir ...")
blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir')
self.nodes[0].assert_start_raises_init_error(["-blocksdir=" + blocksdir_path], 'Error: Specified blocks directory "{}" does not exist.'.format(blocksdir_path))
Expand All @@ -31,8 +31,8 @@ def run_test(self):
self.start_node(0, ["-blocksdir=" + blocksdir_path])
self.log.info("mining blocks..")
self.nodes[0].generate(10)
assert os.path.isfile(os.path.join(blocksdir_path, "regtest", "blocks", "blk00000.dat"))
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks", "index"))
assert os.path.isfile(os.path.join(blocksdir_path, "regtest2", "blocks", "blk00000.dat"))
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest2", "blocks", "index"))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/bitcoin_functional/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_test(self):
os.mkdir(new_data_dir_2)
self.nodes[0].datadir = new_data_dir_2
self.start_node(0, ['-datadir='+new_data_dir_2, '-conf='+conf_file, '-wallet=w2'])
assert os.path.exists(os.path.join(new_data_dir_2, 'regtest', 'wallets', 'w2'))
assert os.path.exists(os.path.join(new_data_dir_2, 'regtest2', 'wallets', 'w2'))

if __name__ == '__main__':
ConfArgsTest().main()
2 changes: 1 addition & 1 deletion test/bitcoin_functional/functional/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def relative_log_path(self, name):
return os.path.join(self.nodes[0].datadir, "regtest", name)
return os.path.join(self.nodes[0].datadir, "regtest2", name)

def run_test(self):
# test default log file name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run_test(self):
rpc_response = self.nodes[0].getblockchaininfo()
assert_equal(cli_response, rpc_response)

user, password = get_auth_cookie(self.nodes[0].datadir)
user, password = get_auth_cookie(self.nodes[0].datadir, self.chain)

self.log.info("Test -stdinrpcpass option")
assert_equal(0, self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input=password).getblockcount())
Expand Down
4 changes: 2 additions & 2 deletions test/bitcoin_functional/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def run_test(self):
self.start_node(0)
wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)

mempooldat0 = os.path.join(self.nodes[0].datadir, 'regtest', 'mempool.dat')
mempooldat1 = os.path.join(self.nodes[1].datadir, 'regtest', 'mempool.dat')
mempooldat0 = os.path.join(self.nodes[0].datadir, 'regtest2', 'mempool.dat')
mempooldat1 = os.path.join(self.nodes[1].datadir, 'regtest2', 'mempool.dat')
self.log.debug("Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it")
os.remove(mempooldat0)
self.nodes[0].savemempool()
Expand Down
2 changes: 1 addition & 1 deletion test/bitcoin_functional/functional/mining_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
self.log.info('getmininginfo')
mining_info = node.getmininginfo()
assert_equal(mining_info['blocks'], 200)
assert_equal(mining_info['chain'], 'regtest')
assert_equal(mining_info['chain'], 'regtest2')
assert_equal(mining_info['currentblocktx'], 0)
assert_equal(mining_info['currentblockweight'], 0)
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))
Expand Down
2 changes: 1 addition & 1 deletion test/bitcoin_functional/functional/rpc_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_allowip_test(self, allow_ips, rpchost, rpcport):
self.nodes[0].rpchost = None
self.start_nodes([base_args])
# connect to node through non-loopback interface
node = get_rpc_proxy(rpc_url(self.nodes[0].datadir, 0, "%s:%d" % (rpchost, rpcport)), 0, coveragedir=self.options.coveragedir)
node = get_rpc_proxy(rpc_url(self.nodes[0].datadir, 0, "regtest2","%s:%d" % (rpchost, rpcport)), 0, coveragedir=self.options.coveragedir)
node.getnetworkinfo()
self.stop_nodes()

Expand Down
2 changes: 1 addition & 1 deletion test/bitcoin_functional/functional/rpc_scantxoutset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_test(self):

self.log.info("Stop node, remove wallet, mine again some blocks...")
self.stop_node(0)
shutil.rmtree(os.path.join(self.nodes[0].datadir, "regtest", 'wallets'))
shutil.rmtree(os.path.join(self.nodes[0].datadir, "regtest2", 'wallets'))
self.start_node(0)
self.nodes[0].generate(110)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):

def __init__(self):
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
self.chain = 'regtest2'
self.setup_clean_chain = False
self.nodes = []
self.network_thread = None
Expand Down Expand Up @@ -120,7 +121,7 @@ def main(self):
parser.add_argument("--coveragedir", dest="coveragedir",
help="Write tested RPC commands into this directory")
parser.add_argument("--configfile", dest="configfile",
default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../../config.ini"),
help="Location of the test framework config file (default: %(default)s)")
parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
help="Attach a python debugger if test fails")
Expand Down Expand Up @@ -293,7 +294,7 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None):
assert_equal(len(extra_args), num_nodes)
assert_equal(len(binary), num_nodes)
for i in range(num_nodes):
self.nodes.append(TestNode(i, get_datadir_path(self.options.tmpdir, i), rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
self.nodes.append(TestNode(i, get_datadir_path(self.options.tmpdir, i), self.chain, rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))

def start_node(self, i, *args, **kwargs):
"""Start a bitcoind"""
Expand Down Expand Up @@ -440,11 +441,11 @@ def _initialize_chain(self):

# Create cache directories, run bitcoinds:
for i in range(MAX_NODES):
datadir = initialize_datadir(self.options.cachedir, i)
datadir = initialize_datadir(self.options.cachedir, i, self.chain)
args = [self.options.bitcoind, "-datadir=" + datadir, '-disablewallet']
if i > 0:
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[], rpchost=None, timewait=self.rpc_timewait, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None))
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), self.chain, extra_conf=["bind=127.0.0.1"], extra_args=[], rpchost=None, timewait=self.rpc_timewait, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None))
self.nodes[i].args = args
self.start_node(i)

Expand Down Expand Up @@ -476,7 +477,7 @@ def _initialize_chain(self):
self.disable_mocktime()

def cache_path(n, *paths):
return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths)
return os.path.join(get_datadir_path(self.options.cachedir, n), self.chain, *paths)

for i in range(MAX_NODES):
os.rmdir(cache_path(i, 'wallets')) # Remove empty wallets dir
Expand All @@ -488,15 +489,15 @@ def cache_path(n, *paths):
from_dir = get_datadir_path(self.options.cachedir, i)
to_dir = get_datadir_path(self.options.tmpdir, i)
shutil.copytree(from_dir, to_dir)
initialize_datadir(self.options.tmpdir, i) # Overwrite port/rpcport in bitcoin.conf
initialize_datadir(self.options.tmpdir, i, self.chain) # Overwrite port/rpcport in bitcoin.conf

def _initialize_chain_clean(self):
"""Initialize empty blockchain for use by the test.
Create an empty blockchain and num_nodes wallets.
Useful if a test case wants complete control over initialization."""
for i in range(self.num_nodes):
initialize_datadir(self.options.tmpdir, i)
initialize_datadir(self.options.tmpdir, i, self.chain)

def skip_if_no_py3_zmq(self):
"""Attempt to import the zmq package and skip the test if the import fails."""
Expand Down
18 changes: 10 additions & 8 deletions test/bitcoin_functional/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ class TestNode():
To make things easier for the test writer, any unrecognised messages will
be dispatched to the RPC connection."""

def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
def __init__(self, i, datadir, chain, *, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
self.index = i
self.datadir = datadir
self.stdout_dir = os.path.join(self.datadir, "stdout")
self.stderr_dir = os.path.join(self.datadir, "stderr")
self.chain = chain
self.rpchost = rpchost
self.rpc_timeout = timewait
self.binary = bitcoind
Expand All @@ -84,7 +85,7 @@ def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mock
"-uacomment=testnode%d" % i
]

self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
self.cli = TestNodeCLI(bitcoin_cli, self.datadir, self.chain)
self.use_cli = use_cli

self.running = False
Expand Down Expand Up @@ -155,7 +156,7 @@ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
# Delete any existing cookie file -- if such a file exists (eg due to
# unclean shutdown), it will get overwritten anyway by bitcoind, and
# potentially interfere with our attempt to authenticate
delete_cookie_file(self.datadir)
delete_cookie_file(self.datadir, self.chain)

# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
Expand All @@ -174,7 +175,7 @@ def wait_for_rpc_connection(self):
raise FailedToStartError(self._node_msg(
'bitcoind exited with status {} during initialization'.format(self.process.returncode)))
try:
self.rpc = get_rpc_proxy(rpc_url(self.datadir, self.index, self.rpchost), self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir)
self.rpc = get_rpc_proxy(rpc_url(self.datadir, self.index, self.chain, self.rpchost), self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir)
self.rpc.getblockcount()
# If the call to getblockcount() succeeds then the RPC connection is up
self.rpc_connected = True
Expand Down Expand Up @@ -248,7 +249,7 @@ def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):

@contextlib.contextmanager
def assert_debug_log(self, expected_msgs):
debug_log = os.path.join(self.datadir, 'regtest', 'debug.log')
debug_log = os.path.join(self.datadir, self.chain, 'debug.log')
with open(debug_log, encoding='utf-8') as dl:
dl.seek(0, 2)
prev_size = dl.tell()
Expand Down Expand Up @@ -351,16 +352,17 @@ def get_request(self, *args, **kwargs):
class TestNodeCLI():
"""Interface to bitcoin-cli for an individual node"""

def __init__(self, binary, datadir):
def __init__(self, binary, datadir, chain):
self.options = []
self.binary = binary
self.datadir = datadir
self.chain = chain
self.input = None
self.log = logging.getLogger('TestFramework.bitcoincli')

def __call__(self, *options, input=None):
# TestNodeCLI is callable with bitcoin-cli command-line options
cli = TestNodeCLI(self.binary, self.datadir)
cli = TestNodeCLI(self.binary, self.datadir, self.chain)
cli.options = [str(o) for o in options]
cli.input = input
return cli
Expand All @@ -382,7 +384,7 @@ def send_cli(self, command=None, *args, **kwargs):
pos_args = [str(arg).lower() if type(arg) is bool else str(arg) for arg in args]
named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()]
assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call"
p_args = [self.binary, "-datadir=" + self.datadir] + self.options
p_args = [self.binary, "-datadir=" + self.datadir, "-chain=" + self.chain] + self.options
if named_args:
p_args += ["-named"]
if command is not None:
Expand Down
34 changes: 23 additions & 11 deletions test/bitcoin_functional/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ def p2p_port(n):
def rpc_port(n):
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)

def rpc_url(datadir, i, rpchost=None):
rpc_u, rpc_p = get_auth_cookie(datadir)
def rpc_url(datadir, i, chain, rpchost=None):
rpc_u, rpc_p = get_auth_cookie(datadir, chain)
host = '127.0.0.1'
port = rpc_port(i)
if rpchost:
Expand All @@ -288,20 +288,32 @@ def rpc_url(datadir, i, rpchost=None):
# Node functions
################

def initialize_datadir(dirname, n):
def initialize_datadir(dirname, n, chain):
datadir = get_datadir_path(dirname, n)
if not os.path.isdir(datadir):
os.makedirs(datadir)
with open(os.path.join(datadir, "bitcoin.conf"), 'w', encoding='utf8') as f:
f.write("regtest=1\n")
f.write("[regtest]\n")
f.write("chain=%s\n" % chain)
f.write("[%s]\n" % chain)
f.write("port=" + str(p2p_port(n)) + "\n")
f.write("rpcport=" + str(rpc_port(n)) + "\n")
f.write("server=1\n")
f.write("keypool=1\n")
f.write("discover=0\n")
f.write("listenonion=0\n")
f.write("printtoconsole=0\n")
# Elements:
f.write("con_blocksubsidy=5000000000\n")
f.write("con_connect_coinbase=0\n")
f.write("anyonecanspendaremine=0\n")
f.write("con_blockheightinheader=0\n")
f.write("con_signed_blocks=0\n")
f.write("multi_data_permitted=0\n")
f.write("walletrbf=0\n") # Default is 1 in Elements
f.write("con_bip34height=100000000\n")
f.write("con_bip65height=1351\n")
f.write("con_bip66height=1251\n")
f.write("con_genesis_style=bitcoin\n")
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
return datadir
Expand All @@ -314,7 +326,7 @@ def append_config(datadir, options):
for option in options:
f.write(option + "\n")

def get_auth_cookie(datadir):
def get_auth_cookie(datadir, chain):
user = None
password = None
if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
Expand All @@ -326,8 +338,8 @@ def get_auth_cookie(datadir):
if line.startswith("rpcpassword="):
assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n")
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f:
if os.path.isfile(os.path.join(datadir, chain, ".cookie")):
with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
userpass = f.read()
split_userpass = userpass.split(':')
user = split_userpass[0]
Expand All @@ -337,10 +349,10 @@ def get_auth_cookie(datadir):
return user, password

# If a cookie file exists in the given datadir, delete it.
def delete_cookie_file(datadir):
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
def delete_cookie_file(datadir, chain):
if os.path.isfile(os.path.join(datadir, chain, ".cookie")):
logger.debug("Deleting leftover cookie file")
os.remove(os.path.join(datadir, "regtest", ".cookie"))
os.remove(os.path.join(datadir, chain, ".cookie"))

def get_bip9_status(node, key):
info = node.getblockchaininfo()
Expand Down
8 changes: 4 additions & 4 deletions test/bitcoin_functional/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def main():

# Read config generated by configure.
config = configparser.ConfigParser()
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../../config.ini"
config.read_file(open(configfile, encoding="utf8"))

passon_args.append("--configfile=%s" % configfile)
Expand Down Expand Up @@ -279,7 +279,7 @@ def main():
if args.help:
# Print help for test_runner.py, then print help of the first script (with args removed) and exit.
parser.print_help()
subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'functional', test_list[0].split()[0]), '-h'])
subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'bitcoin_functional', 'functional', test_list[0].split()[0]), '-h'])
sys.exit(0)

check_script_list(config["environment"]["SRCDIR"])
Expand Down Expand Up @@ -315,7 +315,7 @@ def run_tests(test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=Fal
if os.path.isdir(cache_dir):
print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % (BOLD[1], BOLD[0], cache_dir))

tests_dir = src_dir + '/test/functional/'
tests_dir = src_dir + '/test/bitcoin_functional/functional/'

flags = ['--cachedir={}'.format(cache_dir)] + args

Expand Down Expand Up @@ -531,7 +531,7 @@ def check_script_list(src_dir):
Check that there are no scripts in the functional tests directory which are
not being run by pull-tester.py."""
script_dir = src_dir + '/test/functional/'
script_dir = src_dir + '/test/bitcoin_functional/functional/'
python_files = set([test_file for test_file in os.listdir(script_dir) if test_file.endswith(".py")])
missed_tests = list(python_files - set(map(lambda x: x.split()[0], ALL_SCRIPTS + NON_SCRIPTS)))
if len(missed_tests) != 0:
Expand Down
Loading

0 comments on commit 9d9ee3d

Please sign in to comment.