Skip to content

Commit ff44cae

Browse files
committed
test: Change feature_config_args.py not to rely on strange regtest=0 behavior
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).
1 parent c157a50 commit ff44cae

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

test/functional/feature_config_args.py

Lines changed: 4 additions & 2 deletions
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):
@@ -41,10 +42,11 @@ def test_config_file_parser(self):
4142
conf.write("wallet=foo\n")
4243
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))
4344

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

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

test/functional/test_framework/util.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,25 @@ def initialize_datadir(dirname, n, chain):
334334
datadir = get_datadir_path(dirname, n)
335335
if not os.path.isdir(datadir):
336336
os.makedirs(datadir)
337-
# Translate chain name to config name
337+
write_config(os.path.join(datadir, "bitcoin.conf"), n=n, chain=chain)
338+
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
339+
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
340+
return datadir
341+
342+
343+
def write_config(config_path, *, n, chain, extra_config=""):
344+
# Translate chain subdirectory name to config name
338345
if chain == 'testnet3':
339346
chain_name_conf_arg = 'testnet'
340347
chain_name_conf_section = 'test'
341348
else:
342349
chain_name_conf_arg = chain
343350
chain_name_conf_section = chain
344-
with open(os.path.join(datadir, "bitcoin.conf"), 'w', encoding='utf8') as f:
345-
f.write("{}=1\n".format(chain_name_conf_arg))
346-
f.write("[{}]\n".format(chain_name_conf_section))
351+
with open(config_path, 'w', encoding='utf8') as f:
352+
if chain_name_conf_arg:
353+
f.write("{}=1\n".format(chain_name_conf_arg))
354+
if chain_name_conf_section:
355+
f.write("[{}]\n".format(chain_name_conf_section))
347356
f.write("port=" + str(p2p_port(n)) + "\n")
348357
f.write("rpcport=" + str(rpc_port(n)) + "\n")
349358
f.write("fallbackfee=0.0002\n")
@@ -355,9 +364,7 @@ def initialize_datadir(dirname, n, chain):
355364
f.write("printtoconsole=0\n")
356365
f.write("upnp=0\n")
357366
f.write("shrinkdebugfile=0\n")
358-
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
359-
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
360-
return datadir
367+
f.write(extra_config)
361368

362369

363370
def get_datadir_path(dirname, n):

0 commit comments

Comments
 (0)