Skip to content

Commit 8bc3428

Browse files
authored
Merge pull request #1984 from TheBlueMatt/2023-01-test-robust
Make `test_duplicate_payment_hash_one_failure_one_success` robust
2 parents e2beaef + 7dcbf2c commit 8bc3428

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4718,8 +4718,8 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47184718
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
47194719
let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id())
47204720
.with_features(nodes[3].node.invoice_features());
4721-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[3], payment_params, 900000, TEST_FINAL_CLTV - 40);
4722-
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 900000, duplicate_payment_hash, payment_secret);
4721+
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[3], payment_params, 800_000, TEST_FINAL_CLTV - 40);
4722+
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 800_000, duplicate_payment_hash, payment_secret);
47234723

47244724
let commitment_txn = get_local_commitment_txn!(nodes[2], chan_2.2);
47254725
assert_eq!(commitment_txn[0].input.len(), 1);
@@ -4739,25 +4739,35 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47394739

47404740
check_spends!(node_txn[0], commitment_txn[0]);
47414741
assert_eq!(node_txn[0].input.len(), 1);
4742+
assert_eq!(node_txn[0].output.len(), 1);
47424743

47434744
if node_txn.len() > 2 {
47444745
check_spends!(node_txn[1], commitment_txn[0]);
47454746
assert_eq!(node_txn[1].input.len(), 1);
4747+
assert_eq!(node_txn[1].output.len(), 1);
47464748
assert_eq!(node_txn[0].input[0].previous_output, node_txn[1].input[0].previous_output);
47474749

47484750
check_spends!(node_txn[2], commitment_txn[0]);
4751+
assert_eq!(node_txn[2].input.len(), 1);
4752+
assert_eq!(node_txn[2].output.len(), 1);
47494753
assert_ne!(node_txn[0].input[0].previous_output, node_txn[2].input[0].previous_output);
47504754
} else {
47514755
check_spends!(node_txn[1], commitment_txn[0]);
4756+
assert_eq!(node_txn[1].input.len(), 1);
4757+
assert_eq!(node_txn[1].output.len(), 1);
47524758
assert_ne!(node_txn[0].input[0].previous_output, node_txn[1].input[0].previous_output);
47534759
}
47544760

47554761
assert_eq!(node_txn[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
47564762
assert_eq!(node_txn[1].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
4763+
// Assign htlc_timeout_tx to the forwarded HTLC (with value ~800 sats). The received HTLC
4764+
// (with value 900 sats) will be claimed in the below `claim_funds` call.
47574765
if node_txn.len() > 2 {
47584766
assert_eq!(node_txn[2].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
4767+
htlc_timeout_tx = if node_txn[2].output[0].value < 900 { node_txn[2].clone() } else { node_txn[0].clone() };
4768+
} else {
4769+
htlc_timeout_tx = if node_txn[0].output[0].value < 900 { node_txn[1].clone() } else { node_txn[0].clone() };
47594770
}
4760-
htlc_timeout_tx = node_txn[0].clone();
47614771
}
47624772

47634773
nodes[2].node.claim_funds(our_payment_preimage);
@@ -4808,7 +4818,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
48084818
// Note that the fee paid is effectively double as the HTLC value (including the nodes[1] fee
48094819
// and nodes[2] fee) is rounded down and then claimed in full.
48104820
mine_transaction(&nodes[1], &htlc_success_txn[1]);
4811-
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(196*2), true, true);
4821+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(196), true, true);
48124822
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
48134823
assert!(updates.update_add_htlcs.is_empty());
48144824
assert!(updates.update_fail_htlcs.is_empty());

0 commit comments

Comments
 (0)