@@ -61,45 +61,8 @@ def run_test(self):
61
61
for nsigs in [2 , 3 ]:
62
62
for output_type in ["bech32" , "p2sh-segwit" , "legacy" ]:
63
63
self .do_multisig (nkeys , nsigs , output_type , wallet_multi )
64
- if wallet_multi is not None :
65
- wallet_multi .unloadwallet ()
66
-
67
- # Test mixed compressed and uncompressed pubkeys
68
- self .log .info ('Mixed compressed and uncompressed multisigs are not allowed' )
69
- pk0 , pk1 , pk2 = [getnewdestination ('bech32' )[0 ].hex () for _ in range (3 )]
70
-
71
- # decompress pk2
72
- pk_obj = ECPubKey ()
73
- pk_obj .set (bytes .fromhex (pk2 ))
74
- pk_obj .compressed = False
75
- pk2 = pk_obj .get_bytes ().hex ()
76
-
77
- if self .is_bdb_compiled ():
78
- node0 .createwallet (wallet_name = 'wmulti0' , disable_private_keys = True )
79
- wmulti0 = node0 .get_wallet_rpc ('wmulti0' )
80
-
81
- # Check all permutations of keys because order matters apparently
82
- for keys in itertools .permutations ([pk0 , pk1 , pk2 ]):
83
- # Results should be the same as this legacy one
84
- legacy_addr = node0 .createmultisig (2 , keys , 'legacy' )['address' ]
85
-
86
- if self .is_bdb_compiled ():
87
- result = wmulti0 .addmultisigaddress (2 , keys , '' , 'legacy' )
88
- assert_equal (legacy_addr , result ['address' ])
89
- assert 'warnings' not in result
90
-
91
- # Generate addresses with the segwit types. These should all make legacy addresses
92
- err_msg = ["Unable to make chosen address type, please ensure no uncompressed public keys are present." ]
93
64
94
- for addr_type in ['bech32' , 'p2sh-segwit' ]:
95
- result = self .nodes [0 ].createmultisig (nrequired = 2 , keys = keys , address_type = addr_type )
96
- assert_equal (legacy_addr , result ['address' ])
97
- assert_equal (result ['warnings' ], err_msg )
98
-
99
- if self .is_bdb_compiled ():
100
- result = wmulti0 .addmultisigaddress (nrequired = 2 , keys = keys , address_type = addr_type )
101
- assert_equal (legacy_addr , result ['address' ])
102
- assert_equal (result ['warnings' ], err_msg )
65
+ self .test_mixing_uncompressed_and_compressed_keys (node0 , wallet_multi )
103
66
104
67
self .log .info ('Testing sortedmulti descriptors with BIP 67 test vectors' )
105
68
with open (os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'data/rpc_bip67.json' ), encoding = 'utf-8' ) as f :
@@ -217,6 +180,41 @@ def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
217
180
txinfo = node0 .getrawtransaction (tx , True , blk )
218
181
self .log .info ("n/m=%d/%d %s size=%d vsize=%d weight=%d" % (nsigs , nkeys , output_type , txinfo ["size" ], txinfo ["vsize" ], txinfo ["weight" ]))
219
182
183
+ def test_mixing_uncompressed_and_compressed_keys (self , node , wallet_multi ):
184
+ self .log .info ('Mixed compressed and uncompressed multisigs are not allowed' )
185
+ pk0 , pk1 , pk2 = [getnewdestination ('bech32' )[0 ].hex () for _ in range (3 )]
186
+
187
+ # decompress pk2
188
+ pk_obj = ECPubKey ()
189
+ pk_obj .set (bytes .fromhex (pk2 ))
190
+ pk_obj .compressed = False
191
+ pk2 = pk_obj .get_bytes ().hex ()
192
+
193
+ # Check all permutations of keys because order matters apparently
194
+ for keys in itertools .permutations ([pk0 , pk1 , pk2 ]):
195
+ # Results should be the same as this legacy one
196
+ legacy_addr = node .createmultisig (2 , keys , 'legacy' )['address' ]
197
+
198
+ if wallet_multi is not None :
199
+ # 'addmultisigaddress' should return the same address
200
+ result = wallet_multi .addmultisigaddress (2 , keys , '' , 'legacy' )
201
+ assert_equal (legacy_addr , result ['address' ])
202
+ assert 'warnings' not in result
203
+
204
+ # Generate addresses with the segwit types. These should all make legacy addresses
205
+ err_msg = ["Unable to make chosen address type, please ensure no uncompressed public keys are present." ]
206
+
207
+ for addr_type in ['bech32' , 'p2sh-segwit' ]:
208
+ result = self .nodes [0 ].createmultisig (nrequired = 2 , keys = keys , address_type = addr_type )
209
+ assert_equal (legacy_addr , result ['address' ])
210
+ assert_equal (result ['warnings' ], err_msg )
211
+
212
+ if wallet_multi is not None :
213
+ result = wallet_multi .addmultisigaddress (nrequired = 2 , keys = keys , address_type = addr_type )
214
+ assert_equal (legacy_addr , result ['address' ])
215
+ assert_equal (result ['warnings' ], err_msg )
216
+
217
+
220
218
221
219
if __name__ == '__main__' :
222
220
RpcCreateMultiSigTest ().main ()
0 commit comments