@@ -24,7 +24,42 @@ def run_test(self):
24
24
self .stop_node (0 )
25
25
self .nodes [0 ].assert_start_raises_init_error (['-mnemonicbits=123' ], "Error: Invalid '-mnemonicbits'. Allowed values: 128, 160, 192, 224, 256." )
26
26
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" ])
28
63
29
64
self .log .info ("Can have multiple wallets with different mnemonic length loaded at the same time" )
30
65
self .restart_node (0 , extra_args = ["-mnemonicbits=160" ])
@@ -34,16 +69,27 @@ def run_test(self):
34
69
self .restart_node (0 , extra_args = ["-mnemonicbits=224" ])
35
70
self .nodes [0 ].createwallet ("wallet_224" )
36
71
self .restart_node (0 , extra_args = ["-mnemonicbits=256" ])
72
+ self .nodes [0 ].get_wallet_rpc (self .default_wallet_name ).walletpassphrase ('pass' , 100 )
37
73
self .nodes [0 ].loadwallet ("wallet_160" )
38
74
self .nodes [0 ].loadwallet ("wallet_192" )
39
75
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
47
93
48
94
49
95
if __name__ == '__main__' :
0 commit comments