Skip to content

Commit 11cbd4b

Browse files
author
MarcoFalke
committed
Merge #17556: test: Change feature_config_args.py not to rely 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 #17493 Top commit has no ACKs. Tree-SHA512: 3f77305454f04438493dfc2abd78a00434b30869454d1c3f54587b9c1f63239c49c90fb3b4d3a777ad130f2184e0f2dac87cee4cd23c50f1b3496a375943da01
2 parents 1f45e85 + ff44cae commit 11cbd4b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

test/functional/feature_config_args.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88

99
from test_framework.test_framework import BitcoinTestFramework
10+
from test_framework import util
1011

1112

1213
class ConfArgsTest(BitcoinTestFramework):
@@ -42,10 +43,11 @@ def test_config_file_parser(self):
4243
conf.write("wallet=foo\n")
4344
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))
4445

46+
main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_main.conf')
47+
util.write_config(main_conf_file_path, n=0, chain='', extra_config='includeconf={}\n'.format(inc_conf_file_path))
4548
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
46-
conf.write('regtest=0\n') # mainnet
4749
conf.write('acceptnonstdtxn=1\n')
48-
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
50+
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')
4951

5052
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
5153
conf.write('nono\n')

test/functional/test_framework/util.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,25 @@ def initialize_datadir(dirname, n, chain):
342342
datadir = get_datadir_path(dirname, n)
343343
if not os.path.isdir(datadir):
344344
os.makedirs(datadir)
345-
# Translate chain name to config name
345+
write_config(os.path.join(datadir, "bitcoin.conf"), n=n, chain=chain)
346+
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
347+
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
348+
return datadir
349+
350+
351+
def write_config(config_path, *, n, chain, extra_config=""):
352+
# Translate chain subdirectory name to config name
346353
if chain == 'testnet3':
347354
chain_name_conf_arg = 'testnet'
348355
chain_name_conf_section = 'test'
349356
else:
350357
chain_name_conf_arg = chain
351358
chain_name_conf_section = chain
352-
with open(os.path.join(datadir, "bitcoin.conf"), 'w', encoding='utf8') as f:
353-
f.write("{}=1\n".format(chain_name_conf_arg))
354-
f.write("[{}]\n".format(chain_name_conf_section))
359+
with open(config_path, 'w', encoding='utf8') as f:
360+
if chain_name_conf_arg:
361+
f.write("{}=1\n".format(chain_name_conf_arg))
362+
if chain_name_conf_section:
363+
f.write("[{}]\n".format(chain_name_conf_section))
355364
f.write("port=" + str(p2p_port(n)) + "\n")
356365
f.write("rpcport=" + str(rpc_port(n)) + "\n")
357366
f.write("fallbackfee=0.0002\n")
@@ -364,9 +373,7 @@ def initialize_datadir(dirname, n, chain):
364373
f.write("upnp=0\n")
365374
f.write("natpmp=0\n")
366375
f.write("shrinkdebugfile=0\n")
367-
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
368-
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
369-
return datadir
376+
f.write(extra_config)
370377

371378

372379
def get_datadir_path(dirname, n):

0 commit comments

Comments
 (0)