Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_keypool_topup.py
Show All 15 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
class KeypoolRestoreTest(BitcoinTestFramework): | class KeypoolRestoreTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [[], ['-keypool=100']] | self.extra_args = [[], ["-keypool=100"]] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
wallet_path = os.path.join( | wallet_path = os.path.join( | ||||
self.nodes[1].datadir, self.chain, "wallets", | self.nodes[1].datadir, | ||||
self.default_wallet_name, self.wallet_data_filename) | self.chain, | ||||
"wallets", | |||||
self.default_wallet_name, | |||||
self.wallet_data_filename, | |||||
) | |||||
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak") | wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak") | ||||
self.generate(self.nodes[0], 101) | self.generate(self.nodes[0], 101) | ||||
self.log.info("Make backup of wallet") | self.log.info("Make backup of wallet") | ||||
self.stop_node(1) | self.stop_node(1) | ||||
shutil.copyfile(wallet_path, wallet_backup_path) | shutil.copyfile(wallet_path, wallet_backup_path) | ||||
self.start_node(1, self.extra_args[1]) | self.start_node(1, self.extra_args[1]) | ||||
self.connect_nodes(0, 1) | self.connect_nodes(0, 1) | ||||
Show All 14 Lines | def run_test(self): | ||||
self.stop_node(1) | self.stop_node(1) | ||||
shutil.copyfile(wallet_backup_path, wallet_path) | shutil.copyfile(wallet_backup_path, wallet_path) | ||||
self.start_node(1, self.extra_args[1]) | self.start_node(1, self.extra_args[1]) | ||||
self.connect_nodes(0, 1) | self.connect_nodes(0, 1) | ||||
self.sync_all() | self.sync_all() | ||||
self.log.info("Verify keypool is restored and balance is correct") | self.log.info("Verify keypool is restored and balance is correct") | ||||
assert_equal(self.nodes[1].getbalance(), 15000000) | assert_equal(self.nodes[1].getbalance(), 15000000) | ||||
assert_equal(self.nodes[1].listtransactions() | assert_equal(self.nodes[1].listtransactions()[0]["category"], "receive") | ||||
[0]['category'], "receive") | |||||
# Check that we have marked all keys up to the used keypool key as used | # Check that we have marked all keys up to the used keypool key as used | ||||
if self.options.descriptors: | if self.options.descriptors: | ||||
assert_equal( | assert_equal( | ||||
self.nodes[1].getaddressinfo( | self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())[ | ||||
self.nodes[1].getnewaddress())['hdkeypath'], | "hdkeypath" | ||||
"m/44'/1'/0'/0/110") | ], | ||||
"m/44'/1'/0'/0/110", | |||||
) | |||||
else: | else: | ||||
assert_equal( | assert_equal( | ||||
self.nodes[1].getaddressinfo( | self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())[ | ||||
self.nodes[1].getnewaddress())['hdkeypath'], | "hdkeypath" | ||||
"m/0'/0'/110'") | ], | ||||
"m/0'/0'/110'", | |||||
) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
KeypoolRestoreTest().main() | KeypoolRestoreTest().main() |