@@ -203,7 +203,7 @@ def run_test(self):
203203 "keys" : [key .privkey ]},
204204 success = False ,
205205 error_code = - 4 ,
206- error_message = 'The wallet already contains the private key for this address or script' )
206+ error_message = 'The wallet already contains the private key for this address or script ("' + key . p2pkh_script + '") ' )
207207
208208 # Address + Private key + watchonly
209209 self .log .info ("Should import an address with private key and with watchonly" )
@@ -543,5 +543,88 @@ def run_test(self):
543543 solvable = True ,
544544 ismine = False )
545545
546+ # Test importing of a P2SH-P2WPKH address via descriptor + private key
547+ key = get_key (self .nodes [0 ])
548+ self .log .info ("Should import a p2sh-p2wpkh address from descriptor and private key" )
549+ self .test_importmulti ({"desc" : "sh(wpkh(" + key .pubkey + "))" ,
550+ "timestamp" : "now" ,
551+ "label" : "Descriptor import test" ,
552+ "keys" : [key .privkey ]},
553+ success = True )
554+ test_address (self .nodes [1 ],
555+ key .p2sh_p2wpkh_addr ,
556+ solvable = True ,
557+ ismine = True ,
558+ label = "Descriptor import test" )
559+
560+ # Test ranged descriptor fails if range is not specified
561+ xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg"
562+ addresses = ["2N7yv4p8G8yEaPddJxY41kPihnWvs39qCMf" , "2MsHxyb2JS3pAySeNUsJ7mNnurtpeenDzLA" ] # hdkeypath=m/0'/0'/0' and 1'
563+ desc = "sh(wpkh(" + xpriv + "/0'/0'/*'" + "))"
564+ self .log .info ("Ranged descriptor import should fail without a specified range" )
565+ self .test_importmulti ({"desc" : desc ,
566+ "timestamp" : "now" },
567+ success = False ,
568+ error_code = - 8 ,
569+ error_message = 'Descriptor is ranged, please specify the range' )
570+
571+ # Test importing of a ranged descriptor without keys
572+ self .log .info ("Should import the ranged descriptor with specified range as solvable" )
573+ self .test_importmulti ({"desc" : desc ,
574+ "timestamp" : "now" ,
575+ "range" : {"end" : 1 }},
576+ success = True ,
577+ warnings = ["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag." ])
578+ for address in addresses :
579+ test_address (self .nodes [1 ],
580+ key .p2sh_p2wpkh_addr ,
581+ solvable = True )
582+
583+ # Test importing of a P2PKH address via descriptor
584+ key = get_key (self .nodes [0 ])
585+ self .log .info ("Should import a p2pkh address from descriptor" )
586+ self .test_importmulti ({"desc" : "pkh(" + key .pubkey + ")" ,
587+ "timestamp" : "now" ,
588+ "label" : "Descriptor import test" },
589+ True ,
590+ warnings = ["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag." ])
591+ test_address (self .nodes [1 ],
592+ key .p2pkh_addr ,
593+ solvable = True ,
594+ ismine = False ,
595+ label = "Descriptor import test" )
596+
597+ # Test import fails if both desc and scriptPubKey are provided
598+ key = get_key (self .nodes [0 ])
599+ self .log .info ("Import should fail if both scriptPubKey and desc are provided" )
600+ self .test_importmulti ({"desc" : "pkh(" + key .pubkey + ")" ,
601+ "scriptPubKey" : {"address" : key .p2pkh_addr },
602+ "timestamp" : "now" },
603+ success = False ,
604+ error_code = - 8 ,
605+ error_message = 'Both a descriptor and a scriptPubKey should not be provided.' )
606+
607+ # Test import fails if neither desc nor scriptPubKey are present
608+ key = get_key (self .nodes [0 ])
609+ self .log .info ("Import should fail if neither a descriptor nor a scriptPubKey are provided" )
610+ self .test_importmulti ({"timestamp" : "now" },
611+ success = False ,
612+ error_code = - 8 ,
613+ error_message = 'Either a descriptor or scriptPubKey must be provided.' )
614+
615+ # Test importing of a multisig via descriptor
616+ key1 = get_key (self .nodes [0 ])
617+ key2 = get_key (self .nodes [0 ])
618+ self .log .info ("Should import a 1-of-2 bare multisig from descriptor" )
619+ self .test_importmulti ({"desc" : "multi(1," + key1 .pubkey + "," + key2 .pubkey + ")" ,
620+ "timestamp" : "now" },
621+ success = True )
622+ self .log .info ("Should not treat individual keys from the imported bare multisig as watchonly" )
623+ test_address (self .nodes [1 ],
624+ key1 .p2pkh_addr ,
625+ ismine = False ,
626+ iswatchonly = False )
627+
628+
546629if __name__ == '__main__' :
547630 ImportMultiTest ().main ()
0 commit comments