Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2018-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test the blocksdir option.6"""8from pathlib import Path10from test_framework.test_framework import BitcoinTestFramework, initialize_datadir13class BlocksdirTest(BitcoinTestFramework):14def set_test_params(self):15self.setup_clean_chain = True16self.num_nodes = 118def run_test(self):19self.stop_node(0)20assert self.nodes[0].blocks_path.is_dir()21assert not (self.nodes[0].datadir_path / "blocks").is_dir()22self.cleanup_folder(self.nodes[0].datadir_path)23initialize_datadir(self.options.tmpdir, 0, self.chain)24self.log.info("Starting with nonexistent blocksdir ...")25blocksdir_path = Path(self.options.tmpdir) / 'blocksdir'26self.nodes[0].assert_start_raises_init_error([f"-blocksdir={blocksdir_path}"], f'Error: Specified blocks directory "{blocksdir_path}" does not exist.')27blocksdir_path.mkdir()28self.log.info("Starting with existing blocksdir ...")29self.start_node(0, [f"-blocksdir={blocksdir_path}"])30self.log.info("mining blocks..")31self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)32assert (blocksdir_path / self.chain / "blocks" / "blk00000.dat").is_file()33assert (self.nodes[0].blocks_path / "index").is_dir()36if __name__ == '__main__':37BlocksdirTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.