aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_dump.py
diff options
context:
space:
mode:
authorBrandon Odiwuor <brandon.odiwuor@gmail.com>2023-10-09 15:30:40 +0300
committerBrandon Odiwuor <brandon.odiwuor@gmail.com>2023-10-10 18:12:31 +0300
commit004903ebade38ba47c5ddc17b756d605b963528e (patch)
tree1dd71fdea15ecce01ccc4be4ff324d9c7243271f /test/functional/wallet_dump.py
parentdb283a6b6f1419291bcd15d74d51c8598aefe06a (diff)
downloadbitcoin-004903ebade38ba47c5ddc17b756d605b963528e.tar.xz
test: Add Wallet Unlock Context Manager
Add Context Manager to manage wallet locking/unlocking with passphrase
Diffstat (limited to 'test/functional/wallet_dump.py')
-rwxr-xr-xtest/functional/wallet_dump.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 8c68d03f97..eaedbbed41 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -12,6 +12,7 @@ from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)
+from test_framework.wallet_util import WalletUnlock
def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
@@ -173,26 +174,26 @@ class WalletDumpTest(BitcoinTestFramework):
# encrypt wallet, restart, unlock and dump
self.nodes[0].encryptwallet('test')
- self.nodes[0].walletpassphrase("test", 999000)
- # Should be a no-op:
- self.nodes[0].keypoolrefill()
- self.nodes[0].dumpwallet(wallet_enc_dump)
-
- found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
- read_dump(wallet_enc_dump, addrs, [multisig_addr], hd_master_addr_unenc)
- assert '# End of dump' in found_comments # Check that file is not corrupt
- assert_equal(dump_time_str, next(c for c in found_comments if c.startswith('# * Created on')))
- assert_equal(dump_best_block_1, next(c for c in found_comments if c.startswith('# * Best block')))
- assert_equal(dump_best_block_2, next(c for c in found_comments if c.startswith('# mined on')))
- assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
- assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
- assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump
- assert_equal(found_script_addr, 1)
- assert_equal(found_addr_chg, 90 * 2) # old reserve keys are marked as change now
- assert_equal(found_addr_rsv, 90 * 2)
-
- # Overwriting should fail
- assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
+ with WalletUnlock(self.nodes[0], "test"):
+ # Should be a no-op:
+ self.nodes[0].keypoolrefill()
+ self.nodes[0].dumpwallet(wallet_enc_dump)
+
+ found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
+ read_dump(wallet_enc_dump, addrs, [multisig_addr], hd_master_addr_unenc)
+ assert '# End of dump' in found_comments # Check that file is not corrupt
+ assert_equal(dump_time_str, next(c for c in found_comments if c.startswith('# * Created on')))
+ assert_equal(dump_best_block_1, next(c for c in found_comments if c.startswith('# * Best block')))
+ assert_equal(dump_best_block_2, next(c for c in found_comments if c.startswith('# mined on')))
+ assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
+ assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
+ assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump
+ assert_equal(found_script_addr, 1)
+ assert_equal(found_addr_chg, 90 * 2) # old reserve keys are marked as change now
+ assert_equal(found_addr_rsv, 90 * 2)
+
+ # Overwriting should fail
+ assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
# Restart node with new wallet, and test importwallet
self.restart_node(0)