def _initialize_chain(self, test_dir, num_nodes, cachedir):
    'Initialize a pre-mined blockchain for use by the test.\n\n        Create a cache of a 200-block-long chain (with wallet) for MAX_NODES\n        Afterward, create num_nodes copies from the cache.'
    assert (num_nodes <= MAX_NODES)
    create_cache = False
    for i in range(MAX_NODES):
        if (not os.path.isdir(os.path.join(cachedir, ('node' + str(i))))):
            create_cache = True
            break
    if create_cache:
        self.log.debug('Creating data directories from cached datadir')
        for i in range(MAX_NODES):
            if os.path.isdir(os.path.join(cachedir, ('node' + str(i)))):
                shutil.rmtree(os.path.join(cachedir, ('node' + str(i))))
        for i in range(MAX_NODES):
            datadir = initialize_datadir(cachedir, i)
            args = [os.getenv('BITCOIND', 'bitcoind'), '-server', '-keypool=1', ('-datadir=' + datadir), '-discover=0']
            if (i > 0):
                args.append(('-connect=127.0.0.1:' + str(p2p_port(0))))
            self.nodes.append(TestNode(i, cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
            self.nodes[i].args = args
            self.nodes[i].start()
        for node in self.nodes:
            node.wait_for_rpc_connection()
        self.enable_mocktime()
        block_time = (self.mocktime - ((201 * 10) * 60))
        for i in range(2):
            for peer in range(4):
                for j in range(25):
                    set_node_times(self.nodes, block_time)
                    self.nodes[peer].generate(1)
                    block_time += (10 * 60)
                sync_blocks(self.nodes)
        self.stop_nodes()
        self.nodes = []
        self.disable_mocktime()
        for i in range(MAX_NODES):
            os.remove(log_filename(cachedir, i, 'debug.log'))
            os.remove(log_filename(cachedir, i, 'db.log'))
            os.remove(log_filename(cachedir, i, 'peers.dat'))
            os.remove(log_filename(cachedir, i, 'fee_estimates.dat'))
    for i in range(num_nodes):
        from_dir = os.path.join(cachedir, ('node' + str(i)))
        to_dir = os.path.join(test_dir, ('node' + str(i)))
        shutil.copytree(from_dir, to_dir)
        initialize_datadir(test_dir, i)
Initialize a pre-mined blockchain for use by the test.

Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
Afterward, create num_nodes copies from the cache.
def _initialize_chain(self, test_dir, num_nodes, cachedir):
    'Initialize a pre-mined blockchain for use by the test.\n\n        Create a cache of a 200-block-long chain (with wallet) for MAX_NODES\n        Afterward, create num_nodes copies from the cache.'
    assert (num_nodes <= MAX_NODES)
    create_cache = False
    for i in range(MAX_NODES):
        if (not os.path.isdir(os.path.join(cachedir, ('node' + str(i))))):
            create_cache = True
            break
    if create_cache:
        self.log.debug('Creating data directories from cached datadir')
        for i in range(MAX_NODES):
            if os.path.isdir(os.path.join(cachedir, ('node' + str(i)))):
                shutil.rmtree(os.path.join(cachedir, ('node' + str(i))))
        for i in range(MAX_NODES):
            datadir = initialize_datadir(cachedir, i)
            args = [os.getenv('BITCOIND', 'bitcoind'), '-server', '-keypool=1', ('-datadir=' + datadir), '-discover=0']
            if (i > 0):
                args.append(('-connect=127.0.0.1:' + str(p2p_port(0))))
            self.nodes.append(TestNode(i, cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
            self.nodes[i].args = args
            self.nodes[i].start()
        for node in self.nodes:
            node.wait_for_rpc_connection()
        self.enable_mocktime()
        block_time = (self.mocktime - ((201 * 10) * 60))
        for i in range(2):
            for peer in range(4):
                for j in range(25):
                    set_node_times(self.nodes, block_time)
                    self.nodes[peer].generate(1)
                    block_time += (10 * 60)
                sync_blocks(self.nodes)
        self.stop_nodes()
        self.nodes = []
        self.disable_mocktime()
        for i in range(MAX_NODES):
            os.remove(log_filename(cachedir, i, 'debug.log'))
            os.remove(log_filename(cachedir, i, 'db.log'))
            os.remove(log_filename(cachedir, i, 'peers.dat'))
            os.remove(log_filename(cachedir, i, 'fee_estimates.dat'))
    for i in range(num_nodes):
        from_dir = os.path.join(cachedir, ('node' + str(i)))
        to_dir = os.path.join(test_dir, ('node' + str(i)))
        shutil.copytree(from_dir, to_dir)
        initialize_datadir(test_dir, i)