Skip to content

Commit c7d375e

Browse files
committed
f moar test
1 parent 6064d96 commit c7d375e

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,13 +1485,11 @@ macro_rules! expect_payment_failed {
14851485
};
14861486
}
14871487

1488-
pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
1489-
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
1490-
conditions: PaymentFailedConditions<'e>
1488+
pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
1489+
node: &'a Node<'b, 'c, 'd>, payment_failed_event: Event, expected_payment_hash: PaymentHash,
1490+
expected_rejected_by_dest: bool, conditions: PaymentFailedConditions<'e>
14911491
) {
1492-
let mut events = node.node.get_and_clear_pending_events();
1493-
assert_eq!(events.len(), 1);
1494-
let expected_payment_id = match events.pop().unwrap() {
1492+
let expected_payment_id = match payment_failed_event {
14951493
Event::PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update,
14961494
#[cfg(test)]
14971495
error_code,
@@ -1551,6 +1549,15 @@ pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
15511549
}
15521550
}
15531551

1552+
pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
1553+
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
1554+
conditions: PaymentFailedConditions<'e>
1555+
) {
1556+
let mut events = node.node.get_and_clear_pending_events();
1557+
assert_eq!(events.len(), 1);
1558+
expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_rejected_by_dest, conditions);
1559+
}
1560+
15541561
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
15551562
let payment_id = origin_node.node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
15561563
check_added_monitors!(origin_node, expected_paths.len());

lightning/src/ln/monitor_tests.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,14 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
772772
let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 };
773773
assert_eq!(funding_outpoint.to_channel_id(), chan_id);
774774

775-
// We create four HTLCs for B to claim against A's revoked commitment transaction:
775+
// We create five HTLCs for B to claim against A's revoked commitment transaction:
776776
//
777777
// (1) one for which A is the originator and B knows the preimage
778778
// (2) one for which B is the originator where the HTLC has since timed-out
779779
// (3) one for which B is the originator but where the HTLC has not yet timed-out
780780
// (4) one dust HTLC which is lost in the channel closure
781+
// (5) one that actually isn't in the revoked commitment transaction at all, but was added in
782+
// later commitment transaction updates
781783
//
782784
// Though they could all be claimed in a single claim transaction, due to CLTV timeouts they
783785
// are all currently claimed in separate transactions, which helps us test as we can claim
@@ -801,16 +803,8 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
801803

802804
let chan_feerate = get_feerate!(nodes[0], chan_id) as u64;
803805

804-
{
805-
let mut feerate = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap();
806-
*feerate += 1;
807-
}
808-
nodes[0].node.timer_tick_occurred();
809-
check_added_monitors!(nodes[0], 1);
810-
811-
let fee_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
812-
nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap());
813-
commitment_signed_dance!(nodes[1], nodes[0], fee_update.commitment_signed, false);
806+
let missing_htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety
807+
let missing_htlc_payment_hash = route_payment(&nodes[1], &[&nodes[0]], 2_000_000).1;
814808

815809
nodes[1].node.claim_funds(claimed_payment_preimage);
816810
expect_payment_claimed!(nodes[1], claimed_payment_hash, 3_000_000);
@@ -836,7 +830,10 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
836830
// Prior to channel closure, B considers the preimage HTLC as its own, and otherwise only
837831
// lists the two on-chain timeout-able HTLCs as claimable balances.
838832
assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose {
839-
claimable_amount_satoshis: 100_000 - 5_000 - 4_000 - 3 + 3_000,
833+
claimable_amount_satoshis: 100_000 - 5_000 - 4_000 - 3 - 2_000 + 3_000,
834+
}, Balance::MaybeClaimableHTLCAwaitingTimeout {
835+
claimable_amount_satoshis: 2_000,
836+
claimable_height: missing_htlc_cltv_timeout,
840837
}, Balance::MaybeClaimableHTLCAwaitingTimeout {
841838
claimable_amount_satoshis: 4_000,
842839
claimable_height: htlc_cltv_timeout,
@@ -955,7 +952,14 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
955952

956953
connect_blocks(&nodes[1], 1);
957954
test_spendable_output(&nodes[1], &as_revoked_txn[0]);
958-
expect_payment_failed!(nodes[1], dust_payment_hash, true);
955+
956+
let mut payment_failed_events = nodes[1].node.get_and_clear_pending_events();
957+
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
958+
dust_payment_hash, true, PaymentFailedConditions::new());
959+
expect_payment_failed_conditions_event(&nodes[1], payment_failed_events.pop().unwrap(),
960+
missing_htlc_payment_hash, true, PaymentFailedConditions::new());
961+
assert!(payment_failed_events.is_empty());
962+
959963
connect_blocks(&nodes[1], 1);
960964
test_spendable_output(&nodes[1], &claim_txn[if confirm_htlc_spend_first { 2 } else { 3 }]);
961965
connect_blocks(&nodes[1], 1);

0 commit comments

Comments
 (0)