2018-03-08 20:43:55 -08:00
#!/usr/bin/env python3
# Copyright (c) 2018 The Bitcoin Core developers
# 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 16:24:09 -07:00
import os
import re
import shutil
2018-03-08 20: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 )
2018-03-27 16:24:09 -07:00
shutil . rmtree ( self . nodes [ 0 ] . datadir )
2018-03-08 20:43:55 -08:00
initialize_datadir ( self . options . tmpdir , 0 )
self . log . info ( " Starting with non exiting blocksdir ... " )
2018-03-27 16:24:09 -07:00
blocksdir_path = os . path . join ( self . options . tmpdir , ' blocksdir ' )
self . nodes [ 0 ] . assert_start_raises_init_error ( [ " -blocksdir= " + blocksdir_path ] , re . escape ( ' Error: Specified blocks directory " {} " does not exist. ' . format ( blocksdir_path ) ) )
os . mkdir ( blocksdir_path )
2018-03-08 20:43:55 -08:00
self . log . info ( " Starting with exiting blocksdir ... " )
2018-03-27 16:24:09 -07:00
self . start_node ( 0 , [ " -blocksdir= " + blocksdir_path ] )
2018-03-08 20:43:55 -08:00
self . log . info ( " mining blocks.. " )
self . nodes [ 0 ] . generate ( 10 )
2018-03-27 16:24:09 -07:00
assert os . path . isfile ( os . path . join ( blocksdir_path , " regtest " , " blocks " , " blk00000.dat " ) )
assert os . path . isdir ( os . path . join ( self . nodes [ 0 ] . datadir , " regtest " , " blocks " , " index " ) )
2018-03-08 20:43:55 -08:00
if __name__ == ' __main__ ' :
BlocksdirTest ( ) . main ( )