Skip to content

Commit f32564f

Browse files
author
MarcoFalke
committed
Merge bitcoin#16681: Tests: Use self.chain instead of 'regtest' in all current tests
1abcecc Tests: Use self.chain instead of 'regtest' in almost all current tests (Jorge Timón) Pull request description: Simply avoiding the hardcoded string in more places for consistency. It can also allow for more easily reusing tests for other chains other than regtest. Separated from bitcoin#8994 . Continues bitcoin#16509 . It is still not complete (ie to be complete, we need the -chain parameter in bitcoin#16680 and make whether acceptnonstdtxs is allowed for that chain or not customizable for regtest [or for custom chains like in bitcoin#8994 ] ). But while being incomplete like bitcoin#16509 , it's quite simple to review and another step forward IMO. ACKs for top commit: Sjors: re-ACK 1abcecc. I think it's an improvement even if incomplete and if some PR's might accidentally bring "regtest" back. Subsequent improvements hopefully don't have to touch 16 files. elichai: Code review ACK 1abcecc ryanofsky: Code review ACK 1abcecc. ryanofsky: Code review ACK 1abcecc Tree-SHA512: 5620de6dab235ca8bd8670d6366c7b9f04f0e3ca9c5e7f87765b38e16ed80c17d7d1630c0d5fd7c5526f070830d94dc74cc2096d8ede87dc7180ed20569509ee
2 parents 02fafdd + 1abcecc commit f32564f

16 files changed

+44
-44
lines changed

test/functional/feature_abortnode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run_test(self):
2929
datadir = get_datadir_path(self.options.tmpdir, 0)
3030

3131
# Deleting the undo file will result in reorg failure
32-
os.unlink(os.path.join(datadir, 'regtest', 'blocks', 'rev00000.dat'))
32+
os.unlink(os.path.join(datadir, self.chain, 'blocks', 'rev00000.dat'))
3333

3434
# Connecting to a node with a more work chain will trigger a reorg
3535
# attempt.

test/functional/feature_config_args.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_config_file_parser(self):
3939
if self.is_wallet_compiled():
4040
with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
4141
conf.write("wallet=foo\n")
42-
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.')
42+
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))
4343

4444
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
4545
conf.write('regtest=0\n') # mainnet
@@ -134,7 +134,7 @@ def run_test(self):
134134
# Check that using non-existent datadir in conf file fails
135135
conf_file = os.path.join(default_data_dir, "bitcoin.conf")
136136

137-
# datadir needs to be set before [regtest] section
137+
# datadir needs to be set before [chain] section
138138
conf_file_contents = open(conf_file, encoding='utf8').read()
139139
with open(conf_file, 'w', encoding='utf8') as f:
140140
f.write("datadir=" + new_data_dir + "\n")
@@ -146,17 +146,17 @@ def run_test(self):
146146
os.mkdir(new_data_dir)
147147
self.start_node(0, ['-conf='+conf_file, '-wallet=w1'])
148148
self.stop_node(0)
149-
assert os.path.exists(os.path.join(new_data_dir, 'regtest', 'blocks'))
149+
assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
150150
if self.is_wallet_compiled():
151-
assert os.path.exists(os.path.join(new_data_dir, 'regtest', 'wallets', 'w1'))
151+
assert os.path.exists(os.path.join(new_data_dir, self.chain, 'wallets', 'w1'))
152152

153153
# Ensure command line argument overrides datadir in conf
154154
os.mkdir(new_data_dir_2)
155155
self.nodes[0].datadir = new_data_dir_2
156156
self.start_node(0, ['-datadir='+new_data_dir_2, '-conf='+conf_file, '-wallet=w2'])
157-
assert os.path.exists(os.path.join(new_data_dir_2, 'regtest', 'blocks'))
157+
assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'blocks'))
158158
if self.is_wallet_compiled():
159-
assert os.path.exists(os.path.join(new_data_dir_2, 'regtest', 'wallets', 'w2'))
159+
assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'wallets', 'w2'))
160160

161161

162162
if __name__ == '__main__':

test/functional/feature_filelock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setup_network(self):
1919
self.nodes[0].wait_for_rpc_connection()
2020

2121
def run_test(self):
22-
datadir = os.path.join(self.nodes[0].datadir, 'regtest')
22+
datadir = os.path.join(self.nodes[0].datadir, self.chain)
2323
self.log.info("Using datadir {}".format(datadir))
2424

2525
self.log.info("Check that we can't start a second bitcoind instance using the same datadir")

test/functional/feature_loadblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def run_test(self):
3838
cfg_file = os.path.join(data_dir, "linearize.cfg")
3939
bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat")
4040
genesis_block = self.nodes[0].getblockhash(0)
41-
blocks_dir = os.path.join(data_dir, "regtest", "blocks")
41+
blocks_dir = os.path.join(data_dir, self.chain, "blocks")
4242
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
4343
mode='w',
4444
delete=False,

test/functional/feature_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_test_params(self):
1616
self.setup_clean_chain = True
1717

1818
def relative_log_path(self, name):
19-
return os.path.join(self.nodes[0].datadir, "regtest", name)
19+
return os.path.join(self.nodes[0].datadir, self.chain, name)
2020

2121
def run_test(self):
2222
# test default log file name

test/functional/feature_pruning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def skip_test_if_missing_module(self):
101101
def setup_network(self):
102102
self.setup_nodes()
103103

104-
self.prunedir = os.path.join(self.nodes[2].datadir, 'regtest', 'blocks', '')
104+
self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '')
105105

106106
connect_nodes(self.nodes[0], 1)
107107
connect_nodes(self.nodes[1], 2)
@@ -279,7 +279,7 @@ def prune(index):
279279
assert_equal(ret, node.getblockchaininfo()['pruneheight'])
280280

281281
def has_block(index):
282-
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, "regtest", "blocks", "blk{:05}.dat".format(index)))
282+
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", "blk{:05}.dat".format(index)))
283283

284284
# should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
285285
assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500))

test/functional/interface_rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_getrpcinfo(self):
3333
command = info['active_commands'][0]
3434
assert_equal(command['method'], 'getrpcinfo')
3535
assert_greater_than_or_equal(command['duration'], 0)
36-
assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, 'regtest', 'debug.log'))
36+
assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, self.chain, 'debug.log'))
3737

3838
def test_batch_request(self):
3939
self.log.info("Testing basic JSON-RPC batch request...")

test/functional/mempool_persist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def run_test(self):
117117
wait_until(lambda: self.nodes[0].getmempoolinfo()["loaded"])
118118
assert_equal(len(self.nodes[0].getrawmempool()), 5)
119119

120-
mempooldat0 = os.path.join(self.nodes[0].datadir, 'regtest', 'mempool.dat')
121-
mempooldat1 = os.path.join(self.nodes[1].datadir, 'regtest', 'mempool.dat')
120+
mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat')
121+
mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat')
122122
self.log.debug("Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it")
123123
os.remove(mempooldat0)
124124
self.nodes[0].savemempool()

test/functional/mining_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
7070
self.log.info('getmininginfo')
7171
mining_info = node.getmininginfo()
7272
assert_equal(mining_info['blocks'], 200)
73-
assert_equal(mining_info['chain'], 'regtest')
73+
assert_equal(mining_info['chain'], self.chain)
7474
assert 'currentblocktx' not in mining_info
7575
assert 'currentblockweight' not in mining_info
7676
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))

test/functional/rpc_scantxoutset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_test(self):
5454

5555
self.log.info("Stop node, remove wallet, mine again some blocks...")
5656
self.stop_node(0)
57-
shutil.rmtree(os.path.join(self.nodes[0].datadir, "regtest", 'wallets'))
57+
shutil.rmtree(os.path.join(self.nodes[0].datadir, self.chain, 'wallets'))
5858
self.start_node(0)
5959
self.nodes[0].generate(110)
6060

0 commit comments

Comments
 (0)