aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_dump.py
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-10-19 10:07:55 +0100
committerfanquake <fanquake@gmail.com>2023-10-19 10:23:44 +0100
commit091d29c49590d31dacdace24a8ae0fb781665ed6 (patch)
tree659ff858a767d0f2635f0724cc882a87cc789300 /test/functional/wallet_dump.py
parent5eb82d5706ea1b3b9eee2daaf6e47d1405549d4f (diff)
parent004903ebade38ba47c5ddc17b756d605b963528e (diff)
downloadbitcoin-091d29c49590d31dacdace24a8ae0fb781665ed6.tar.xz
Merge bitcoin/bitcoin#28617: test: Add Wallet Unlock Context Manager
004903ebade38ba47c5ddc17b756d605b963528e test: Add Wallet Unlock Context Manager (Brandon Odiwuor) Pull request description: Fixes #28601, see https://github.com/bitcoin/bitcoin/pull/28403#discussion_r1325426430 Add Context Manager to manage the locking and unlocking of locked wallets with a passphrase during testing. ACKs for top commit: kevkevinpal: lgtm ACK [004903e](https://github.com/bitcoin/bitcoin/pull/28617/commits/004903ebade38ba47c5ddc17b756d605b963528e) maflcko: lgtm ACK 004903ebade38ba47c5ddc17b756d605b963528e Tree-SHA512: ab234c167e71531df0d974ff9a31d444f7ce2a1d05aba5ea868cc9452f139845eeb24ca058d88f058bc02482b762adf2d99e63a6640b872cc71a57a0068abfe8
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 fdce9739eb..f50aae0c53 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -11,6 +11,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):
@@ -172,26 +173,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)