Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_backup.py
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | def start_three(self): | ||||
connect_nodes(self.nodes[2], self.nodes[0]) | connect_nodes(self.nodes[2], self.nodes[0]) | ||||
def stop_three(self): | def stop_three(self): | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.stop_node(1) | self.stop_node(1) | ||||
self.stop_node(2) | self.stop_node(2) | ||||
def erase_three(self): | def erase_three(self): | ||||
os.remove(os.path.join( | os.remove( | ||||
self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')) | os.path.join(self.nodes[0].datadir, self.chain, 'wallets', | ||||
os.remove(os.path.join( | self.default_wallet_name, self.wallet_data_filename)) | ||||
self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat')) | os.remove( | ||||
os.remove(os.path.join( | os.path.join(self.nodes[1].datadir, self.chain, 'wallets', | ||||
self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat')) | self.default_wallet_name, self.wallet_data_filename)) | ||||
os.remove( | |||||
os.path.join(self.nodes[2].datadir, self.chain, 'wallets', | |||||
self.default_wallet_name, self.wallet_data_filename)) | |||||
def run_test(self): | def run_test(self): | ||||
self.log.info("Generating initial blockchain") | self.log.info("Generating initial blockchain") | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_blocks() | self.sync_blocks() | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
self.sync_blocks() | self.sync_blocks() | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
os.path.join( | os.path.join( | ||||
self.nodes[2].datadir, | self.nodes[2].datadir, | ||||
self.chain, | self.chain, | ||||
'blocks')) | 'blocks')) | ||||
shutil.rmtree(os.path.join( | shutil.rmtree(os.path.join( | ||||
self.nodes[2].datadir, self.chain, 'chainstate')) | self.nodes[2].datadir, self.chain, 'chainstate')) | ||||
# Restore wallets from backup | # Restore wallets from backup | ||||
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join( | shutil.copyfile( | ||||
self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')) | os.path.join(self.nodes[0].datadir, 'wallet.bak'), | ||||
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join( | os.path.join(self.nodes[0].datadir, self.chain, 'wallets', | ||||
self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat')) | self.default_wallet_name, self.wallet_data_filename)) | ||||
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join( | shutil.copyfile( | ||||
self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat')) | 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.log.info("Re-starting nodes") | ||||
self.start_three() | self.start_three() | ||||
self.sync_blocks() | self.sync_blocks() | ||||
assert_equal(self.nodes[0].getbalance(), balance0) | assert_equal(self.nodes[0].getbalance(), balance0) | ||||
assert_equal(self.nodes[1].getbalance(), balance1) | assert_equal(self.nodes[1].getbalance(), balance1) | ||||
assert_equal(self.nodes[2].getbalance(), balance2) | assert_equal(self.nodes[2].getbalance(), balance2) | ||||
Show All 27 Lines | def run_test(self): | ||||
self.sync_blocks() | self.sync_blocks() | ||||
assert_equal(self.nodes[0].getbalance(), balance0) | assert_equal(self.nodes[0].getbalance(), balance0) | ||||
assert_equal(self.nodes[1].getbalance(), balance1) | assert_equal(self.nodes[1].getbalance(), balance1) | ||||
assert_equal(self.nodes[2].getbalance(), balance2) | assert_equal(self.nodes[2].getbalance(), balance2) | ||||
# Backup to source wallet file must fail | # Backup to source wallet file must fail | ||||
sourcePaths = [ | sourcePaths = [ | ||||
os.path.join(self.nodes[0].datadir, | os.path.join(self.nodes[0].datadir, self.chain, 'wallets', | ||||
self.chain, 'wallets', 'wallet.dat'), | self.default_wallet_name, self.wallet_data_filename), | ||||
os.path.join(self.nodes[0].datadir, self.chain, | os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', | ||||
'.', 'wallets', 'wallet.dat'), | self.default_wallet_name, self.wallet_data_filename), | ||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''), | os.path.join(self.nodes[0].datadir, self.chain, 'wallets', | ||||
self.default_wallet_name), | |||||
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')] | os.path.join(self.nodes[0].datadir, self.chain, 'wallets')] | ||||
for sourcePath in sourcePaths: | for sourcePath in sourcePaths: | ||||
assert_raises_rpc_error(-4, "backup failed", | assert_raises_rpc_error(-4, "backup failed", | ||||
self.nodes[0].backupwallet, sourcePath) | self.nodes[0].backupwallet, sourcePath) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
WalletBackupTest().main() | WalletBackupTest().main() |