2018-03-09 12:43:55 +08:00
|
|
|
#!/usr/bin/env python3
|
2021-07-28 13:57:16 +02:00
|
|
|
# Copyright (c) 2018-2021 The Bitcoin Core developers
|
2018-03-09 12:43:55 +08:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Test the blocksdir option.
|
|
|
|
"""
|
|
|
|
|
2018-03-27 19:24:09 -04:00
|
|
|
import shutil
|
2023-09-02 01:09:43 -04:00
|
|
|
from pathlib import Path
|
2018-03-27 19:24:09 -04:00
|
|
|
|
2018-03-09 12:43:55 +08:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework, initialize_datadir
|
|
|
|
|
|
|
|
|
|
|
|
class BlocksdirTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
self.num_nodes = 1
|
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
self.stop_node(0)
|
2023-09-02 01:09:43 -04:00
|
|
|
assert self.nodes[0].blocks_path.is_dir()
|
|
|
|
assert not (self.nodes[0].datadir_path / "blocks").is_dir()
|
|
|
|
shutil.rmtree(self.nodes[0].datadir_path)
|
2019-07-31 14:11:32 -04:00
|
|
|
initialize_datadir(self.options.tmpdir, 0, self.chain)
|
2018-08-15 15:18:26 -07:00
|
|
|
self.log.info("Starting with nonexistent blocksdir ...")
|
2023-09-02 01:09:43 -04:00
|
|
|
blocksdir_path = Path(self.options.tmpdir) / 'blocksdir'
|
2021-06-11 13:42:56 +08:00
|
|
|
self.nodes[0].assert_start_raises_init_error([f"-blocksdir={blocksdir_path}"], f'Error: Specified blocks directory "{blocksdir_path}" does not exist.')
|
2023-09-02 01:09:43 -04:00
|
|
|
blocksdir_path.mkdir()
|
2018-08-15 15:18:26 -07:00
|
|
|
self.log.info("Starting with existing blocksdir ...")
|
2021-06-11 13:42:56 +08:00
|
|
|
self.start_node(0, [f"-blocksdir={blocksdir_path}"])
|
2018-03-09 12:43:55 +08:00
|
|
|
self.log.info("mining blocks..")
|
2021-08-19 17:10:24 +02:00
|
|
|
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)
|
2023-09-02 01:09:43 -04:00
|
|
|
assert (blocksdir_path / self.chain / "blocks" / "blk00000.dat").is_file()
|
|
|
|
assert (self.nodes[0].blocks_path / "index").is_dir()
|
2018-03-27 19:24:09 -04:00
|
|
|
|
2018-03-09 12:43:55 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-07-16 22:05:14 +01:00
|
|
|
BlocksdirTest(__file__).main()
|