From efc8c99139659695ebfff2139645f92b8055b2f4 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 1 Nov 2024 15:25:14 +0300 Subject: [PATCH] refactor: Introduce `get_chain_conf_names` --- .../test_framework/test_framework.py | 15 ++------- test/functional/test_framework/util.py | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 024ab330ef..a9a063b593 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -48,6 +48,7 @@ from .util import ( check_json_precision, copy_datadir, force_finish_mnsync, + get_chain_conf_names, get_datadir_path, initialize_datadir, p2p_port, @@ -610,19 +611,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): if entry not in ['chainstate', 'blocks', 'indexes', 'evodb']: os.remove(os.path.join(new_data_dir, self.chain, entry)) - # Translate chain name to config name - if self.chain == 'testnet3': - chain_name_conf_arg = 'testnet' - chain_name_conf_section = 'test' - chain_name_conf_arg_value = '1' - elif self.chain == 'devnet': - chain_name_conf_arg = 'devnet' - chain_name_conf_section = 'devnet' - chain_name_conf_arg_value = 'devnet1' - else: - chain_name_conf_arg = self.chain - chain_name_conf_section = self.chain - chain_name_conf_arg_value = '1' + (chain_name_conf_arg, chain_name_conf_arg_value, chain_name_conf_section) = get_chain_conf_names(self.chain) with open(os.path.join(new_data_dir, "dash.conf"), 'w', encoding='utf8') as f: f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value)) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 9b427cf40b..54578d6cce 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -381,19 +381,7 @@ def initialize_datadir(dirname, n, chain): def write_config(config_path, *, n, chain, extra_config=""): - # Translate chain subdirectory name to config name - if chain == 'testnet3': - chain_name_conf_arg = 'testnet' - chain_name_conf_section = 'test' - chain_name_conf_arg_value = '1' - elif chain == 'devnet': - chain_name_conf_arg = 'devnet' - chain_name_conf_section = 'devnet' - chain_name_conf_arg_value = 'devnet1' - else: - chain_name_conf_arg = chain - chain_name_conf_section = chain - chain_name_conf_arg_value = '1' + (chain_name_conf_arg, chain_name_conf_arg_value, chain_name_conf_section) = get_chain_conf_names(chain) with open(config_path, 'w', encoding='utf8') as f: if chain_name_conf_arg: f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value)) @@ -494,6 +482,24 @@ def get_chain_folder(datadir, chain): pass return chain +def get_chain_conf_names(chain): + """ + Translate chain name to config names + """ + if chain == 'testnet3': + arg = 'testnet' + value = '1' + section = 'test' + elif chain == 'devnet': + arg = 'devnet' + value = 'devnet1' + section = 'devnet' + else: + arg = chain + value = '1' + section = chain + return (arg, value, section) + def get_bip9_details(node, key): """Return extra info about bip9 softfork""" return node.getblockchaininfo()['softforks'][key]['bip9']