@@ -626,5 +626,70 @@ def run_test(self):
626
626
iswatchonly = False )
627
627
628
628
629
+ # Import pubkeys with key origin info
630
+ self .log .info ("Addresses should have hd keypath and master key id after import with key origin" )
631
+ pub_addr = self .nodes [1 ].getnewaddress ()
632
+ pub_addr = self .nodes [1 ].getnewaddress ()
633
+ info = self .nodes [1 ].getaddressinfo (pub_addr )
634
+ pub = info ['pubkey' ]
635
+ pub_keypath = info ['hdkeypath' ]
636
+ pub_fpr = info ['hdmasterfingerprint' ]
637
+ result = self .nodes [0 ].importmulti (
638
+ [{
639
+ 'desc' : "wpkh([" + pub_fpr + pub_keypath [1 :] + "]" + pub + ")" ,
640
+ "timestamp" : "now" ,
641
+ }]
642
+ )
643
+ assert result [0 ]['success' ]
644
+ pub_import_info = self .nodes [0 ].getaddressinfo (pub_addr )
645
+ assert_equal (pub_import_info ['hdmasterfingerprint' ], pub_fpr )
646
+ assert_equal (pub_import_info ['pubkey' ], pub )
647
+ assert_equal (pub_import_info ['hdkeypath' ], pub_keypath )
648
+
649
+ # Import privkeys with key origin info
650
+ priv_addr = self .nodes [1 ].getnewaddress ()
651
+ info = self .nodes [1 ].getaddressinfo (priv_addr )
652
+ priv = self .nodes [1 ].dumpprivkey (priv_addr )
653
+ priv_keypath = info ['hdkeypath' ]
654
+ priv_fpr = info ['hdmasterfingerprint' ]
655
+ result = self .nodes [0 ].importmulti (
656
+ [{
657
+ 'desc' : "wpkh([" + priv_fpr + priv_keypath [1 :] + "]" + priv + ")" ,
658
+ "timestamp" : "now" ,
659
+ }]
660
+ )
661
+ assert result [0 ]['success' ]
662
+ priv_import_info = self .nodes [0 ].getaddressinfo (priv_addr )
663
+ assert_equal (priv_import_info ['hdmasterfingerprint' ], priv_fpr )
664
+ assert_equal (priv_import_info ['hdkeypath' ], priv_keypath )
665
+
666
+ # Make sure the key origin info are still there after a restart
667
+ self .stop_nodes ()
668
+ self .start_nodes ()
669
+ import_info = self .nodes [0 ].getaddressinfo (pub_addr )
670
+ assert_equal (import_info ['hdmasterfingerprint' ], pub_fpr )
671
+ assert_equal (import_info ['hdkeypath' ], pub_keypath )
672
+ import_info = self .nodes [0 ].getaddressinfo (priv_addr )
673
+ assert_equal (import_info ['hdmasterfingerprint' ], priv_fpr )
674
+ assert_equal (import_info ['hdkeypath' ], priv_keypath )
675
+
676
+ # Check legacy import does not import key origin info
677
+ self .log .info ("Legacy imports don't have key origin info" )
678
+ pub_addr = self .nodes [1 ].getnewaddress ()
679
+ info = self .nodes [1 ].getaddressinfo (pub_addr )
680
+ pub = info ['pubkey' ]
681
+ result = self .nodes [0 ].importmulti (
682
+ [{
683
+ 'scriptPubKey' : {'address' : pub_addr },
684
+ 'pubkeys' : [pub ],
685
+ "timestamp" : "now" ,
686
+ }]
687
+ )
688
+ assert result [0 ]['success' ]
689
+ pub_import_info = self .nodes [0 ].getaddressinfo (pub_addr )
690
+ assert_equal (pub_import_info ['pubkey' ], pub )
691
+ assert 'hdmasterfingerprint' not in pub_import_info
692
+ assert 'hdkeypath' not in pub_import_info
693
+
629
694
if __name__ == '__main__' :
630
695
ImportMultiTest ().main ()
0 commit comments