Skip to content

Commit 27d4fc6

Browse files
committed
add mine_tx helper method
1 parent 067a96a commit 27d4fc6

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
@@ -579,6 +579,17 @@ impl TestWallet {
579579
}
580580
}
581581

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

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

0 commit comments

Comments
 (0)