Skip to content

Commit 858ef03

Browse files
committed
add mine_tx helper method
1 parent 4fe648d commit 858ef03

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

tests/transfers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ fn ln_transfers() {
681681
println!("\n7. broadcast old PSBT");
682682
let tx = wlt_1.sign_finalize(&mut old_psbt);
683683
wlt_1.broadcast_tx(&tx);
684-
mine(false);
684+
wlt_1.mine_tx(&tx.txid(), false);
685685
wlt_1.sync();
686686
wlt_1.update_witnesses(pre_funding_height);
687687
let mut wlt_3 = get_wallet(&DescriptorType::Wpkh);
@@ -714,8 +714,8 @@ fn mainnet_wlt_receiving_test_asset() {
714714
wlt_2.close_method(),
715715
InvoiceType::Blinded(Some(utxo)),
716716
);
717-
let (consignment, _) = wlt_1.transfer(invoice.clone(), None, Some(500));
718-
mine(false);
717+
let (consignment, tx) = wlt_1.transfer(invoice.clone(), None, Some(500));
718+
wlt_1.mine_tx(&tx.txid(), false);
719719
match consignment.validate(&wlt_2.get_resolver(), wlt_2.testnet()) {
720720
Err((status, _invalid_consignment)) => {
721721
assert_eq!(

tests/utils/helpers.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ impl TestWallet {
578578
}
579579
}
580580

581+
pub fn get_tx_height(&self, txid: &Txid) -> Option<u32> {
582+
match self
583+
.get_resolver()
584+
.resolve_pub_witness_ord(XWitnessId::Bitcoin(*txid))
585+
.unwrap()
586+
{
587+
WitnessOrd::Mined(witness_pos) => Some(witness_pos.height().get()),
588+
_ => None,
589+
}
590+
}
591+
581592
pub fn sync(&mut self) {
582593
let indexer = self.get_indexer();
583594
self.wallet
@@ -591,6 +602,20 @@ impl TestWallet {
591602
self.wallet.wallet().seal_close_method()
592603
}
593604

605+
pub fn mine_tx(&self, txid: &Txid, resume: bool) {
606+
let mut attempts = 10;
607+
loop {
608+
mine(resume);
609+
if self.get_tx_height(txid).is_some() {
610+
break;
611+
}
612+
attempts -= 1;
613+
if attempts == 0 {
614+
panic!("TX is not getting mined");
615+
}
616+
}
617+
}
618+
594619
pub fn issue_with_info(
595620
&mut self,
596621
asset_info: AssetInfo,
@@ -926,7 +951,7 @@ impl TestWallet {
926951
fee: Option<u64>,
927952
) -> (Transfer, Tx) {
928953
let (consignment, tx) = self.transfer(invoice, sats, fee);
929-
mine(false);
954+
self.mine_tx(&tx.txid(), false);
930955
recv_wlt.accept_transfer(consignment.clone());
931956
self.sync();
932957
(consignment, tx)

0 commit comments

Comments
 (0)