@@ -24,7 +24,42 @@ def run_test(self):
2424 self .stop_node (0 )
2525 self .nodes [0 ].assert_start_raises_init_error (['-mnemonicbits=123' ], "Error: Invalid '-mnemonicbits'. Allowed values: 128, 160, 192, 224, 256." )
2626 self .start_node (0 )
27- assert_equal (len (self .nodes [0 ].dumphdinfo ()["mnemonic" ].split ()), 12 ) # 12 words by default
27+
28+ mnemonic_pre = self .nodes [0 ].listdescriptors (True )['descriptors' ][1 ]["mnemonic" ] if self .options .descriptors else self .nodes [0 ].dumphdinfo ()["mnemonic" ]
29+
30+ self .nodes [0 ].encryptwallet ('pass' )
31+ self .nodes [0 ].walletpassphrase ('pass' , 100 )
32+ if self .options .descriptors :
33+ assert "mnemonic" not in self .nodes [0 ].listdescriptors ()['descriptors' ][0 ]
34+ assert "mnemonic" in self .nodes [0 ].listdescriptors (True )['descriptors' ][0 ]
35+
36+ descriptors = self .nodes [0 ].listdescriptors (True )['descriptors' ]
37+ assert_equal (descriptors [0 ]['mnemonic' ], descriptors [1 ]['mnemonic' ])
38+
39+ mnemonic_count = 0
40+ found_in_encrypted = 0
41+ for desc in descriptors :
42+ if 'mnemonic' not in desc :
43+ # skip imported coinbase private key
44+ continue
45+ assert_equal (len (desc ['mnemonic' ].split ()), 12 )
46+ mnemonic_count += 1
47+ if desc ['mnemonic' ] == mnemonic_pre :
48+ found_in_encrypted += 1
49+ assert not desc ['active' ]
50+ else :
51+ assert desc ['active' ]
52+ # there should 5 descriptors in total
53+ # one of them imported private key for coinbase without mnemonic
54+ # encryption of descriptor wallet creates new private keys,
55+ # it should be 2 active and 2 inactive mnemonics
56+ assert_equal (found_in_encrypted , 2 )
57+ assert_equal (mnemonic_count , 4 )
58+ assert_equal (len (descriptors ), 5 )
59+ else :
60+ assert_equal (len (self .nodes [0 ].dumphdinfo ()["mnemonic" ].split ()), 12 ) # 12 words by default
61+ # legacy HD wallets could have only one chain
62+ assert_equal (mnemonic_pre , self .nodes [0 ].dumphdinfo ()["mnemonic" ])
2863
2964 self .log .info ("Can have multiple wallets with different mnemonic length loaded at the same time" )
3065 self .restart_node (0 , extra_args = ["-mnemonicbits=160" ])
@@ -34,16 +69,27 @@ def run_test(self):
3469 self .restart_node (0 , extra_args = ["-mnemonicbits=224" ])
3570 self .nodes [0 ].createwallet ("wallet_224" )
3671 self .restart_node (0 , extra_args = ["-mnemonicbits=256" ])
72+ self .nodes [0 ].get_wallet_rpc (self .default_wallet_name ).walletpassphrase ('pass' , 100 )
3773 self .nodes [0 ].loadwallet ("wallet_160" )
3874 self .nodes [0 ].loadwallet ("wallet_192" )
3975 self .nodes [0 ].loadwallet ("wallet_224" )
40- self .nodes [0 ].createwallet ("wallet_256" , False , True ) # blank
41- self .nodes [0 ].get_wallet_rpc ("wallet_256" ).upgradetohd ()
42- assert_equal (len (self .nodes [0 ].get_wallet_rpc (self .default_wallet_name ).dumphdinfo ()["mnemonic" ].split ()), 12 ) # 12 words by default
43- assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_160" ).dumphdinfo ()["mnemonic" ].split ()), 15 ) # 15 words
44- assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_192" ).dumphdinfo ()["mnemonic" ].split ()), 18 ) # 18 words
45- assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_224" ).dumphdinfo ()["mnemonic" ].split ()), 21 ) # 21 words
46- assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_256" ).dumphdinfo ()["mnemonic" ].split ()), 24 ) # 24 words
76+ if self .options .descriptors :
77+ self .nodes [0 ].createwallet ("wallet_256" , False , True , "" , False , True ) # blank Descriptors
78+ self .nodes [0 ].get_wallet_rpc ("wallet_256" ).upgradetohd ()
79+ # first descriptor is private key with no mnemonic for CbTx (see node.importprivkey), we use number#1 here instead
80+ assert_equal (len (self .nodes [0 ].get_wallet_rpc (self .default_wallet_name ).listdescriptors (True )["descriptors" ][1 ]["mnemonic" ].split ()), 12 ) # 12 words by default
81+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_160" ).listdescriptors (True )["descriptors" ][0 ]["mnemonic" ].split ()), 15 ) # 15 words
82+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_192" ).listdescriptors (True )["descriptors" ][0 ]["mnemonic" ].split ()), 18 ) # 18 words
83+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_224" ).listdescriptors (True )["descriptors" ][0 ]["mnemonic" ].split ()), 21 ) # 21 words
84+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_256" ).listdescriptors (True )["descriptors" ][0 ]["mnemonic" ].split ()), 24 ) # 24 words
85+ else :
86+ self .nodes [0 ].createwallet ("wallet_256" , False , True ) # blank HD legacy
87+ self .nodes [0 ].get_wallet_rpc ("wallet_256" ).upgradetohd ()
88+ assert_equal (len (self .nodes [0 ].get_wallet_rpc (self .default_wallet_name ).dumphdinfo ()["mnemonic" ].split ()), 12 ) # 12 words by default
89+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_160" ).dumphdinfo ()["mnemonic" ].split ()), 15 ) # 15 words
90+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_192" ).dumphdinfo ()["mnemonic" ].split ()), 18 ) # 18 words
91+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_224" ).dumphdinfo ()["mnemonic" ].split ()), 21 ) # 21 words
92+ assert_equal (len (self .nodes [0 ].get_wallet_rpc ("wallet_256" ).dumphdinfo ()["mnemonic" ].split ()), 24 ) # 24 words
4793
4894
4995if __name__ == '__main__' :
0 commit comments