mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge bitcoin/bitcoin#25634: wallet, tests: Expand and test when the blank wallet flag should be un/set
cdba23db35wallet: Document blank flag use in descriptor wallets (Ryan Ofsky)43310200dcwallet: Ensure that the blank wallet flag is unset after imports (Andrew Chow)e9379f1ffarpc, wallet: Include information about blank flag (Andrew Chow) Pull request description: The `blank` wallet flag is used to indicate that the wallet intentionally does not have any keys, scripts, or descriptors, and it prevents the automatic generation of those things for such a wallet. Once the wallet contains any of those data, it is unnecessary, and possibly incorrect, to have `blank` set. This PR fixes a few places where this was not properly happening. It also adds a test for this unset behavior. ACKs for top commit: S3RK: reACKcdba23db35ryanofsky: Code review ACKcdba23db35. Only change since last review is dropping the commit which makes createwallet RPC set BLANK flag automatically when DISABLE_PRIVATE_KEYS flag is set Tree-SHA512: 85bc2a9754df0531575d5c8f4ad7e8f38dcd50083dc29b3283dacf56feae842e81f34654c5e1781f2dadb0560ff80e454bbc8ca3b2d1fab1b236499ae9abd7da
This commit is contained in:
@@ -166,6 +166,8 @@ BASE_SCRIPTS = [
|
||||
'p2p_compactblocks_blocksonly.py',
|
||||
'wallet_hd.py --legacy-wallet',
|
||||
'wallet_hd.py --descriptors',
|
||||
'wallet_blank.py --legacy-wallet',
|
||||
'wallet_blank.py --descriptors',
|
||||
'wallet_keypool_topup.py --legacy-wallet',
|
||||
'wallet_keypool_topup.py --descriptors',
|
||||
'wallet_fast_rescan.py --descriptors',
|
||||
|
||||
170
test/functional/wallet_blank.py
Executable file
170
test/functional/wallet_blank.py
Executable file
@@ -0,0 +1,170 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2022 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or https://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import os
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.address import (
|
||||
ADDRESS_BCRT1_UNSPENDABLE,
|
||||
ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR,
|
||||
)
|
||||
from test_framework.key import ECKey
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
from test_framework.wallet_util import bytes_to_wif
|
||||
|
||||
|
||||
class WalletBlankTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def add_options(self, options):
|
||||
self.add_wallet_options(options)
|
||||
|
||||
def test_importaddress(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importaddress unsets the blank flag")
|
||||
self.nodes[0].createwallet(wallet_name="iaddr", disable_private_keys=True, blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("iaddr")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
wallet.importaddress(ADDRESS_BCRT1_UNSPENDABLE)
|
||||
assert_equal(wallet.getwalletinfo()["blank"], False)
|
||||
|
||||
def test_importpubkey(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importpubkey unsets the blank flag")
|
||||
for i, comp in enumerate([True, False]):
|
||||
self.nodes[0].createwallet(wallet_name=f"ipub{i}", disable_private_keys=True, blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc(f"ipub{i}")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
|
||||
eckey = ECKey()
|
||||
eckey.generate(compressed=comp)
|
||||
|
||||
wallet.importpubkey(eckey.get_pubkey().get_bytes().hex())
|
||||
assert_equal(wallet.getwalletinfo()["blank"], False)
|
||||
|
||||
def test_importprivkey(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importprivkey unsets the blank flag")
|
||||
for i, comp in enumerate([True, False]):
|
||||
self.nodes[0].createwallet(wallet_name=f"ipriv{i}", blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc(f"ipriv{i}")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
|
||||
eckey = ECKey()
|
||||
eckey.generate(compressed=comp)
|
||||
wif = bytes_to_wif(eckey.get_bytes(), eckey.is_compressed)
|
||||
|
||||
wallet.importprivkey(wif)
|
||||
assert_equal(wallet.getwalletinfo()["blank"], False)
|
||||
|
||||
def test_importmulti(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importmulti unsets the blank flag")
|
||||
self.nodes[0].createwallet(wallet_name="imulti", disable_private_keys=True, blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("imulti")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
wallet.importmulti([{
|
||||
"desc": ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR,
|
||||
"timestamp": "now",
|
||||
}])
|
||||
assert_equal(wallet.getwalletinfo()["blank"], False)
|
||||
|
||||
def test_importdescriptors(self):
|
||||
if not self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importdescriptors preserves the blank flag")
|
||||
self.nodes[0].createwallet(wallet_name="idesc", disable_private_keys=True, blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("idesc")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], True)
|
||||
assert_equal(info["blank"], True)
|
||||
wallet.importdescriptors([{
|
||||
"desc": ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR,
|
||||
"timestamp": "now",
|
||||
}])
|
||||
assert_equal(wallet.getwalletinfo()["blank"], True)
|
||||
|
||||
def test_importwallet(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that importwallet unsets the blank flag")
|
||||
def_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||
|
||||
self.nodes[0].createwallet(wallet_name="iwallet", blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("iwallet")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
|
||||
wallet_dump_path = os.path.join(self.nodes[0].datadir, "wallet.dump")
|
||||
def_wallet.dumpwallet(wallet_dump_path)
|
||||
|
||||
wallet.importwallet(wallet_dump_path)
|
||||
assert_equal(wallet.getwalletinfo()["blank"], False)
|
||||
|
||||
def test_encrypt_legacy(self):
|
||||
if self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that encrypting a blank legacy wallet preserves the blank flag and does not generate a seed")
|
||||
self.nodes[0].createwallet(wallet_name="encblanklegacy", blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("encblanklegacy")
|
||||
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], False)
|
||||
assert_equal(info["blank"], True)
|
||||
assert "hdseedid" not in info
|
||||
|
||||
wallet.encryptwallet("pass")
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["blank"], True)
|
||||
assert "hdseedid" not in info
|
||||
|
||||
def test_encrypt_descriptors(self):
|
||||
if not self.options.descriptors:
|
||||
return
|
||||
self.log.info("Test that encrypting a blank descriptor wallet preserves the blank flag and descriptors remain the same")
|
||||
self.nodes[0].createwallet(wallet_name="encblankdesc", blank=True)
|
||||
wallet = self.nodes[0].get_wallet_rpc("encblankdesc")
|
||||
|
||||
info = wallet.getwalletinfo()
|
||||
assert_equal(info["descriptors"], True)
|
||||
assert_equal(info["blank"], True)
|
||||
descs = wallet.listdescriptors()
|
||||
|
||||
wallet.encryptwallet("pass")
|
||||
assert_equal(wallet.getwalletinfo()["blank"], True)
|
||||
assert_equal(descs, wallet.listdescriptors())
|
||||
|
||||
def run_test(self):
|
||||
self.test_importaddress()
|
||||
self.test_importpubkey()
|
||||
self.test_importprivkey()
|
||||
self.test_importmulti()
|
||||
self.test_importdescriptors()
|
||||
self.test_importwallet()
|
||||
self.test_encrypt_legacy()
|
||||
self.test_encrypt_descriptors()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletBlankTest().main()
|
||||
Reference in New Issue
Block a user