Skip to content

Commit

Permalink
add mine_tx helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Sep 18, 2024
1 parent 4fe648d commit 858ef03
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ fn ln_transfers() {
println!("\n7. broadcast old PSBT");
let tx = wlt_1.sign_finalize(&mut old_psbt);
wlt_1.broadcast_tx(&tx);
mine(false);
wlt_1.mine_tx(&tx.txid(), false);
wlt_1.sync();
wlt_1.update_witnesses(pre_funding_height);
let mut wlt_3 = get_wallet(&DescriptorType::Wpkh);
Expand Down Expand Up @@ -714,8 +714,8 @@ fn mainnet_wlt_receiving_test_asset() {
wlt_2.close_method(),
InvoiceType::Blinded(Some(utxo)),
);
let (consignment, _) = wlt_1.transfer(invoice.clone(), None, Some(500));
mine(false);
let (consignment, tx) = wlt_1.transfer(invoice.clone(), None, Some(500));
wlt_1.mine_tx(&tx.txid(), false);
match consignment.validate(&wlt_2.get_resolver(), wlt_2.testnet()) {
Err((status, _invalid_consignment)) => {
assert_eq!(
Expand Down
27 changes: 26 additions & 1 deletion tests/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,17 @@ impl TestWallet {
}
}

pub fn get_tx_height(&self, txid: &Txid) -> Option<u32> {
match self
.get_resolver()
.resolve_pub_witness_ord(XWitnessId::Bitcoin(*txid))
.unwrap()
{
WitnessOrd::Mined(witness_pos) => Some(witness_pos.height().get()),
_ => None,
}
}

pub fn sync(&mut self) {
let indexer = self.get_indexer();
self.wallet
Expand All @@ -591,6 +602,20 @@ impl TestWallet {
self.wallet.wallet().seal_close_method()
}

pub fn mine_tx(&self, txid: &Txid, resume: bool) {
let mut attempts = 10;
loop {
mine(resume);
if self.get_tx_height(txid).is_some() {
break;
}
attempts -= 1;
if attempts == 0 {
panic!("TX is not getting mined");
}
}
}

pub fn issue_with_info(
&mut self,
asset_info: AssetInfo,
Expand Down Expand Up @@ -926,7 +951,7 @@ impl TestWallet {
fee: Option<u64>,
) -> (Transfer, Tx) {
let (consignment, tx) = self.transfer(invoice, sats, fee);
mine(false);
self.mine_tx(&tx.txid(), false);
recv_wlt.accept_transfer(consignment.clone());
self.sync();
(consignment, tx)
Expand Down

0 comments on commit 858ef03

Please sign in to comment.