3
3
from fixtures import *
4
4
from test_framework .utils import (
5
5
wait_for ,
6
+ wait_for_while_condition_holds ,
6
7
get_txid ,
7
8
spend_coins ,
8
9
RpcError ,
@@ -407,7 +408,13 @@ def is_spent_by(lianad, outpoint, txid):
407
408
return False
408
409
return coin ["spend_info" ]["txid" ] == txid .hex ()
409
410
410
- wait_for (lambda : is_spent_by (lianad , spent_coin ["outpoint" ], txid_b ))
411
+ wait_for_while_condition_holds (
412
+ lambda : is_spent_by (lianad , spent_coin ["outpoint" ], txid_b ),
413
+ lambda : lianad .rpc .listcoins ([], [spent_coin ["outpoint" ]])["coins" ][0 ][
414
+ "spend_info"
415
+ ]
416
+ is not None , # The spend txid changes directly from txid_a to txid_b
417
+ )
411
418
412
419
413
420
def test_spend_replacement (lianad , bitcoind ):
@@ -454,11 +461,15 @@ def test_spend_replacement(lianad, bitcoind):
454
461
# newly marked as spending, the second one's spend_txid should be updated and
455
462
# the first one's spend txid should be dropped.
456
463
second_txid = sign_and_broadcast_psbt (lianad , second_psbt )
457
- wait_for (
464
+ wait_for_while_condition_holds (
458
465
lambda : all (
459
466
c ["spend_info" ] is not None and c ["spend_info" ]["txid" ] == second_txid
460
467
for c in lianad .rpc .listcoins ([], second_outpoints )["coins" ]
461
- )
468
+ ),
469
+ lambda : lianad .rpc .listcoins ([], [coins [1 ]["outpoint" ]])["coins" ][0 ][
470
+ "spend_info"
471
+ ]
472
+ is not None , # The spend txid of coin from first spend is updated directly
462
473
)
463
474
wait_for (
464
475
lambda : lianad .rpc .listcoins ([], [first_outpoints [0 ]])["coins" ][0 ]["spend_info" ]
@@ -467,11 +478,15 @@ def test_spend_replacement(lianad, bitcoind):
467
478
468
479
# Now RBF the second transaction with a send-to-self, just because.
469
480
third_txid = sign_and_broadcast_psbt (lianad , third_psbt )
470
- wait_for (
481
+ wait_for_while_condition_holds (
471
482
lambda : all (
472
483
c ["spend_info" ] is not None and c ["spend_info" ]["txid" ] == third_txid
473
484
for c in lianad .rpc .listcoins ([], second_outpoints )["coins" ]
474
- )
485
+ ),
486
+ lambda : all (
487
+ c ["spend_info" ] is not None
488
+ for c in lianad .rpc .listcoins ([], second_outpoints )["coins" ]
489
+ ), # The spend txid of all coins are updated directly
475
490
)
476
491
assert (
477
492
lianad .rpc .listcoins ([], [first_outpoints [0 ]])["coins" ][0 ]["spend_info" ] is None
0 commit comments