Skip to content

Commit 736e906

Browse files
jtimonPiRK
authored andcommitted
Tests: Use self.chain instead of 'regtest' in all current tests
Summary: This is a backport of Core [[bitcoin/bitcoin#16681 | PR16681]] and [[bitcoin/bitcoin#18069 | PR18069]] I also replaced one occurence of 'regtest' in test_framework.py, that was missed in the backport of [[bitcoin/bitcoin#16509 | PR16509]] (D5942) Test Plan: `ninja && ninja check-functional-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D8738
1 parent 972b80d commit 736e906

18 files changed

+63
-47
lines changed

test/functional/feature_abortnode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run_test(self):
3131
datadir = get_datadir_path(self.options.tmpdir, 0)
3232

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

3636
# Connecting to a node with a more work chain will trigger a reorg
3737
# attempt.

test/functional/feature_config_args.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_config_file_parser(self):
4141
with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
4242
conf.write("wallet=foo\n")
4343
self.nodes[0].assert_start_raises_init_error(
44-
expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.')
44+
expected_msg='Error: Config setting for -wallet only applied on {} network when in [{}] section.'.format(self.chain, self.chain))
4545

4646
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
4747
conf.write('regtest=0\n') # mainnet
@@ -108,8 +108,8 @@ def test_args_log(self):
108108
'Command-line arg: rpcpassword=****',
109109
'Command-line arg: rpcuser=****',
110110
'Command-line arg: torpassword=****',
111-
'Config file arg: regtest="1"',
112-
'Config file arg: [regtest] server="1"',
111+
'Config file arg: {}="1"'.format(self.chain),
112+
'Config file arg: [{}] server="1"'.format(self.chain),
113113
],
114114
unexpected_msgs=[
115115
'alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc0',
@@ -150,7 +150,7 @@ def run_test(self):
150150
# Check that using non-existent datadir in conf file fails
151151
conf_file = os.path.join(default_data_dir, "bitcoin.conf")
152152

153-
# datadir needs to be set before [regtest] section
153+
# datadir needs to be set before [chain] section
154154
conf_file_contents = open(conf_file, encoding='utf8').read()
155155
with open(conf_file, 'w', encoding='utf8') as f:
156156
f.write("datadir=" + new_data_dir + "\n")
@@ -163,10 +163,10 @@ def run_test(self):
163163
os.mkdir(new_data_dir)
164164
self.start_node(0, ['-conf=' + conf_file, '-wallet=w1'])
165165
self.stop_node(0)
166-
assert os.path.exists(os.path.join(new_data_dir, 'regtest', 'blocks'))
166+
assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
167167
if self.is_wallet_compiled():
168168
assert os.path.exists(os.path.join(
169-
new_data_dir, 'regtest', 'wallets', 'w1'))
169+
new_data_dir, self.chain, 'wallets', 'w1'))
170170

171171
# Ensure command line argument overrides datadir in conf
172172
os.mkdir(new_data_dir_2)
@@ -176,13 +176,13 @@ def run_test(self):
176176
assert os.path.exists(
177177
os.path.join(
178178
new_data_dir_2,
179-
'regtest',
179+
self.chain,
180180
'blocks'))
181181
if self.is_wallet_compiled():
182182
assert os.path.exists(
183183
os.path.join(
184184
new_data_dir_2,
185-
'regtest',
185+
self.chain,
186186
'wallets',
187187
'w2'))
188188

test/functional/feature_filelock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setup_network(self):
2020
self.nodes[0].wait_for_rpc_connection()
2121

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

2626
self.log.info(

test/functional/feature_loadblock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run_test(self):
3636
cfg_file = os.path.join(data_dir, "linearize.cfg")
3737
bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat")
3838
genesis_block = self.nodes[0].getblockhash(0)
39-
blocks_dir = os.path.join(data_dir, "regtest", "blocks")
39+
blocks_dir = os.path.join(data_dir, self.chain, "blocks")
4040
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
4141
mode='w',
4242
delete=False,

test/functional/feature_logging.py

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def setup_network(self):
110110
self.setup_nodes()
111111

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

115115
connect_nodes(self.nodes[0], self.nodes[1])
116116
connect_nodes(self.nodes[1], self.nodes[2])
@@ -319,7 +319,7 @@ def prune(index):
319319

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

324324
# should not prune because chain tip of node 3 (995) < PruneAfterHeight
325325
# (1000)

test/functional/interface_rpc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_getrpcinfo(self):
4040
info['logpath'],
4141
os.path.join(
4242
self.nodes[0].datadir,
43-
'regtest',
43+
self.chain,
4444
'debug.log'))
4545

4646
def test_batch_request(self):

test/functional/mempool_persist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def run_test(self):
132132
assert_equal(len(self.nodes[0].getrawmempool()), 5)
133133

134134
mempooldat0 = os.path.join(
135-
self.nodes[0].datadir, 'regtest', 'mempool.dat')
135+
self.nodes[0].datadir, self.chain, 'mempool.dat')
136136
mempooldat1 = os.path.join(
137-
self.nodes[1].datadir, 'regtest', 'mempool.dat')
137+
self.nodes[1].datadir, self.chain, 'mempool.dat')
138138
self.log.debug(
139139
"Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it")
140140
os.remove(mempooldat0)

test/functional/mining_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
7878
self.log.info('getmininginfo')
7979
mining_info = node.getmininginfo()
8080
assert_equal(mining_info['blocks'], 200)
81-
assert_equal(mining_info['chain'], 'regtest')
81+
assert_equal(mining_info['chain'], self.chain)
8282
assert 'currentblocktx' not in mining_info
8383
assert 'currentblocksize' not in mining_info
8484
assert_equal(mining_info['difficulty'],

test/functional/rpc_dumptxoutset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run_test(self):
2525

2626
FILENAME = 'txoutset.dat'
2727
out = node.dumptxoutset(FILENAME)
28-
expected_path = Path(node.datadir) / 'regtest' / FILENAME
28+
expected_path = Path(node.datadir) / self.chain / FILENAME
2929

3030
assert expected_path.is_file()
3131

test/functional/rpc_scantxoutset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_test(self):
7474
self.log.info("Stop node, remove wallet, mine again some blocks...")
7575
self.stop_node(0)
7676
shutil.rmtree(os.path.join(
77-
self.nodes[0].datadir, "regtest", 'wallets'))
77+
self.nodes[0].datadir, self.chain, 'wallets'))
7878
self.start_node(0)
7979
self.nodes[0].generate(110)
8080

test/functional/test_framework/test_framework.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def _initialize_chain(self):
616616
self.nodes = []
617617

618618
def cache_path(*paths):
619-
return os.path.join(cache_node_dir, "regtest", *paths)
619+
return os.path.join(cache_node_dir, self.chain, *paths)
620620

621621
# Remove empty wallets dir
622622
os.rmdir(cache_path('wallets'))

test/functional/tool_wallet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def bitcoin_wallet_process(self, *args):
3030
binary = self.config["environment"]["BUILDDIR"] + \
3131
'/src/bitcoin-wallet' + self.config["environment"]["EXEEXT"]
3232
args = ['-datadir={}'.format(self.nodes[0].datadir),
33-
'-regtest'] + list(args)
33+
'-chain={}'.format(self.chain)] + list(args)
3434

3535
command_line = [binary] + args
3636
if self.config["environment"]["EMULATOR"]:
@@ -243,7 +243,7 @@ def test_salvage(self):
243243

244244
def run_test(self):
245245
self.wallet_path = os.path.join(
246-
self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat')
246+
self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')
247247
self.test_invalid_tool_commands_and_args()
248248
# Warning: The following tests are order-dependent.
249249
self.test_tool_wallet_info()

test/functional/wallet_backup.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ def stop_three(self):
108108

109109
def erase_three(self):
110110
os.remove(os.path.join(
111-
self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
111+
self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
112112
os.remove(os.path.join(
113-
self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
113+
self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
114114
os.remove(os.path.join(
115-
self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
115+
self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
116116

117117
def run_test(self):
118118
self.log.info("Generating initial blockchain")
@@ -175,17 +175,21 @@ def run_test(self):
175175
self.erase_three()
176176

177177
# Start node2 with no chain
178-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
178+
shutil.rmtree(
179+
os.path.join(
180+
self.nodes[2].datadir,
181+
self.chain,
182+
'blocks'))
179183
shutil.rmtree(os.path.join(
180-
self.nodes[2].datadir, 'regtest', 'chainstate'))
184+
self.nodes[2].datadir, self.chain, 'chainstate'))
181185

182186
# Restore wallets from backup
183187
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(
184-
self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
188+
self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
185189
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(
186-
self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
190+
self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
187191
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(
188-
self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
192+
self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
189193

190194
self.log.info("Re-starting nodes")
191195
self.start_three()
@@ -200,9 +204,13 @@ def run_test(self):
200204
self.erase_three()
201205

202206
# start node2 with no chain
203-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
207+
shutil.rmtree(
208+
os.path.join(
209+
self.nodes[2].datadir,
210+
self.chain,
211+
'blocks'))
204212
shutil.rmtree(os.path.join(
205-
self.nodes[2].datadir, 'regtest', 'chainstate'))
213+
self.nodes[2].datadir, self.chain, 'chainstate'))
206214

207215
self.start_three()
208216

@@ -226,11 +234,11 @@ def run_test(self):
226234
# Backup to source wallet file must fail
227235
sourcePaths = [
228236
os.path.join(self.nodes[0].datadir,
229-
'regtest', 'wallets', 'wallet.dat'),
230-
os.path.join(self.nodes[0].datadir, 'regtest',
237+
self.chain, 'wallets', 'wallet.dat'),
238+
os.path.join(self.nodes[0].datadir, self.chain,
231239
'.', 'wallets', 'wallet.dat'),
232-
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', ''),
233-
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets')]
240+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
241+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
234242

235243
for sourcePath in sourcePaths:
236244
assert_raises_rpc_error(-4, "backup failed",

test/functional/wallet_hd.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ def run_test(self):
7474
# we need to delete the complete regtest directory
7575
# otherwise node1 would auto-recover all funds in flag the keypool keys
7676
# as used
77-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
77+
shutil.rmtree(
78+
os.path.join(
79+
self.nodes[1].datadir,
80+
self.chain,
81+
"blocks"))
7882
shutil.rmtree(os.path.join(
79-
self.nodes[1].datadir, "regtest", "chainstate"))
83+
self.nodes[1].datadir, self.chain, "chainstate"))
8084
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(
81-
self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
85+
self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
8286
self.start_node(1)
8387

8488
# Assert that derivation is deterministic
@@ -99,11 +103,15 @@ def run_test(self):
99103

100104
# Try a RPC based rescan
101105
self.stop_node(1)
102-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
106+
shutil.rmtree(
107+
os.path.join(
108+
self.nodes[1].datadir,
109+
self.chain,
110+
"blocks"))
103111
shutil.rmtree(os.path.join(
104-
self.nodes[1].datadir, "regtest", "chainstate"))
112+
self.nodes[1].datadir, self.chain, "chainstate"))
105113
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(
106-
self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
114+
self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
107115
self.start_node(1, extra_args=self.extra_args[1])
108116
connect_nodes(self.nodes[0], self.nodes[1])
109117
self.sync_all()

test/functional/wallet_keypool_topup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def skip_test_if_missing_module(self):
3131

3232
def run_test(self):
3333
wallet_path = os.path.join(
34-
self.nodes[1].datadir, "regtest", "wallets", "wallet.dat")
34+
self.nodes[1].datadir, self.chain, "wallets", "wallet.dat")
3535
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
3636
self.nodes[0].generate(101)
3737

test/functional/wallet_multiwallet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add_options(self, parser):
4141
def run_test(self):
4242
node = self.nodes[0]
4343

44-
def data_dir(*p): return os.path.join(node.datadir, 'regtest', *p)
44+
def data_dir(*p): return os.path.join(node.datadir, self.chain, *p)
4545

4646
def wallet_dir(*p): return data_dir('wallets', *p)
4747

@@ -223,7 +223,7 @@ def wallet_file(name):
223223

224224
batch = w1.batch([w1.getblockchaininfo.get_request(),
225225
w1.getwalletinfo.get_request()])
226-
assert_equal(batch[0]["result"]["chain"], "regtest")
226+
assert_equal(batch[0]["result"]["chain"], self.chain)
227227
assert_equal(batch[1]["result"]["walletname"], "w1")
228228

229229
self.log.info('Check for per-wallet settxfee call')

test/functional/wallet_reorgsrestore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def run_test(self):
109109
'wallet.bak'),
110110
os.path.join(
111111
self.nodes[1].datadir,
112-
'regtest',
112+
self.chain,
113113
'wallet.dat'))
114114
self.start_node(1)
115115
tx_after_reorg = self.nodes[1].gettransaction(txid)

0 commit comments

Comments
 (0)