Skip to content

Commit

Permalink
Merge bitcoin#17556: test: Change feature_config_args.py not to rely …
Browse files Browse the repository at this point in the history
…on strange regtest=0 behavior

ff44cae test: Change feature_config_args.py not to rely on strange regtest=0 behavior (Russell Yanofsky)

Pull request description:

  Update test to simply generate a normal mainnet configuration file instead of using a crazy setup where a regtest=1 config file using an includeconf in the [regtest] section includes another config file that specifies regtest=0, retroactively switching the network to mainnet.

  This setup was fragile and only worked because the triggered InitError happened early enough that none of the ignored [regtest] options mattered (only affecting log output).

  This change was originally made as part of bitcoin#17493

Top commit has no ACKs.

Tree-SHA512: 3f77305454f04438493dfc2abd78a00434b30869454d1c3f54587b9c1f63239c49c90fb3b4d3a777ad130f2184e0f2dac87cee4cd23c50f1b3496a375943da01
  • Loading branch information
MarcoFalke authored and vijaydasmp committed Nov 9, 2023
1 parent 8022b44 commit b6de87d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions test/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os

from test_framework.test_framework import BitcoinTestFramework
from test_framework import util


class ConfArgsTest(BitcoinTestFramework):
Expand Down Expand Up @@ -42,10 +43,11 @@ def test_config_file_parser(self):
conf.write("wallet=foo\n")
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Config setting for -wallet only applied on %s network when in [%s] section.' % (self.chain, self.chain))

main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_main.conf')
util.write_config(main_conf_file_path, n=0, chain='', extra_config='includeconf={}\n'.format(inc_conf_file_path))
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('regtest=0\n') # mainnet
conf.write('acceptnonstdtxn=1\n')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
self.nodes[0].assert_start_raises_init_error(extra_args=["-conf={}".format(main_conf_file_path)], expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')

with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('nono\n')
Expand Down
21 changes: 14 additions & 7 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,14 @@ def initialize_datadir(dirname, n, chain):
datadir = get_datadir_path(dirname, n)
if not os.path.isdir(datadir):
os.makedirs(datadir)
# Translate chain name to config name
write_config(os.path.join(datadir, "bitcoin.conf"), n=n, chain=chain)
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
return datadir


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'
Expand All @@ -325,9 +332,11 @@ def initialize_datadir(dirname, n, chain):
chain_name_conf_arg = chain
chain_name_conf_section = chain
chain_name_conf_arg_value = '1'
with open(os.path.join(datadir, "dash.conf"), 'w', encoding='utf8') as f:
f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value))
f.write("[{}]\n".format(chain_name_conf_section))
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))
if chain_name_conf_section:
f.write("[{}]\n".format(chain_name_conf_section))
f.write("port=" + str(p2p_port(n)) + "\n")
f.write("rpcport=" + str(rpc_port(n)) + "\n")
f.write("fallbackfee=0.00001\n")
Expand All @@ -341,9 +350,7 @@ def initialize_datadir(dirname, n, chain):
f.write("shrinkdebugfile=0\n")
# To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync
f.write("unsafesqlitesync=1\n")
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
return datadir
f.write(extra_config)

def adjust_bitcoin_conf_for_pre_16(conf_file):
with open(conf_file,'r', encoding='utf8') as conf:
Expand Down

0 comments on commit b6de87d

Please sign in to comment.