23
23
assert_equal ,
24
24
assert_raises_rpc_error ,
25
25
)
26
+ from test_framework .wallet import (
27
+ MiniWallet ,
28
+ )
26
29
from test_framework .netutil import test_ipv6_local
27
30
from io import BytesIO
28
31
from time import sleep
@@ -111,6 +114,7 @@ def skip_test_if_missing_module(self):
111
114
self .skip_if_no_bitcoind_zmq ()
112
115
113
116
def run_test (self ):
117
+ self .wallet = MiniWallet (self .nodes [0 ])
114
118
self .ctx = zmq .Context ()
115
119
try :
116
120
self .test_basic ()
@@ -212,17 +216,18 @@ def test_basic(self):
212
216
213
217
214
218
if self .is_wallet_compiled ():
219
+ self .wallet .rescan_utxos ()
215
220
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' ]
217
223
self .sync_all ()
218
-
219
224
# Should receive the broadcasted txid.
220
225
txid = hashtx .receive ()
221
226
assert_equal (payment_txid , txid .hex ())
222
227
223
228
# Should receive the broadcasted raw transaction.
224
229
hex = rawtx .receive ()
225
- assert_equal (payment_txid , hash256_reversed (hex ).hex ())
230
+ assert_equal (payment_tx [ 'wtxid' ] , hash256_reversed (hex ).hex ())
226
231
227
232
# Mining the block with this tx should result in second notification
228
233
# after coinbase tx notification
@@ -256,7 +261,7 @@ def test_reorg(self):
256
261
self .disconnect_nodes (0 , 1 )
257
262
258
263
# 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' ]
260
265
disconnect_block = self .generatetoaddress (self .nodes [0 ], 1 , ADDRESS_BCRT1_UNSPENDABLE , sync_fun = self .no_op )[0 ]
261
266
disconnect_cb = self .nodes [0 ].getblock (disconnect_block )["tx" ][0 ]
262
267
assert_equal (self .nodes [0 ].getbestblockhash (), hashblock .receive ().hex ())
@@ -328,7 +333,8 @@ def test_sequence(self):
328
333
# Rest of test requires wallet functionality
329
334
if self .is_wallet_compiled ():
330
335
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' ]
332
338
self .sync_all ()
333
339
self .log .info ("Testing sequence notifications with mempool sequence values" )
334
340
@@ -338,11 +344,12 @@ def test_sequence(self):
338
344
339
345
self .log .info ("Testing RBF notification" )
340
346
# 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 ())
342
349
self .sync_all ()
343
350
assert_equal ((payment_txid , "R" , seq_num ), seq .receive_sequence ())
344
351
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 ())
346
353
seq_num += 1
347
354
348
355
# Doesn't get published when mined, make a block and tx to "flush" the possibility
@@ -354,7 +361,7 @@ def test_sequence(self):
354
361
mempool_size_delta = mempool_size - len (self .nodes [0 ].getrawmempool ())
355
362
assert_equal (len (self .nodes [0 ].getblock (c_block )["tx" ])- 1 , mempool_size_delta )
356
363
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' ]
358
365
self .sync_all ()
359
366
assert_equal ((c_block , "C" , None ), seq .receive_sequence ())
360
367
assert_equal ((payment_txid_2 , "A" , seq_num ), seq .receive_sequence ())
@@ -383,32 +390,33 @@ def test_sequence(self):
383
390
assert self .nodes [0 ].getrawmempool (mempool_sequence = True )["mempool_sequence" ] > seq_num
384
391
385
392
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 ())
387
394
seq_num += 1
388
395
389
396
# Other things may happen but aren't wallet-deterministic so we don't test for them currently
390
397
self .nodes [0 ].reconsiderblock (best_hash )
391
398
self .generatetoaddress (self .nodes [1 ], 1 , ADDRESS_BCRT1_UNSPENDABLE )
392
399
393
400
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' ]
395
403
396
404
# More to be simply mined
397
405
more_tx = []
398
406
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 ]))
400
408
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 () )
403
411
# 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 ]
405
413
block = create_block (int (self .nodes [0 ].getbestblockhash (), 16 ), create_coinbase (self .nodes [0 ].getblockcount ()+ 1 ), txlist = txs_to_add )
406
414
add_witness_commitment (block )
407
415
block .solve ()
408
416
assert_equal (self .nodes [0 ].submitblock (block .serialize ().hex ()), None )
409
417
tip = self .nodes [0 ].getbestblockhash ()
410
418
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' ]
412
420
413
421
# Flush old notifications until evicted tx original entry
414
422
(hash_str , label , mempool_seq ) = seq .receive_sequence ()
@@ -420,15 +428,15 @@ def test_sequence(self):
420
428
assert_equal (label , "A" )
421
429
# More transactions to be simply mined
422
430
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 ())
424
432
mempool_seq += 1
425
433
# Bumped by rbf
426
434
assert_equal ((orig_txid , "R" , mempool_seq ), seq .receive_sequence ())
427
435
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 ())
429
437
mempool_seq += 1
430
438
# 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 ())
432
440
mempool_seq += 1
433
441
assert_equal ((tip , "C" , None ), seq .receive_sequence ())
434
442
mempool_seq += len (more_tx )
@@ -455,10 +463,10 @@ def test_mempool_sync(self):
455
463
456
464
# Some transactions have been happening but we aren't consuming zmq notifications yet
457
465
# or we lost a ZMQ message somehow and want to start over
458
- txids = []
466
+ txs = []
459
467
num_txs = 5
460
468
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 ] ))
462
470
self .sync_all ()
463
471
464
472
# 1) Consume backlog until we get a mempool sequence number
@@ -484,11 +492,12 @@ def test_mempool_sync(self):
484
492
# Things continue to happen in the "interim" while waiting for snapshot results
485
493
# We have node 0 do all these to avoid p2p races with RBF announcements
486
494
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 ())
489
498
self .sync_all ()
490
499
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' ]
492
501
493
502
# 3) Consume ZMQ backlog until we get to "now" for the mempool snapshot
494
503
while True :
0 commit comments