Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | def parse_args(self): | ||||
parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | ||||
help="use bitcoin-cli instead of RPC for all commands") | help="use bitcoin-cli instead of RPC for all commands") | ||||
parser.add_argument("--perf", dest="perf", default=False, action="store_true", | parser.add_argument("--perf", dest="perf", default=False, action="store_true", | ||||
help="profile running nodes with perf for the duration of the test") | help="profile running nodes with perf for the duration of the test") | ||||
parser.add_argument("--valgrind", dest="valgrind", default=False, action="store_true", | parser.add_argument("--valgrind", dest="valgrind", default=False, action="store_true", | ||||
help="run nodes under the valgrind memory error detector: expect at least a ~10x slowdown, valgrind 3.14 or later required") | help="run nodes under the valgrind memory error detector: expect at least a ~10x slowdown, valgrind 3.14 or later required") | ||||
parser.add_argument("--randomseed", type=int, | parser.add_argument("--randomseed", type=int, | ||||
help="set a random seed for deterministically reproducing a previous test run") | help="set a random seed for deterministically reproducing a previous test run") | ||||
parser.add_argument("--descriptors", default=False, action="store_true", | |||||
help="Run test using a descriptor wallet") | |||||
parser.add_argument("--with-axionactivation", dest="axionactivation", default=False, action="store_true", | parser.add_argument("--with-axionactivation", dest="axionactivation", default=False, action="store_true", | ||||
help="Activate axion update on timestamp {}".format(TIMESTAMP_IN_THE_PAST)) | help="Activate axion update on timestamp {}".format(TIMESTAMP_IN_THE_PAST)) | ||||
parser.add_argument( | parser.add_argument( | ||||
'--timeout-factor', | '--timeout-factor', | ||||
dest="timeout_factor", | dest="timeout_factor", | ||||
type=float, | type=float, | ||||
default=1.0, | default=1.0, | ||||
help='adjust test timeouts by a factor. ' | help='adjust test timeouts by a factor. ' | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def setup_network(self): | ||||
# If further outbound connections are needed, they can be added at the beginning of the test with e.g. | # If further outbound connections are needed, they can be added at the beginning of the test with e.g. | ||||
# self.connect_nodes(1, 2) | # self.connect_nodes(1, 2) | ||||
for i in range(self.num_nodes - 1): | for i in range(self.num_nodes - 1): | ||||
self.connect_nodes(i + 1, i) | self.connect_nodes(i + 1, 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 = [[]] * self.num_nodes | ||||
wallets = [[]] * self.num_nodes | |||||
if hasattr(self, "extra_args"): | if hasattr(self, "extra_args"): | ||||
extra_args = self.extra_args | extra_args = self.extra_args | ||||
wallets = [[x for x in eargs if x.startswith( | |||||
'-wallet=')] for eargs in extra_args] | |||||
extra_args = [x + ['-nowallet'] for x in extra_args] | |||||
self.add_nodes(self.num_nodes, extra_args) | self.add_nodes(self.num_nodes, extra_args) | ||||
self.start_nodes() | self.start_nodes() | ||||
for i, n in enumerate(self.nodes): | |||||
n.extra_args.pop() | |||||
if '-wallet=0' in n.extra_args or '-nowallet' in n.extra_args or '-disablewallet' in n.extra_args or not self.is_wallet_compiled(): | |||||
continue | |||||
if '-wallet=' not in wallets[i] and not any( | |||||
[x.startswith('-wallet=') for x in wallets[i]]): | |||||
wallets[i].append('-wallet=') | |||||
for w in wallets[i]: | |||||
wallet_name = w.split('=', 1)[1] | |||||
n.createwallet( | |||||
wallet_name=wallet_name, | |||||
descriptors=self.options.descriptors) | |||||
self.import_deterministic_coinbase_privkeys() | self.import_deterministic_coinbase_privkeys() | ||||
if not self.setup_clean_chain: | if not self.setup_clean_chain: | ||||
for n in self.nodes: | for n in self.nodes: | ||||
assert_equal(n.getblockchaininfo()["blocks"], 199) | assert_equal(n.getblockchaininfo()["blocks"], 199) | ||||
# To ensure that all nodes are out of IBD, the most recent block | # To ensure that all nodes are out of IBD, the most recent block | ||||
# must have a timestamp not too old (see IsInitialBlockDownload()). | # must have a timestamp not too old (see IsInitialBlockDownload()). | ||||
self.log.debug('Generate a block with current time') | self.log.debug('Generate a block with current time') | ||||
block_hash = self.nodes[0].generate(1)[0] | block_hash = self.nodes[0].generate(1)[0] | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | def add_nodes(self, num_nodes: int, extra_args=None, | ||||
coverage_dir=self.options.coveragedir, | coverage_dir=self.options.coveragedir, | ||||
cwd=self.options.tmpdir, | cwd=self.options.tmpdir, | ||||
extra_conf=extra_confs[i], | extra_conf=extra_confs[i], | ||||
extra_args=extra_args[i], | extra_args=extra_args[i], | ||||
use_cli=self.options.usecli, | use_cli=self.options.usecli, | ||||
emulator=self.options.emulator, | emulator=self.options.emulator, | ||||
start_perf=self.options.perf, | start_perf=self.options.perf, | ||||
use_valgrind=self.options.valgrind, | use_valgrind=self.options.valgrind, | ||||
descriptors=self.options.descriptors, | |||||
)) | )) | ||||
if self.options.axionactivation: | if self.options.axionactivation: | ||||
self.nodes[i].extend_default_args( | self.nodes[i].extend_default_args( | ||||
["-axionactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ["-axionactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ||||
def start_node(self, i, *args, **kwargs): | def start_node(self, i, *args, **kwargs): | ||||
"""Start a bitcoind""" | """Start a bitcoind""" | ||||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | def _initialize_chain(self): | ||||
p2p_port=p2p_port(CACHE_NODE_ID), | p2p_port=p2p_port(CACHE_NODE_ID), | ||||
timewait=self.rpc_timeout, | timewait=self.rpc_timeout, | ||||
timeout_factor=self.options.timeout_factor, | timeout_factor=self.options.timeout_factor, | ||||
bitcoind=self.options.bitcoind, | bitcoind=self.options.bitcoind, | ||||
bitcoin_cli=self.options.bitcoincli, | bitcoin_cli=self.options.bitcoincli, | ||||
coverage_dir=None, | coverage_dir=None, | ||||
cwd=self.options.tmpdir, | cwd=self.options.tmpdir, | ||||
emulator=self.options.emulator, | emulator=self.options.emulator, | ||||
descriptors=self.options.descriptors, | |||||
)) | )) | ||||
if self.options.axionactivation: | if self.options.axionactivation: | ||||
self.nodes[CACHE_NODE_ID].extend_default_args( | self.nodes[CACHE_NODE_ID].extend_default_args( | ||||
["-axionactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ["-axionactivationtime={}".format(TIMESTAMP_IN_THE_PAST)]) | ||||
self.start_node(CACHE_NODE_ID) | self.start_node(CACHE_NODE_ID) | ||||
cache_node = self.nodes[CACHE_NODE_ID] | cache_node = self.nodes[CACHE_NODE_ID] | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |