aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSamuel Dobson <dobsonsa68@gmail.com>2021-08-15 16:46:51 +1200
committerSamuel Dobson <dobsonsa68@gmail.com>2021-08-15 16:58:05 +1200
commit502d22ceed1f90ed41336260f8eb428d3acaf514 (patch)
tree962792ed52293c77b5c8da903401abe5bd658a45 /test
parentbe499aa07ff10957debc9b10a93d0781acec2e43 (diff)
parent5fe8100ff36fed6d50c2a25b028f57b25af3504c (diff)
Merge bitcoin/bitcoin#22541: Add a new RPC command: restorewallet
5fe8100ff36fed6d50c2a25b028f57b25af3504c Change the wallet_backup.py test to use the restorewallet RPC command instead of restoring wallets manually. (lsilva01) ae23faba6fc5cabc896f1175456d1018576f912d Add a new RPC command: restorewallet (lsilva01) Pull request description: As far as I know, there is no command to restore the wallet from a backup file. The only way to do this is to replace the `wallet.dat` of a newly created wallet with the backup file, which is hardly an intuitive way. This PR implements the `restorewallet` RPC command which restores the wallet from the backup file. To test: First create a backup file: `$ bitcoin-cli -rpcwallet="wallet-01" backupwallet /home/Backups/wallet-01.bak` Then restore it in another wallet: `$ bitcoin-cli restorewallet "restored-wallet-01" /home/Backups/wallet-01.bak` ACKs for top commit: achow101: re-ACK 5fe8100ff36fed6d50c2a25b028f57b25af3504c prayank23: tACK https://github.com/bitcoin/bitcoin/commit/5fe8100ff36fed6d50c2a25b028f57b25af3504c meshcollider: utACK 5fe8100ff36fed6d50c2a25b028f57b25af3504c Tree-SHA512: 9639df4d8ad32f255f5b868320dc69878bd9aceb3b471b49dfad500b67681e2d354292b5410982fbf18e25a44ed0c06fd4a0dd010e82807c2e00ff32e84047a1
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/wallet_backup.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py
index 05a0ef0ea1..c7a983556d 100755
--- a/test/functional/wallet_backup.py
+++ b/test/functional/wallet_backup.py
@@ -111,6 +111,18 @@ class WalletBackupTest(BitcoinTestFramework):
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 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 restore_nonexistent_wallet(self):
+ node = self.nodes[3]
+ nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak')
+ wallet_name = "res0"
+ assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file)
+
+ def restore_wallet_existent_name(self):
+ node = self.nodes[3]
+ wallet_file = os.path.join(self.nodes[0].datadir, 'wallet.bak')
+ wallet_name = "res0"
+ assert_raises_rpc_error(-8, "Wallet name already exists.", node.restorewallet, wallet_name, wallet_file)
+
def init_three(self):
self.init_wallet(0)
self.init_wallet(1)
@@ -169,26 +181,27 @@ class WalletBackupTest(BitcoinTestFramework):
##
# Test restoring spender wallets from backups
##
- self.log.info("Restoring using wallet.dat")
- self.stop_three()
- self.erase_three()
+ self.log.info("Restoring wallets on node 3 using backup files")
- # Start node2 with no chain
- 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.restore_nonexistent_wallet()
- # Restore wallets from backup
- 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))
+ backup_file_0 = os.path.join(self.nodes[0].datadir, 'wallet.bak')
+ backup_file_1 = os.path.join(self.nodes[1].datadir, 'wallet.bak')
+ backup_file_2 = os.path.join(self.nodes[2].datadir, 'wallet.bak')
- self.log.info("Re-starting nodes")
- self.start_three()
- self.sync_blocks()
+ self.nodes[3].restorewallet("res0", backup_file_0)
+ self.nodes[3].restorewallet("res1", backup_file_1)
+ self.nodes[3].restorewallet("res2", backup_file_2)
+
+ res0_rpc = self.nodes[3].get_wallet_rpc("res0")
+ res1_rpc = self.nodes[3].get_wallet_rpc("res1")
+ res2_rpc = self.nodes[3].get_wallet_rpc("res2")
+
+ assert_equal(res0_rpc.getbalance(), balance0)
+ assert_equal(res1_rpc.getbalance(), balance1)
+ assert_equal(res2_rpc.getbalance(), balance2)
- assert_equal(self.nodes[0].getbalance(), balance0)
- assert_equal(self.nodes[1].getbalance(), balance1)
- assert_equal(self.nodes[2].getbalance(), balance2)
+ self.restore_wallet_existent_name()
if not self.options.descriptors:
self.log.info("Restoring using dumped wallet")