Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #13

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/start_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fi

# restart services (down + up) checking for ports availability
$COMPOSE_BASE --profile '*' down -v --remove-orphans
rm -rf $TEST_DIR
zoedberg marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $TEST_DIR
for port in "${EXPOSED_PORTS[@]}"; do
if [ -n "$(ss -HOlnt "sport = :$port")" ];then
Expand Down
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
41 changes: 39 additions & 2 deletions tests/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,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 @@ -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() {
zoedberg marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -750,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();
zoedberg marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand Down Expand Up @@ -927,7 +964,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