def run_test(self):
    self.log.info('Generating initial blockchain')
    self.nodes[0].generate(1)
    self.sync_blocks()
    self.nodes[1].generate(1)
    self.sync_blocks()
    self.nodes[2].generate(1)
    self.sync_blocks()
    self.nodes[3].generate(100)
    self.sync_blocks()
    assert_equal(self.nodes[0].getbalance(), 50)
    assert_equal(self.nodes[1].getbalance(), 50)
    assert_equal(self.nodes[2].getbalance(), 50)
    assert_equal(self.nodes[3].getbalance(), 0)
    self.log.info('Creating transactions')
    for _ in range(5):
        self.do_one_round()
    self.log.info('Backing up')
    self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
    self.nodes[1].backupwallet(os.path.join(self.nodes[1].datadir, 'wallet.bak'))
    self.nodes[2].backupwallet(os.path.join(self.nodes[2].datadir, 'wallet.bak'))
    if (not self.options.descriptors):
        self.nodes[0].dumpwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
        self.nodes[1].dumpwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
        self.nodes[2].dumpwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
    self.log.info('More transactions')
    for _ in range(5):
        self.do_one_round()
    self.nodes[3].generate(101)
    self.sync_all()
    balance0 = self.nodes[0].getbalance()
    balance1 = self.nodes[1].getbalance()
    balance2 = self.nodes[2].getbalance()
    balance3 = self.nodes[3].getbalance()
    total = (((balance0 + balance1) + balance2) + balance3)
    assert_equal(total, 5700)
    self.log.info('Restoring using wallet.dat')
    self.stop_three()
    self.erase_three()
    shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
    shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
    shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    self.log.info('Re-starting nodes')
    self.start_three()
    self.sync_blocks()
    assert_equal(self.nodes[0].getbalance(), balance0)
    assert_equal(self.nodes[1].getbalance(), balance1)
    assert_equal(self.nodes[2].getbalance(), balance2)
    if (not self.options.descriptors):
        self.log.info('Restoring using dumped wallet')
        self.stop_three()
        self.erase_three()
        shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
        shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
        self.start_three(['-nowallet'])
        self.init_three()
        assert_equal(self.nodes[0].getbalance(), 0)
        assert_equal(self.nodes[1].getbalance(), 0)
        assert_equal(self.nodes[2].getbalance(), 0)
        self.nodes[0].importwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
        self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
        self.nodes[2].importwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
        self.sync_blocks()
        assert_equal(self.nodes[0].getbalance(), balance0)
        assert_equal(self.nodes[1].getbalance(), balance1)
        assert_equal(self.nodes[2].getbalance(), balance2)
    sourcePaths = [os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename), os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name), os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
    for sourcePath in sourcePaths:
        assert_raises_rpc_error((- 4), 'backup failed', self.nodes[0].backupwallet, sourcePath)
def run_test(self):
    self.log.info('Generating initial blockchain')
    self.nodes[0].generate(1)
    self.sync_blocks()
    self.nodes[1].generate(1)
    self.sync_blocks()
    self.nodes[2].generate(1)
    self.sync_blocks()
    self.nodes[3].generate(100)
    self.sync_blocks()
    assert_equal(self.nodes[0].getbalance(), 50)
    assert_equal(self.nodes[1].getbalance(), 50)
    assert_equal(self.nodes[2].getbalance(), 50)
    assert_equal(self.nodes[3].getbalance(), 0)
    self.log.info('Creating transactions')
    for _ in range(5):
        self.do_one_round()
    self.log.info('Backing up')
    self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
    self.nodes[1].backupwallet(os.path.join(self.nodes[1].datadir, 'wallet.bak'))
    self.nodes[2].backupwallet(os.path.join(self.nodes[2].datadir, 'wallet.bak'))
    if (not self.options.descriptors):
        self.nodes[0].dumpwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
        self.nodes[1].dumpwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
        self.nodes[2].dumpwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
    self.log.info('More transactions')
    for _ in range(5):
        self.do_one_round()
    self.nodes[3].generate(101)
    self.sync_all()
    balance0 = self.nodes[0].getbalance()
    balance1 = self.nodes[1].getbalance()
    balance2 = self.nodes[2].getbalance()
    balance3 = self.nodes[3].getbalance()
    total = (((balance0 + balance1) + balance2) + balance3)
    assert_equal(total, 5700)
    self.log.info('Restoring using wallet.dat')
    self.stop_three()
    self.erase_three()
    shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
    shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
    shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
    self.log.info('Re-starting nodes')
    self.start_three()
    self.sync_blocks()
    assert_equal(self.nodes[0].getbalance(), balance0)
    assert_equal(self.nodes[1].getbalance(), balance1)
    assert_equal(self.nodes[2].getbalance(), balance2)
    if (not self.options.descriptors):
        self.log.info('Restoring using dumped wallet')
        self.stop_three()
        self.erase_three()
        shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
        shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
        self.start_three(['-nowallet'])
        self.init_three()
        assert_equal(self.nodes[0].getbalance(), 0)
        assert_equal(self.nodes[1].getbalance(), 0)
        assert_equal(self.nodes[2].getbalance(), 0)
        self.nodes[0].importwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
        self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
        self.nodes[2].importwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
        self.sync_blocks()
        assert_equal(self.nodes[0].getbalance(), balance0)
        assert_equal(self.nodes[1].getbalance(), balance1)
        assert_equal(self.nodes[2].getbalance(), balance2)
    sourcePaths = [os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename), os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name), os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
    for sourcePath in sourcePaths:
        assert_raises_rpc_error((- 4), 'backup failed', self.nodes[0].backupwallet, sourcePath)