From 3f3c00af1bea16c8ee53fe11c9f2647f243dc7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoe=20Faltib=C3=A0?= Date: Wed, 18 Sep 2024 17:25:21 +0200 Subject: [PATCH 1/2] add mine_tx helper method --- tests/transfers.rs | 6 +++--- tests/utils/helpers.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/transfers.rs b/tests/transfers.rs index 083b3c5..f817dd7 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -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); @@ -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!( diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index de2e7fa..414bbf3 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -579,6 +579,17 @@ impl TestWallet { } } + pub fn get_tx_height(&self, txid: &Txid) -> Option { + 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 @@ -592,6 +603,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, @@ -927,7 +952,7 @@ impl TestWallet { fee: Option, ) -> (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) From 32367cc8695e443f192748f2a300e04a36167153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoe=20Faltib=C3=A0?= Date: Fri, 20 Sep 2024 13:59:47 +0200 Subject: [PATCH 2/2] save consignment yaml on file --- tests/start_services.sh | 1 - tests/utils/helpers.rs | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/start_services.sh b/tests/start_services.sh index 3f41528..5141597 100755 --- a/tests/start_services.sh +++ b/tests/start_services.sh @@ -29,7 +29,6 @@ fi # restart services (down + up) checking for ports availability $COMPOSE_BASE --profile '*' down -v --remove-orphans -rm -rf $TEST_DIR mkdir -p $TEST_DIR for port in "${EXPOSED_PORTS[@]}"; do if [ -n "$(ss -HOlnt "sport = :$port")" ];then diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index 414bbf3..0c4ab50 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -775,12 +775,24 @@ impl TestWallet { let params = TransferParams::with(fee, sats); let (mut psbt, _psbt_meta, consignment) = self.wallet.pay(&invoice, params).unwrap(); + let mut cs_path = self.wallet_dir.join("consignments"); + std::fs::create_dir_all(&cs_path).unwrap(); + cs_path.push(consignment.consignment_id().to_string()); + cs_path.set_extension("yaml"); + let mut file = std::fs::File::options() + .read(true) + .write(true) + .create_new(true) + .open(cs_path) + .unwrap(); + serde_yaml::to_writer(&mut file, &consignment).unwrap(); + let tx = self.sign_finalize(&mut psbt); let txid = tx.txid().to_string(); println!("transfer txid: {txid}"); - let mut tx_path = self.wallet_dir.join("tx"); + let mut tx_path = self.wallet_dir.join("transactions"); std::fs::create_dir_all(&tx_path).unwrap(); tx_path.push(&txid); tx_path.set_extension("yaml");