Skip to content

Commit 5fe8100

Browse files
committed
Change the wallet_backup.py test to use the restorewallet RPC command instead of restoring wallets manually.
1 parent ae23fab commit 5fe8100

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

test/functional/wallet_backup.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ def erase_three(self):
111111
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
112112
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
113113

114+
def restore_nonexistent_wallet(self):
115+
node = self.nodes[3]
116+
nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak')
117+
wallet_name = "res0"
118+
assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file)
119+
120+
def restore_wallet_existent_name(self):
121+
node = self.nodes[3]
122+
wallet_file = os.path.join(self.nodes[0].datadir, 'wallet.bak')
123+
wallet_name = "res0"
124+
assert_raises_rpc_error(-8, "Wallet name already exists.", node.restorewallet, wallet_name, wallet_file)
125+
114126
def init_three(self):
115127
self.init_wallet(0)
116128
self.init_wallet(1)
@@ -169,26 +181,27 @@ def run_test(self):
169181
##
170182
# Test restoring spender wallets from backups
171183
##
172-
self.log.info("Restoring using wallet.dat")
173-
self.stop_three()
174-
self.erase_three()
184+
self.log.info("Restoring wallets on node 3 using backup files")
175185

176-
# Start node2 with no chain
177-
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
178-
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
186+
self.restore_nonexistent_wallet()
179187

180-
# Restore wallets from backup
181-
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))
182-
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))
183-
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))
188+
backup_file_0 = os.path.join(self.nodes[0].datadir, 'wallet.bak')
189+
backup_file_1 = os.path.join(self.nodes[1].datadir, 'wallet.bak')
190+
backup_file_2 = os.path.join(self.nodes[2].datadir, 'wallet.bak')
184191

185-
self.log.info("Re-starting nodes")
186-
self.start_three()
187-
self.sync_blocks()
192+
self.nodes[3].restorewallet("res0", backup_file_0)
193+
self.nodes[3].restorewallet("res1", backup_file_1)
194+
self.nodes[3].restorewallet("res2", backup_file_2)
195+
196+
res0_rpc = self.nodes[3].get_wallet_rpc("res0")
197+
res1_rpc = self.nodes[3].get_wallet_rpc("res1")
198+
res2_rpc = self.nodes[3].get_wallet_rpc("res2")
199+
200+
assert_equal(res0_rpc.getbalance(), balance0)
201+
assert_equal(res1_rpc.getbalance(), balance1)
202+
assert_equal(res2_rpc.getbalance(), balance2)
188203

189-
assert_equal(self.nodes[0].getbalance(), balance0)
190-
assert_equal(self.nodes[1].getbalance(), balance1)
191-
assert_equal(self.nodes[2].getbalance(), balance2)
204+
self.restore_wallet_existent_name()
192205

193206
if not self.options.descriptors:
194207
self.log.info("Restoring using dumped wallet")

0 commit comments

Comments
 (0)