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

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

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

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

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

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

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

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

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

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

test/functional/tool_wallet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def skip_test_if_missing_module(self):
2727

2828
def bitcoin_wallet_process(self, *args):
2929
binary = self.config["environment"]["BUILDDIR"] + '/src/bitcoin-wallet' + self.config["environment"]["EXEEXT"]
30-
args = ['-datadir={}'.format(self.nodes[0].datadir), '-regtest'] + list(args)
30+
args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain] + list(args)
3131
return subprocess.Popen([binary] + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
3232

3333
def assert_raises_tool_error(self, error, *args):
@@ -198,7 +198,7 @@ def test_getwalletinfo_on_different_wallet(self):
198198
self.log.debug('Wallet file shasum unchanged\n')
199199

200200
def run_test(self):
201-
self.wallet_path = os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat')
201+
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')
202202
self.test_invalid_tool_commands_and_args()
203203
# Warning: The following tests are order-dependent.
204204
self.test_tool_wallet_info()

test/functional/wallet_backup.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def stop_three(self):
107107
self.stop_node(2)
108108

109109
def erase_three(self):
110-
os.remove(os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
111-
os.remove(os.path.join(self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
112-
os.remove(os.path.join(self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
110+
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
111+
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
112+
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
113113

114114
def run_test(self):
115115
self.log.info("Generating initial blockchain")
@@ -167,13 +167,13 @@ def run_test(self):
167167
self.erase_three()
168168

169169
# Start node2 with no chain
170-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
171-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'chainstate'))
170+
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
171+
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
172172

173173
# Restore wallets from backup
174-
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
175-
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
176-
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
174+
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
175+
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
176+
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
177177

178178
self.log.info("Re-starting nodes")
179179
self.start_three()
@@ -188,8 +188,8 @@ def run_test(self):
188188
self.erase_three()
189189

190190
#start node2 with no chain
191-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
192-
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'chainstate'))
191+
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
192+
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
193193

194194
self.start_three()
195195

@@ -209,10 +209,10 @@ def run_test(self):
209209

210210
# Backup to source wallet file must fail
211211
sourcePaths = [
212-
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'),
213-
os.path.join(self.nodes[0].datadir, 'regtest', '.', 'wallets', 'wallet.dat'),
214-
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', ''),
215-
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets')]
212+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'),
213+
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', 'wallet.dat'),
214+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
215+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
216216

217217
for sourcePath in sourcePaths:
218218
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)

test/functional/wallet_hd.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def run_test(self):
6868

6969
self.log.info("Restore backup ...")
7070
self.stop_node(1)
71-
# we need to delete the complete regtest directory
71+
# we need to delete the complete chain directory
7272
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
73-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
74-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "chainstate"))
75-
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
73+
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
74+
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
75+
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
7676
self.start_node(1)
7777

7878
# Assert that derivation is deterministic
@@ -93,9 +93,9 @@ def run_test(self):
9393

9494
# Try a RPC based rescan
9595
self.stop_node(1)
96-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
97-
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "chainstate"))
98-
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
96+
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
97+
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
98+
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
9999
self.start_node(1, extra_args=self.extra_args[1])
100100
connect_nodes(self.nodes[0], 1)
101101
self.sync_all()

test/functional/wallet_keypool_topup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def skip_test_if_missing_module(self):
3030
self.skip_if_no_wallet()
3131

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

test/functional/wallet_multiwallet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def add_options(self, parser):
3838
def run_test(self):
3939
node = self.nodes[0]
4040

41-
data_dir = lambda *p: os.path.join(node.datadir, 'regtest', *p)
41+
data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p)
4242
wallet_dir = lambda *p: data_dir('wallets', *p)
4343
wallet = lambda name: node.get_wallet_rpc(name)
4444

@@ -186,7 +186,7 @@ def wallet_file(name):
186186
assert_equal(w4.getbalance(), 3)
187187

188188
batch = w1.batch([w1.getblockchaininfo.get_request(), w1.getwalletinfo.get_request()])
189-
assert_equal(batch[0]["result"]["chain"], "regtest")
189+
assert_equal(batch[0]["result"]["chain"], self.chain)
190190
assert_equal(batch[1]["result"]["walletname"], "w1")
191191

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

test/functional/wallet_reorgsrestore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self):
9090
# Node0 wallet file is loaded on longest sync'ed node1
9191
self.stop_node(1)
9292
self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
93-
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, 'regtest', 'wallet.dat'))
93+
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallet.dat'))
9494
self.start_node(1)
9595
tx_after_reorg = self.nodes[1].gettransaction(txid)
9696
# Check that normal confirmed tx is confirmed again but with different blockhash

0 commit comments

Comments
 (0)