Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251assert_equal(e.error["code"], -1)252assert_equal(e.error["message"], "Rescan aborted by user.")254def test_musig_private_key_warnings(self, xprv1, acc_xprv2, acc_xpub2, derivation_path):255self.log.info("Testing importdescriptors MuSig private key warnings")257self.nodes[1].createwallet(wallet_name="musig_import_warnings", blank=True)258wallet = self.nodes[1].get_wallet_rpc("musig_import_warnings")259res = wallet.importdescriptors([260{261"desc": descsum_create(f"rawtr(musig({xprv1}/{derivation_path}/0,{acc_xprv2}/1))"),262"timestamp": "now",263},264{265"desc": descsum_create(f"rawtr(musig({xprv1}/{derivation_path}/2,{acc_xpub2}/3))"),266"timestamp": "now",267},268{269"desc": descsum_create(f"rawtr(musig({xprv1}/{derivation_path},{acc_xprv2})/0/*)"),270"timestamp": "now",271"range": [0, 1],272},273{274"desc": descsum_create(f"rawtr(musig({xprv1}/{derivation_path},{acc_xpub2})/1/*)"),275"timestamp": "now",276"range": [0, 1],277},278])280assert_equal(res[0]["success"], True)281assert "warnings" not in res[0]282assert_equal(res[1]["success"], True)283assert_equal(res[1]["warnings"], [MISSING_KEYS_WARNING])284assert_equal(res[2]["success"], True)285assert "warnings" not in res[2]286assert_equal(res[3]["success"], True)287assert_equal(res[3]["warnings"], [MISSING_KEYS_WARNING])289def run_test(self):290self.log.info('Setting up wallets')291self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False)292w0 = self.nodes[0].get_wallet_rpc('w0')294self.nodes[1].createwallet(wallet_name='w1', disable_private_keys=True, blank=True)295w1 = self.nodes[1].get_wallet_rpc('w1')296assert_equal(w1.getwalletinfo()['keypoolsize'], 0)298self.nodes[1].createwallet(wallet_name="wpriv", disable_private_keys=False, blank=True)299wpriv = self.nodes[1].get_wallet_rpc("wpriv")300assert_equal(wpriv.getwalletinfo()['keypoolsize'], 0)302self.log.info('Mining coins')303self.generatetoaddress(self.nodes[0], COINBASE_MATURITY + 1, w0.getnewaddress())305# RPC importdescriptors -----------------------------------------------307# # Test import fails if no descriptor present308self.log.info("Import should fail if a descriptor is not provided")309self.test_importdesc({"timestamp": "now"},310success=False,311error_code=-8,312error_message='Descriptor not found.')314# Test import fails if one timestamp is invalid or missing315self.log.info("Import should fail if timestamp is missing or an invalid timestamp is present in the request")316key = get_generate_key()317import_request = {"desc": descsum_create("pkh(" + key.pubkey + ")"), "label": "Descriptor import test"}318self.test_importdesc(import_request,319success=False,320global_error=True,321error_code=-3,322error_message="Missing required timestamp field for key")324import_request = {"desc": descsum_create("pkh(" + key.pubkey + ")"),325"timestamp": "this_is_not_a_valid_timestamp",326"label": "Descriptor import test"}327self.test_importdesc(import_request,328success=False,329global_error=True,330error_code=-3,331error_message='Expected number or "now" timestamp value for key. got type string')333# # Test importing of a P2PKH descriptor334key = get_generate_key()335self.log.info("Should import a p2pkh descriptor")336import_request = {"desc": descsum_create("pkh(" + key.pubkey + ")"),337"timestamp": "now",338"label": "Descriptor import test"}339self.test_importdesc(import_request, success=True)340test_address(w1,341key.p2pkh_addr,342solvable=True,343ismine=True,344labels=["Descriptor import test"])345assert_equal(w1.getwalletinfo()['keypoolsize'], 0)347self.log.info("Test can import same descriptor with public key twice")348list_descs = w1.listdescriptors()349self.test_importdesc(import_request, success=True)350assert_equal(list_descs, w1.listdescriptors())352self.log.info("Test can update descriptor label")353self.test_importdesc({**import_request, "label": "Updated label"}, success=True)354test_address(w1, key.p2pkh_addr, solvable=True, ismine=True, labels=["Updated label"])355assert_equal(list_descs, w1.listdescriptors())357self.log.info("Internal addresses cannot have labels")358self.test_importdesc({**import_request, "internal": True},359success=False,360error_code=-8,361error_message="Internal addresses should not have a label")363self.log.info("External non-ranged addresses can have labels")364self.test_importdesc({**import_request, "internal": False}, success=True)366self.log.info("Internal addresses should be detected as such")367key = get_generate_key()368self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + ")"),369"timestamp": "now",370"internal": True},371success=True)372info = w1.getaddressinfo(key.p2pkh_addr)373assert_equal(info["ismine"], True)374assert_equal(info["ischange"], True)376self.log.info("Should not import a descriptor with an invalid public key due to whitespace")377self.test_importdesc({"desc": descsum_create("pkh( " + key.pubkey + ")"),378"timestamp": "now",379"internal": True},380error_code=-5,381error_message=f"pkh(): Key ' {key.pubkey}' is invalid due to whitespace",382success=False)383self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + " )"),384"timestamp": "now",385"internal": True},386error_code=-5,387error_message=f"pkh(): Key '{key.pubkey} ' is invalid due to whitespace",388success=False)390# # Test importing of a P2SH-P2WPKH descriptor391key = get_generate_key()392self.log.info("Should not import a p2sh-p2wpkh descriptor without checksum")393self.test_importdesc({"desc": "sh(wpkh(" + key.pubkey + "))",394"timestamp": "now"395},396success=False,397error_code=-5,398error_message="Missing checksum")400self.log.info("Should not import a p2sh-p2wpkh descriptor that has range specified")401self.test_importdesc({"desc": descsum_create("sh(wpkh(" + key.pubkey + "))"),402"timestamp": "now",403"range": 1,404},405success=False,406error_code=-8,407error_message="Range should not be specified for an un-ranged descriptor")409self.log.info("Should not import a p2sh-p2wpkh descriptor and have it set to active")410self.test_importdesc({"desc": descsum_create("sh(wpkh(" + key.pubkey + "))"),411"timestamp": "now",412"active": True,413},414success=False,415error_code=-8,416error_message="Active descriptors must be ranged")418self.log.info("Should import a (non-active) p2sh-p2wpkh descriptor")419self.test_importdesc({"desc": descsum_create("sh(wpkh(" + key.pubkey + "))"),420"timestamp": "now",421"active": False,422},423success=True)424assert_equal(w1.getwalletinfo()['keypoolsize'], 0)426test_address(w1,427key.p2sh_p2wpkh_addr,428ismine=True,429solvable=True)431# Check persistence of data and that loading works correctly432w1.unloadwallet()433self.nodes[1].loadwallet('w1')434test_address(w1,435key.p2sh_p2wpkh_addr,436ismine=True,437solvable=True)439# # Test importing of a multisig descriptor440key1 = get_generate_key()441key2 = get_generate_key()442self.log.info("Should import a 1-of-2 bare multisig from descriptor")443self.test_importdesc({"desc": descsum_create("multi(1," + key1.pubkey + "," + key2.pubkey + ")"),444"timestamp": "now"},445success=True)446self.log.info("Should not treat individual keys from the imported bare multisig as watchonly")447test_address(w1,448key1.p2pkh_addr,449ismine=False)451# # Test ranged descriptors452extended_key = ExtendedPrivateKey.generate()453xpriv = extended_key.to_string()454xpub = extended_key.pubkey().to_string()455pubkeys = [extended_key.derive_path(f"m/0'/0'/{i}'").pubkey().pubkey.get_bytes() for i in range(2)]456addresses = [key_to_p2sh_p2wpkh(pubkey) for pubkey in pubkeys] # hdkeypath=m/0'/0'/0' and 1'457addresses += [key_to_p2wpkh(pubkey) for pubkey in pubkeys] # wpkh subscripts corresponding to the above addresses458desc = "sh(wpkh(" + xpub + "/0/0/*" + "))"460self.log.info("Ranged descriptors cannot have labels")461self.test_importdesc({"desc":descsum_create(desc),462"timestamp": "now",463"range": [0, 100],464"label": "test"},465success=False,466error_code=-8,467error_message='Ranged descriptors should not have a label')469self.log.info("Ranged descriptors cannot have labels - even if range not provided by user and only implied by asterisk (*)")470self.test_importdesc({"desc":descsum_create("wpkh(" + xpub + "/100/0/*)"),471"timestamp": "now",472"label": "test",473"active": True},474success=False,475warnings=['Range not given, using default keypool range'],476error_code=-8,477error_message='Ranged descriptors should not have a label')479self.log.info("Private keys required for private keys enabled wallet")480self.test_importdesc({"desc":descsum_create(desc),481"timestamp": "now",482"range": [0, 100]},483success=False,484error_code=-4,485error_message='Cannot import descriptor without private keys to a wallet with private keys enabled',486wallet=wpriv)488self.log.info("Ranged descriptor import should warn without a specified range")489self.test_importdesc({"desc": descsum_create(desc),490"timestamp": "now"},491success=True,492warnings=['Range not given, using default keypool range'])493assert_equal(w1.getwalletinfo()['keypoolsize'], 0)495# # Test importing of a ranged descriptor with xpriv496self.log.info("Should not import a ranged descriptor that includes xpriv into a watch-only wallet")497desc = "sh(wpkh(" + xpriv + "/0'/0'/*'" + "))"498self.test_importdesc({"desc": descsum_create(desc),499"timestamp": "now",500"range": 1},
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.