9
9
import os
10
10
11
11
from test_framework .address import address_to_scriptpubkey
12
- from test_framework .blocktools import COINBASE_MATURITY
13
12
from test_framework .descriptors import descsum_create , drop_origins
14
13
from test_framework .key import ECPubKey
15
14
from test_framework .messages import COIN
@@ -41,10 +40,6 @@ def create_keys(self, num_keys):
41
40
privkey , pubkey = generate_keypair (wif = True )
42
41
self .pub .append (pubkey .hex ())
43
42
self .priv .append (privkey )
44
- if self .is_bdb_compiled ():
45
- self .final = self .nodes [2 ].getnewaddress ()
46
- else :
47
- self .final = getnewdestination ('bech32' )[2 ]
48
43
49
44
def create_wallet (self , node , wallet_name ):
50
45
node .createwallet (wallet_name = wallet_name , disable_private_keys = True )
@@ -54,23 +49,20 @@ def run_test(self):
54
49
node0 , node1 , node2 = self .nodes
55
50
self .wallet = MiniWallet (test_node = node0 )
56
51
57
- if self .is_bdb_compiled ():
52
+ if self .is_wallet_compiled ():
58
53
self .check_addmultisigaddress_errors ()
59
54
60
55
self .log .info ('Generating blocks ...' )
61
56
self .generate (self .wallet , 149 )
62
57
63
58
wallet_multi = self .create_wallet (node1 , 'wmulti' ) if self ._requires_wallet else None
64
- self .moved = 0
65
59
self .create_keys (5 )
66
60
for nkeys in [3 , 5 ]:
67
61
for nsigs in [2 , 3 ]:
68
62
for output_type in ["bech32" , "p2sh-segwit" , "legacy" ]:
69
63
self .do_multisig (nkeys , nsigs , output_type , wallet_multi )
70
64
if wallet_multi is not None :
71
65
wallet_multi .unloadwallet ()
72
- if self .is_bdb_compiled ():
73
- self .checkbalances ()
74
66
75
67
# Test mixed compressed and uncompressed pubkeys
76
68
self .log .info ('Mixed compressed and uncompressed multisigs are not allowed' )
@@ -139,22 +131,6 @@ def check_addmultisigaddress_errors(self):
139
131
pubs = [self .nodes [1 ].getaddressinfo (addr )["pubkey" ] for addr in addresses ]
140
132
assert_raises_rpc_error (- 5 , "Bech32m multisig addresses cannot be created with legacy wallets" , self .nodes [0 ].addmultisigaddress , 2 , pubs , "" , "bech32m" )
141
133
142
- def checkbalances (self ):
143
- node0 , node1 , node2 = self .nodes
144
- self .generate (node0 , COINBASE_MATURITY )
145
-
146
- bal0 = node0 .getbalance ()
147
- bal1 = node1 .getbalance ()
148
- bal2 = node2 .getbalance ()
149
- balw = self .wallet .get_balance ()
150
-
151
- height = node0 .getblockchaininfo ()["blocks" ]
152
- assert 150 < height < 350
153
- total = 149 * 50 + (height - 149 - 100 ) * 25
154
- assert bal1 == 0
155
- assert bal2 == self .moved
156
- assert_equal (bal0 + bal1 + bal2 + balw , total )
157
-
158
134
def do_multisig (self , nkeys , nsigs , output_type , wallet_multi ):
159
135
node0 , node1 , node2 = self .nodes
160
136
pub_keys = self .pub [0 : nkeys ]
@@ -196,7 +172,10 @@ def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
196
172
self .generate (node0 , 1 )
197
173
198
174
outval = value - decimal .Decimal ("0.00001000" )
199
- rawtx = node2 .createrawtransaction ([{"txid" : tx ["txid" ], "vout" : tx ["sent_vout" ]}], [{self .final : outval }])
175
+ # send coins to node2 when wallet is enabled
176
+ node2_balance = node2 .getbalances ()['mine' ]['trusted' ] if self .is_wallet_compiled () else 0
177
+ out_addr = node2 .getnewaddress () if self .is_wallet_compiled () else getnewdestination ('bech32' )[2 ]
178
+ rawtx = node2 .createrawtransaction ([{"txid" : tx ["txid" ], "vout" : tx ["sent_vout" ]}], [{out_addr : outval }])
200
179
201
180
prevtx_err = dict (prevtxs [0 ])
202
181
del prevtx_err ["redeemScript" ]
@@ -227,11 +206,14 @@ def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
227
206
rawtx2 = node2 .signrawtransactionwithkey (rawtx , priv_keys [0 :nsigs - 1 ], prevtxs )
228
207
rawtx3 = node2 .signrawtransactionwithkey (rawtx2 ["hex" ], [priv_keys [- 1 ]], prevtxs )
229
208
230
- self .moved += outval
231
209
tx = node0 .sendrawtransaction (rawtx3 ["hex" ], 0 )
232
210
blk = self .generate (node0 , 1 )[0 ]
233
211
assert tx in node0 .getblock (blk )["tx" ]
234
212
213
+ # When the wallet is enabled, assert node2 sees the incoming amount
214
+ if self .is_wallet_compiled ():
215
+ assert_equal (node2 .getbalances ()['mine' ]['trusted' ], node2_balance + outval )
216
+
235
217
txinfo = node0 .getrawtransaction (tx , True , blk )
236
218
self .log .info ("n/m=%d/%d %s size=%d vsize=%d weight=%d" % (nsigs , nkeys , output_type , txinfo ["size" ], txinfo ["vsize" ], txinfo ["weight" ]))
237
219
0 commit comments