Skip to content

Commit

Permalink
parametrize ln_transfers: calls to update_witnesses shouldn't disrupt…
Browse files Browse the repository at this point in the history
… channel operations
  • Loading branch information
St333p committed Jan 13, 2025
1 parent 1163628 commit d6c1603
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,11 @@ fn accept_0conf() {
);
}

#[test]
fn ln_transfers() {
#[rstest]
#[case(false)]
#[ignore = "fix needed"] // https://github.com/RGB-WG/rgb-std/issues/292
#[case(true)]
fn ln_transfers(#[case] update_witnesses_before_htlc: bool) {
initialize();

let mut wlt_1 = get_wallet(&DescriptorType::Wpkh);
Expand Down Expand Up @@ -787,6 +790,9 @@ fn ln_transfers() {
let htlc_btc_amt = 4000;
let htlc_derived_addr = wlt_1.get_derived_address();

// no problem: since there's no htlc for this commitment
wlt_1.sync_and_update_witnesses(Some(pre_funding_height));

println!("\n2. fake commitment TX (1 HTLC)");
let beneficiaries = vec![
(wlt_2.get_address(), Some(2000)),
Expand All @@ -811,6 +817,10 @@ fn ln_transfers() {
wlt_1.consume_fascia(fascia.clone(), psbt.txid());
wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll);

if update_witnesses_before_htlc {
wlt_1.sync_and_update_witnesses(Some(pre_funding_height));
}

println!("\n3. fake HTLC TX");
let witness_id = fascia.witness_id();
let txid = witness_id.as_reduced_unsafe();
Expand Down Expand Up @@ -887,6 +897,10 @@ fn ln_transfers() {
wlt_1.consume_fascia(fascia.clone(), psbt.txid());
wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll);

if update_witnesses_before_htlc {
wlt_1.sync_and_update_witnesses(Some(pre_funding_height));
}

println!("\n6. fake HTLC TX");
let witness_id = fascia.witness_id();
let txid = witness_id.as_reduced_unsafe();
Expand Down Expand Up @@ -914,6 +928,9 @@ fn ln_transfers() {
wlt_1.consume_fascia(fascia.clone(), psbt.txid());
wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll);

// no problem: since the force-close tx will be updated to mined soon
wlt_1.sync_and_update_witnesses(Some(pre_funding_height));

println!("\n7. broadcast old PSBT");
let tx = wlt_1.sign_finalize_extract(&mut old_psbt);
wlt_1.broadcast_tx(&tx);
Expand Down

0 comments on commit d6c1603

Please sign in to comment.