18
18
assert_equal ,
19
19
)
20
20
from test_framework .wallet_util import bytes_to_wif
21
+ from test_framework .wallet import (
22
+ MiniWallet ,
23
+ getnewdestination ,
24
+ )
21
25
22
26
class RpcCreateMultiSigTest (BitcoinTestFramework ):
23
27
def set_test_params (self ):
24
28
self .setup_clean_chain = True
25
29
self .num_nodes = 3
26
30
self .supports_cli = False
27
-
28
- def skip_test_if_missing_module (self ):
29
- self .skip_if_no_wallet ()
31
+ if self .is_bdb_compiled ():
32
+ self .requires_wallet = True
30
33
31
34
def get_keys (self ):
32
35
self .pub = []
@@ -37,57 +40,66 @@ def get_keys(self):
37
40
k .generate ()
38
41
self .pub .append (k .get_pubkey ().get_bytes ().hex ())
39
42
self .priv .append (bytes_to_wif (k .get_bytes (), k .is_compressed ))
40
- self .final = node2 .getnewaddress ()
43
+ if self .is_bdb_compiled ():
44
+ self .final = node2 .getnewaddress ()
45
+ else :
46
+ self .final = getnewdestination ()[2 ]
41
47
42
48
def run_test (self ):
43
49
node0 , node1 , node2 = self .nodes
50
+ self .wallet = MiniWallet (test_node = node0 )
44
51
45
- self .check_addmultisigaddress_errors ()
52
+ if self .is_bdb_compiled ():
53
+ self .check_addmultisigaddress_errors ()
46
54
47
55
self .log .info ('Generating blocks ...' )
48
- self .generate (node0 , 149 )
56
+ self .generate (self . wallet , 149 )
49
57
50
58
self .moved = 0
51
59
for self .nkeys in [3 , 5 ]:
52
60
for self .nsigs in [2 , 3 ]:
53
61
for self .output_type in ["bech32" , "p2sh-segwit" , "legacy" ]:
54
62
self .get_keys ()
55
63
self .do_multisig ()
56
-
57
- self .checkbalances ()
64
+ if self . is_bdb_compiled ():
65
+ self .checkbalances ()
58
66
59
67
# Test mixed compressed and uncompressed pubkeys
60
68
self .log .info ('Mixed compressed and uncompressed multisigs are not allowed' )
61
- pk0 = node0 . getaddressinfo ( node0 . getnewaddress ())[ 'pubkey' ]
62
- pk1 = node1 . getaddressinfo ( node1 . getnewaddress ())[ 'pubkey' ]
63
- pk2 = node2 . getaddressinfo ( node2 . getnewaddress ())[ 'pubkey' ]
69
+ pk0 = getnewdestination ()[ 0 ]. hex ()
70
+ pk1 = getnewdestination ()[ 0 ]. hex ()
71
+ pk2 = getnewdestination ()[ 0 ]. hex ()
64
72
65
73
# decompress pk2
66
74
pk_obj = ECPubKey ()
67
75
pk_obj .set (bytes .fromhex (pk2 ))
68
76
pk_obj .compressed = False
69
77
pk2 = pk_obj .get_bytes ().hex ()
70
78
71
- node0 .createwallet (wallet_name = 'wmulti0' , disable_private_keys = True )
72
- wmulti0 = node0 .get_wallet_rpc ('wmulti0' )
79
+ if self .is_bdb_compiled ():
80
+ node0 .createwallet (wallet_name = 'wmulti0' , disable_private_keys = True )
81
+ wmulti0 = node0 .get_wallet_rpc ('wmulti0' )
73
82
74
83
# Check all permutations of keys because order matters apparently
75
84
for keys in itertools .permutations ([pk0 , pk1 , pk2 ]):
76
85
# Results should be the same as this legacy one
77
86
legacy_addr = node0 .createmultisig (2 , keys , 'legacy' )['address' ]
78
- result = wmulti0 .addmultisigaddress (2 , keys , '' , 'legacy' )
79
- assert_equal (legacy_addr , result ['address' ])
80
- assert 'warnings' not in result
87
+
88
+ if self .is_bdb_compiled ():
89
+ result = wmulti0 .addmultisigaddress (2 , keys , '' , 'legacy' )
90
+ assert_equal (legacy_addr , result ['address' ])
91
+ assert 'warnings' not in result
81
92
82
93
# Generate addresses with the segwit types. These should all make legacy addresses
83
94
for addr_type in ['bech32' , 'p2sh-segwit' ]:
84
- result = wmulti0 .createmultisig (2 , keys , addr_type )
95
+ result = self . nodes [ 0 ] .createmultisig (2 , keys , addr_type )
85
96
assert_equal (legacy_addr , result ['address' ])
86
97
assert_equal (result ['warnings' ], ["Unable to make chosen address type, please ensure no uncompressed public keys are present." ])
87
98
88
- result = wmulti0 .addmultisigaddress (2 , keys , '' , addr_type )
89
- assert_equal (legacy_addr , result ['address' ])
90
- assert_equal (result ['warnings' ], ["Unable to make chosen address type, please ensure no uncompressed public keys are present." ])
99
+ if self .is_bdb_compiled ():
100
+ result = wmulti0 .addmultisigaddress (2 , keys , '' , addr_type )
101
+ assert_equal (legacy_addr , result ['address' ])
102
+ assert_equal (result ['warnings' ], ["Unable to make chosen address type, please ensure no uncompressed public keys are present." ])
91
103
92
104
self .log .info ('Testing sortedmulti descriptors with BIP 67 test vectors' )
93
105
with open (os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'data/rpc_bip67.json' ), encoding = 'utf-8' ) as f :
@@ -126,26 +138,29 @@ def checkbalances(self):
126
138
bal0 = node0 .getbalance ()
127
139
bal1 = node1 .getbalance ()
128
140
bal2 = node2 .getbalance ()
141
+ balw = self .wallet .get_balance ()
129
142
130
143
height = node0 .getblockchaininfo ()["blocks" ]
131
144
assert 150 < height < 350
132
145
total = 149 * 50 + (height - 149 - 100 ) * 25
133
146
assert bal1 == 0
134
147
assert bal2 == self .moved
135
- assert bal0 + bal1 + bal2 == total
148
+ assert_equal ( bal0 + bal1 + bal2 + balw , total )
136
149
137
150
def do_multisig (self ):
138
151
node0 , node1 , node2 = self .nodes
139
- if 'wmulti' not in node1 .listwallets ():
140
- try :
141
- node1 .loadwallet ('wmulti' )
142
- except JSONRPCException as e :
143
- path = os .path .join (self .options .tmpdir , "node1" , "regtest" , "wallets" , "wmulti" )
144
- if e .error ['code' ] == - 18 and "Wallet file verification failed. Failed to load database path '{}'. Path does not exist." .format (path ) in e .error ['message' ]:
145
- node1 .createwallet (wallet_name = 'wmulti' , disable_private_keys = True )
146
- else :
147
- raise
148
- wmulti = node1 .get_wallet_rpc ('wmulti' )
152
+
153
+ if self .is_bdb_compiled ():
154
+ if 'wmulti' not in node1 .listwallets ():
155
+ try :
156
+ node1 .loadwallet ('wmulti' )
157
+ except JSONRPCException as e :
158
+ path = os .path .join (self .options .tmpdir , "node1" , "regtest" , "wallets" , "wmulti" )
159
+ if e .error ['code' ] == - 18 and "Wallet file verification failed. Failed to load database path '{}'. Path does not exist." .format (path ) in e .error ['message' ]:
160
+ node1 .createwallet (wallet_name = 'wmulti' , disable_private_keys = True )
161
+ else :
162
+ raise
163
+ wmulti = node1 .get_wallet_rpc ('wmulti' )
149
164
150
165
# Construct the expected descriptor
151
166
desc = 'multi({},{})' .format (self .nsigs , ',' .join (self .pub ))
@@ -164,17 +179,19 @@ def do_multisig(self):
164
179
if self .output_type == 'bech32' :
165
180
assert madd [0 :4 ] == "bcrt" # actually a bech32 address
166
181
167
- # compare against addmultisigaddress
168
- msigw = wmulti .addmultisigaddress (self .nsigs , self .pub , None , self .output_type )
169
- maddw = msigw ["address" ]
170
- mredeemw = msigw ["redeemScript" ]
171
- assert_equal (desc , drop_origins (msigw ['descriptor' ]))
172
- # addmultisigiaddress and createmultisig work the same
173
- assert maddw == madd
174
- assert mredeemw == mredeem
175
-
176
- txid = node0 .sendtoaddress (madd , 40 )
177
-
182
+ if self .is_bdb_compiled ():
183
+ # compare against addmultisigaddress
184
+ msigw = wmulti .addmultisigaddress (self .nsigs , self .pub , None , self .output_type )
185
+ maddw = msigw ["address" ]
186
+ mredeemw = msigw ["redeemScript" ]
187
+ assert_equal (desc , drop_origins (msigw ['descriptor' ]))
188
+ # addmultisigiaddress and createmultisig work the same
189
+ assert maddw == madd
190
+ assert mredeemw == mredeem
191
+ wmulti .unloadwallet ()
192
+
193
+ spk = bytes .fromhex (node0 .validateaddress (madd )["scriptPubKey" ])
194
+ txid , _ = self .wallet .send_to (from_node = self .nodes [0 ], scriptPubKey = spk , amount = 1300 )
178
195
tx = node0 .getrawtransaction (txid , True )
179
196
vout = [v ["n" ] for v in tx ["vout" ] if madd == v ["scriptPubKey" ]["address" ]]
180
197
assert len (vout ) == 1
@@ -225,8 +242,6 @@ def do_multisig(self):
225
242
txinfo = node0 .getrawtransaction (tx , True , blk )
226
243
self .log .info ("n/m=%d/%d %s size=%d vsize=%d weight=%d" % (self .nsigs , self .nkeys , self .output_type , txinfo ["size" ], txinfo ["vsize" ], txinfo ["weight" ]))
227
244
228
- wmulti .unloadwallet ()
229
-
230
245
231
246
if __name__ == '__main__' :
232
247
RpcCreateMultiSigTest ().main ()
0 commit comments