30
30
import random
31
31
import time
32
32
33
+ from test_framework .blocktools import COINBASE_MATURITY
33
34
from test_framework .messages import (
34
35
COIN ,
35
- COutPoint ,
36
- CTransaction ,
37
- CTxIn ,
38
- CTxOut ,
39
36
)
40
37
from test_framework .test_framework import BitcoinTestFramework
41
38
from test_framework .util import (
42
39
assert_equal ,
43
- create_confirmed_utxos ,
40
+ )
41
+ from test_framework .wallet import (
42
+ MiniWallet ,
43
+ getnewdestination ,
44
44
)
45
45
46
46
@@ -66,13 +66,9 @@ def set_test_params(self):
66
66
self .node3_args = ["-blockmaxweight=4000000" , "-acceptnonstdtxn" ]
67
67
self .extra_args = [self .node0_args , self .node1_args , self .node2_args , self .node3_args ]
68
68
69
- def skip_test_if_missing_module (self ):
70
- self .skip_if_no_wallet ()
71
-
72
69
def setup_network (self ):
73
70
self .add_nodes (self .num_nodes , extra_args = self .extra_args )
74
71
self .start_nodes ()
75
- self .import_deterministic_coinbase_privkeys ()
76
72
# Leave them unconnected, we'll use submitblock directly in this test
77
73
78
74
def restart_node (self , node_index , expected_tip ):
@@ -190,34 +186,36 @@ def generate_small_transactions(self, node, count, utxo_list):
190
186
num_transactions = 0
191
187
random .shuffle (utxo_list )
192
188
while len (utxo_list ) >= 2 and num_transactions < count :
193
- tx = CTransaction ()
194
- input_amount = 0
195
- for _ in range (2 ):
196
- utxo = utxo_list .pop ()
197
- tx .vin .append (CTxIn (COutPoint (int (utxo ['txid' ], 16 ), utxo ['vout' ])))
198
- input_amount += int (utxo ['amount' ] * COIN )
199
- output_amount = (input_amount - FEE ) // 3
200
-
201
- if output_amount <= 0 :
189
+ utxos_to_spend = [utxo_list .pop () for _ in range (2 )]
190
+ input_amount = int (sum ([utxo ['value' ] for utxo in utxos_to_spend ]) * COIN )
191
+ if input_amount < FEE :
202
192
# Sanity check -- if we chose inputs that are too small, skip
203
193
continue
204
194
205
- for _ in range (3 ):
206
- tx .vout .append (CTxOut (output_amount , bytes .fromhex (utxo ['scriptPubKey' ])))
195
+ tx = self .wallet .create_self_transfer_multi (
196
+ from_node = node ,
197
+ utxos_to_spend = utxos_to_spend ,
198
+ num_outputs = 3 ,
199
+ fee_per_output = FEE // 3 )
207
200
208
- # Sign and send the transaction to get into the mempool
209
- tx_signed_hex = node .signrawtransactionwithwallet (tx .serialize ().hex ())['hex' ]
210
- node .sendrawtransaction (tx_signed_hex )
201
+ # Send the transaction to get into the mempool (skip fee-checks to run faster)
202
+ node .sendrawtransaction (hexstring = tx .serialize ().hex (), maxfeerate = 0 )
211
203
num_transactions += 1
212
204
213
205
def run_test (self ):
206
+ self .wallet = MiniWallet (self .nodes [3 ])
207
+ self .wallet .rescan_utxos ()
208
+ initial_height = self .nodes [3 ].getblockcount ()
209
+ self .generate (self .nodes [3 ], COINBASE_MATURITY , sync_fun = self .no_op )
210
+
214
211
# Track test coverage statistics
215
212
self .restart_counts = [0 , 0 , 0 ] # Track the restarts for nodes 0-2
216
213
self .crashed_on_restart = 0 # Track count of crashes during recovery
217
214
218
215
# Start by creating a lot of utxos on node3
219
- initial_height = self .nodes [3 ].getblockcount ()
220
- utxo_list = create_confirmed_utxos (self , self .nodes [3 ].getnetworkinfo ()['relayfee' ], self .nodes [3 ], 5000 , sync_fun = self .no_op )
216
+ utxo_list = self .wallet .send_self_transfer_multi (from_node = self .nodes [3 ], num_outputs = 5000 )['new_utxos' ]
217
+ self .generate (self .nodes [3 ], 1 , sync_fun = self .no_op )
218
+ assert_equal (len (self .nodes [3 ].getrawmempool ()), 0 )
221
219
self .log .info (f"Prepped { len (utxo_list )} utxo entries" )
222
220
223
221
# Sync these blocks with the other nodes
@@ -257,13 +255,14 @@ def run_test(self):
257
255
self .nodes [3 ],
258
256
nblocks = min (10 , current_height + 1 - self .nodes [3 ].getblockcount ()),
259
257
# new address to avoid mining a block that has just been invalidated
260
- address = self . nodes [ 3 ]. getnewaddress () ,
258
+ address = getnewdestination ()[ 2 ] ,
261
259
sync_fun = self .no_op ,
262
260
))
263
261
self .log .debug (f"Syncing { len (block_hashes )} new blocks..." )
264
262
self .sync_node3blocks (block_hashes )
265
- utxo_list = self .nodes [3 ].listunspent ()
266
- self .log .debug (f"Node3 utxo count: { len (utxo_list )} " )
263
+ self .wallet .rescan_utxos ()
264
+ utxo_list = self .wallet .get_utxos ()
265
+ self .log .debug (f"MiniWallet utxo count: { len (utxo_list )} " )
267
266
268
267
# Check that the utxo hashes agree with node3
269
268
# Useful side effect: each utxo cache gets flushed here, so that we
0 commit comments