|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2018 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Check that it's not possible to start a second bitcoind instance using the same datadir or wallet.""" |
| 6 | +import os |
| 7 | + |
| 8 | +from test_framework.test_framework import BitcoinTestFramework |
| 9 | +from test_framework.test_node import ErrorMatch |
| 10 | + |
| 11 | +class FilelockTest(BitcoinTestFramework): |
| 12 | + def set_test_params(self): |
| 13 | + self.setup_clean_chain = True |
| 14 | + self.num_nodes = 2 |
| 15 | + |
| 16 | + def setup_network(self): |
| 17 | + self.add_nodes(self.num_nodes, extra_args=None) |
| 18 | + self.nodes[0].start([]) |
| 19 | + self.nodes[0].wait_for_rpc_connection() |
| 20 | + |
| 21 | + def run_test(self): |
| 22 | + datadir = os.path.join(self.nodes[0].datadir, 'regtest') |
| 23 | + self.log.info("Using datadir {}".format(datadir)) |
| 24 | + |
| 25 | + self.log.info("Check that we can't start a second bitcoind instance using the same datadir") |
| 26 | + expected_msg = "Error: Cannot obtain a lock on data directory {}. Bitcoin Core is probably already running.".format(datadir) |
| 27 | + self.nodes[1].assert_start_raises_init_error(extra_args=['-datadir={}'.format(self.nodes[0].datadir), '-noserver'], expected_msg=expected_msg) |
| 28 | + |
| 29 | + if self.is_wallet_compiled(): |
| 30 | + wallet_dir = os.path.join(datadir, 'wallets') |
| 31 | + self.log.info("Check that we can't start a second bitcoind instance using the same wallet") |
| 32 | + expected_msg = "Error: Error initializing wallet database environment" |
| 33 | + self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX) |
| 34 | + |
| 35 | +if __name__ == '__main__': |
| 36 | + FilelockTest().main() |
0 commit comments