2323 assert_equal ,
2424 assert_raises_rpc_error ,
2525)
26+ from test_framework .wallet import (
27+ MiniWallet ,
28+ )
2629from test_framework .netutil import test_ipv6_local
2730from io import BytesIO
2831from time import sleep
@@ -111,6 +114,7 @@ def skip_test_if_missing_module(self):
111114 self .skip_if_no_bitcoind_zmq ()
112115
113116 def run_test (self ):
117+ self .wallet = MiniWallet (self .nodes [0 ])
114118 self .ctx = zmq .Context ()
115119 try :
116120 self .test_basic ()
@@ -212,17 +216,18 @@ def test_basic(self):
212216
213217
214218 if self .is_wallet_compiled ():
219+ self .wallet .rescan_utxos ()
215220 self .log .info ("Wait for tx from second node" )
216- payment_txid = self .nodes [1 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 1.0 )
221+ payment_tx = self .wallet .send_self_transfer (from_node = self .nodes [1 ])
222+ payment_txid = payment_tx ['txid' ]
217223 self .sync_all ()
218-
219224 # Should receive the broadcasted txid.
220225 txid = hashtx .receive ()
221226 assert_equal (payment_txid , txid .hex ())
222227
223228 # Should receive the broadcasted raw transaction.
224229 hex = rawtx .receive ()
225- assert_equal (payment_txid , hash256_reversed (hex ).hex ())
230+ assert_equal (payment_tx [ 'wtxid' ] , hash256_reversed (hex ).hex ())
226231
227232 # Mining the block with this tx should result in second notification
228233 # after coinbase tx notification
@@ -256,7 +261,7 @@ def test_reorg(self):
256261 self .disconnect_nodes (0 , 1 )
257262
258263 # Generate 1 block in nodes[0] with 1 mempool tx and receive all notifications
259- payment_txid = self .nodes [ 0 ]. sendtoaddress ( self .nodes [0 ]. getnewaddress (), 1.0 )
264+ payment_txid = self .wallet . send_self_transfer ( from_node = self .nodes [0 ])[ 'txid' ]
260265 disconnect_block = self .generatetoaddress (self .nodes [0 ], 1 , ADDRESS_BCRT1_UNSPENDABLE , sync_fun = self .no_op )[0 ]
261266 disconnect_cb = self .nodes [0 ].getblock (disconnect_block )["tx" ][0 ]
262267 assert_equal (self .nodes [0 ].getbestblockhash (), hashblock .receive ().hex ())
@@ -328,7 +333,8 @@ def test_sequence(self):
328333 # Rest of test requires wallet functionality
329334 if self .is_wallet_compiled ():
330335 self .log .info ("Wait for tx from second node" )
331- payment_txid = self .nodes [1 ].sendtoaddress (address = self .nodes [0 ].getnewaddress (), amount = 5.0 , replaceable = True )
336+ payment_tx = self .wallet .send_self_transfer (from_node = self .nodes [1 ])
337+ payment_txid = payment_tx ['txid' ]
332338 self .sync_all ()
333339 self .log .info ("Testing sequence notifications with mempool sequence values" )
334340
@@ -338,11 +344,12 @@ def test_sequence(self):
338344
339345 self .log .info ("Testing RBF notification" )
340346 # Replace it to test eviction/addition notification
341- rbf_info = self .nodes [1 ].bumpfee (payment_txid )
347+ payment_tx ['tx' ].vout [0 ].nValue -= 1000
348+ rbf_txid = self .nodes [1 ].sendrawtransaction (payment_tx ['tx' ].serialize ().hex ())
342349 self .sync_all ()
343350 assert_equal ((payment_txid , "R" , seq_num ), seq .receive_sequence ())
344351 seq_num += 1
345- assert_equal ((rbf_info [ "txid" ] , "A" , seq_num ), seq .receive_sequence ())
352+ assert_equal ((rbf_txid , "A" , seq_num ), seq .receive_sequence ())
346353 seq_num += 1
347354
348355 # Doesn't get published when mined, make a block and tx to "flush" the possibility
@@ -354,7 +361,7 @@ def test_sequence(self):
354361 mempool_size_delta = mempool_size - len (self .nodes [0 ].getrawmempool ())
355362 assert_equal (len (self .nodes [0 ].getblock (c_block )["tx" ])- 1 , mempool_size_delta )
356363 seq_num += mempool_size_delta
357- payment_txid_2 = self .nodes [ 1 ]. sendtoaddress ( self .nodes [0 ]. getnewaddress (), 1.0 )
364+ payment_txid_2 = self .wallet . send_self_transfer ( from_node = self .nodes [1 ])[ 'txid' ]
358365 self .sync_all ()
359366 assert_equal ((c_block , "C" , None ), seq .receive_sequence ())
360367 assert_equal ((payment_txid_2 , "A" , seq_num ), seq .receive_sequence ())
@@ -383,32 +390,33 @@ def test_sequence(self):
383390 assert self .nodes [0 ].getrawmempool (mempool_sequence = True )["mempool_sequence" ] > seq_num
384391
385392 assert_equal ((best_hash , "D" , None ), seq .receive_sequence ())
386- assert_equal ((rbf_info [ "txid" ] , "A" , seq_num ), seq .receive_sequence ())
393+ assert_equal ((rbf_txid , "A" , seq_num ), seq .receive_sequence ())
387394 seq_num += 1
388395
389396 # Other things may happen but aren't wallet-deterministic so we don't test for them currently
390397 self .nodes [0 ].reconsiderblock (best_hash )
391398 self .generatetoaddress (self .nodes [1 ], 1 , ADDRESS_BCRT1_UNSPENDABLE )
392399
393400 self .log .info ("Evict mempool transaction by block conflict" )
394- orig_txid = self .nodes [0 ].sendtoaddress (address = self .nodes [0 ].getnewaddress (), amount = 1.0 , replaceable = True )
401+ orig_tx = self .wallet .send_self_transfer (from_node = self .nodes [0 ])
402+ orig_txid = orig_tx ['txid' ]
395403
396404 # More to be simply mined
397405 more_tx = []
398406 for _ in range (5 ):
399- more_tx .append (self .nodes [ 0 ]. sendtoaddress ( self .nodes [0 ]. getnewaddress (), 0.1 ))
407+ more_tx .append (self .wallet . send_self_transfer ( from_node = self .nodes [0 ]))
400408
401- raw_tx = self . nodes [0 ].getrawtransaction ( orig_txid )
402- bump_info = self .nodes [0 ].bumpfee ( orig_txid )
409+ orig_tx [ 'tx' ]. vout [0 ].nValue -= 1000
410+ bump_txid = self .nodes [0 ].sendrawtransaction ( orig_tx [ 'tx' ]. serialize (). hex () )
403411 # Mine the pre-bump tx
404- txs_to_add = [raw_tx ] + [self . nodes [ 0 ]. getrawtransaction ( txid ) for txid in more_tx ]
412+ txs_to_add = [orig_tx [ 'hex' ]] + [tx [ 'hex' ] for tx in more_tx ]
405413 block = create_block (int (self .nodes [0 ].getbestblockhash (), 16 ), create_coinbase (self .nodes [0 ].getblockcount ()+ 1 ), txlist = txs_to_add )
406414 add_witness_commitment (block )
407415 block .solve ()
408416 assert_equal (self .nodes [0 ].submitblock (block .serialize ().hex ()), None )
409417 tip = self .nodes [0 ].getbestblockhash ()
410418 assert_equal (int (tip , 16 ), block .sha256 )
411- orig_txid_2 = self .nodes [ 0 ]. sendtoaddress ( address = self .nodes [0 ]. getnewaddress (), amount = 1.0 , replaceable = True )
419+ orig_txid_2 = self .wallet . send_self_transfer ( from_node = self .nodes [0 ])[ 'txid' ]
412420
413421 # Flush old notifications until evicted tx original entry
414422 (hash_str , label , mempool_seq ) = seq .receive_sequence ()
@@ -420,15 +428,15 @@ def test_sequence(self):
420428 assert_equal (label , "A" )
421429 # More transactions to be simply mined
422430 for i in range (len (more_tx )):
423- assert_equal ((more_tx [i ], "A" , mempool_seq ), seq .receive_sequence ())
431+ assert_equal ((more_tx [i ][ 'txid' ] , "A" , mempool_seq ), seq .receive_sequence ())
424432 mempool_seq += 1
425433 # Bumped by rbf
426434 assert_equal ((orig_txid , "R" , mempool_seq ), seq .receive_sequence ())
427435 mempool_seq += 1
428- assert_equal ((bump_info [ "txid" ] , "A" , mempool_seq ), seq .receive_sequence ())
436+ assert_equal ((bump_txid , "A" , mempool_seq ), seq .receive_sequence ())
429437 mempool_seq += 1
430438 # Conflict announced first, then block
431- assert_equal ((bump_info [ "txid" ] , "R" , mempool_seq ), seq .receive_sequence ())
439+ assert_equal ((bump_txid , "R" , mempool_seq ), seq .receive_sequence ())
432440 mempool_seq += 1
433441 assert_equal ((tip , "C" , None ), seq .receive_sequence ())
434442 mempool_seq += len (more_tx )
@@ -455,10 +463,10 @@ def test_mempool_sync(self):
455463
456464 # Some transactions have been happening but we aren't consuming zmq notifications yet
457465 # or we lost a ZMQ message somehow and want to start over
458- txids = []
466+ txs = []
459467 num_txs = 5
460468 for _ in range (num_txs ):
461- txids .append (self .nodes [ 1 ]. sendtoaddress ( address = self .nodes [0 ]. getnewaddress (), amount = 1.0 , replaceable = True ))
469+ txs .append (self .wallet . send_self_transfer ( from_node = self .nodes [1 ] ))
462470 self .sync_all ()
463471
464472 # 1) Consume backlog until we get a mempool sequence number
@@ -484,11 +492,12 @@ def test_mempool_sync(self):
484492 # Things continue to happen in the "interim" while waiting for snapshot results
485493 # We have node 0 do all these to avoid p2p races with RBF announcements
486494 for _ in range (num_txs ):
487- txids .append (self .nodes [0 ].sendtoaddress (address = self .nodes [0 ].getnewaddress (), amount = 0.1 , replaceable = True ))
488- self .nodes [0 ].bumpfee (txids [- 1 ])
495+ txs .append (self .wallet .send_self_transfer (from_node = self .nodes [0 ]))
496+ txs [- 1 ]['tx' ].vout [0 ].nValue -= 1000
497+ self .nodes [0 ].sendrawtransaction (txs [- 1 ]['tx' ].serialize ().hex ())
489498 self .sync_all ()
490499 self .generatetoaddress (self .nodes [0 ], 1 , ADDRESS_BCRT1_UNSPENDABLE )
491- final_txid = self .nodes [ 0 ]. sendtoaddress ( address = self .nodes [0 ]. getnewaddress (), amount = 0.1 , replaceable = True )
500+ final_txid = self .wallet . send_self_transfer ( from_node = self .nodes [0 ])[ 'txid' ]
492501
493502 # 3) Consume ZMQ backlog until we get to "now" for the mempool snapshot
494503 while True :
0 commit comments