Skip to content

Commit 65c25ed

Browse files
committed
Fix test_duplicate_htlc_different_direction_onchain
1 parent 838ef29 commit 65c25ed

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,18 +1308,21 @@ fn test_duplicate_htlc_different_direction_onchain() {
13081308

13091309
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
13101310

1311+
let payment_value_sats = 546;
1312+
let payment_value_msats = payment_value_sats * 1000;
1313+
13111314
// balancing
13121315
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
13131316

13141317
let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 900_000);
13151318

1316-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], 800_000);
1319+
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_value_msats);
13171320
let node_a_payment_secret = nodes[0].node.create_inbound_payment_for_hash(payment_hash, None, 7200, None).unwrap();
1318-
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], 800_000, payment_hash, node_a_payment_secret);
1321+
send_along_route_with_secret(&nodes[1], route, &[&[&nodes[0]]], payment_value_msats, payment_hash, node_a_payment_secret);
13191322

13201323
// Provide preimage to node 0 by claiming payment
13211324
nodes[0].node.claim_funds(payment_preimage);
1322-
expect_payment_claimed!(nodes[0], payment_hash, 800_000);
1325+
expect_payment_claimed!(nodes[0], payment_hash, payment_value_msats);
13231326
check_added_monitors!(nodes[0], 1);
13241327

13251328
// Broadcast node 1 commitment txn
@@ -1328,7 +1331,7 @@ fn test_duplicate_htlc_different_direction_onchain() {
13281331
assert_eq!(remote_txn[0].output.len(), 4); // 1 local, 1 remote, 1 htlc inbound, 1 htlc outbound
13291332
let mut has_both_htlcs = 0; // check htlcs match ones committed
13301333
for outp in remote_txn[0].output.iter() {
1331-
if outp.value.to_sat() == 800_000 / 1000 {
1334+
if outp.value.to_sat() == payment_value_sats {
13321335
has_both_htlcs += 1;
13331336
} else if outp.value.to_sat() == 900_000 / 1000 {
13341337
has_both_htlcs += 1;
@@ -1342,24 +1345,22 @@ fn test_duplicate_htlc_different_direction_onchain() {
13421345
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
13431346

13441347
let claim_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
1345-
assert_eq!(claim_txn.len(), 3);
1348+
assert!(claim_txn.len() >= 3);
1349+
assert!(claim_txn.len() <= 5);
13461350

13471351
check_spends!(claim_txn[0], remote_txn[0]); // Immediate HTLC claim with preimage
13481352
check_spends!(claim_txn[1], remote_txn[0]);
13491353
check_spends!(claim_txn[2], remote_txn[0]);
13501354
let preimage_tx = &claim_txn[0];
1351-
let (preimage_bump_tx, timeout_tx) = if claim_txn[1].input[0].previous_output == preimage_tx.input[0].previous_output {
1352-
(&claim_txn[1], &claim_txn[2])
1353-
} else {
1354-
(&claim_txn[2], &claim_txn[1])
1355-
};
1355+
let timeout_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap();
1356+
let preimage_bump_tx = claim_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap();
13561357

13571358
assert_eq!(preimage_tx.input.len(), 1);
13581359
assert_eq!(preimage_bump_tx.input.len(), 1);
13591360

13601361
assert_eq!(preimage_tx.input.len(), 1);
13611362
assert_eq!(preimage_tx.input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC 1 <--> 0, preimage tx
1362-
assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), 800);
1363+
assert_eq!(remote_txn[0].output[preimage_tx.input[0].previous_output.vout as usize].value.to_sat(), payment_value_sats);
13631364

13641365
assert_eq!(timeout_tx.input.len(), 1);
13651366
assert_eq!(timeout_tx.input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT); // HTLC 0 <--> 1, timeout tx

0 commit comments

Comments
 (0)