Skip to content

Commit 2cf23ce

Browse files
committed
f add coverage to check incoming accountable for receiving node
1 parent 86e044a commit 2cf23ce

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lightning/src/ln/accountable_tests.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
1+
use crate::ln::channelmanager::{
2+
HTLCForwardInfo, PaymentId, PendingAddHTLCInfo, PendingHTLCInfo, RecipientOnionFields, Retry,
3+
};
24
use crate::ln::functional_test_utils::*;
35
use crate::ln::msgs::{accountable_from_bool, ChannelMessageHandler, ExperimentalAccountable};
46
use crate::routing::router::{PaymentParameters, RouteParameters};
57

68
fn test_accountable_forwarding_with_override(
7-
override_accountable: ExperimentalAccountable, expected_forwarded: ExperimentalAccountable,
9+
override_accountable: ExperimentalAccountable, expected_forwarded: bool,
810
) {
911
let chanmon_cfgs = create_chanmon_cfgs(3);
1012
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -45,14 +47,35 @@ fn test_accountable_forwarding_with_override(
4547
let updates_bc = get_htlc_update_msgs(&nodes[1], &nodes[2].node.get_our_node_id());
4648
assert_eq!(updates_bc.update_add_htlcs.len(), 1);
4749
let htlc_bc = &updates_bc.update_add_htlcs[0];
50+
let expected_acountable_signal = accountable_from_bool(expected_forwarded);
4851
assert_eq!(
49-
htlc_bc.accountable, expected_forwarded,
52+
htlc_bc.accountable, expected_acountable_signal,
5053
"B -> C should have accountable = {:?}",
51-
expected_forwarded
54+
expected_acountable_signal
5255
);
5356

5457
nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), htlc_bc);
5558
do_commitment_signed_dance(&nodes[2], &nodes[1], &updates_bc.commitment_signed, false, false);
59+
60+
// Accountable signal is not surfaced in PaymentClaimable, so we do our next-best and check
61+
// that the received htlcs that will be processed has the signal set as we expect. We manually
62+
// process pending update adds so that we can access the htlc in forward_htlcs.
63+
nodes[2].node.process_pending_update_add_htlcs();
64+
{
65+
let fwds_lock = nodes[2].node.forward_htlcs.lock().unwrap();
66+
let recvs = fwds_lock.get(&0).unwrap();
67+
assert_eq!(recvs.len(), 1);
68+
match recvs[0] {
69+
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
70+
forward_info: PendingHTLCInfo { incoming_accountable, .. },
71+
..
72+
}) => {
73+
assert_eq!(incoming_accountable, expected_forwarded)
74+
},
75+
_ => panic!("Unexpected forward"),
76+
}
77+
}
78+
5679
expect_and_process_pending_htlcs(&nodes[2], false);
5780
check_added_monitors(&nodes[2], 0);
5881
expect_payment_claimable!(nodes[2], payment_hash, payment_secret, 100_000);
@@ -62,7 +85,7 @@ fn test_accountable_forwarding_with_override(
6285
#[test]
6386
fn test_accountable_signal() {
6487
// Tests forwarding of accountable signal for various incoming signal values.
65-
test_accountable_forwarding_with_override(None, accountable_from_bool(false));
66-
test_accountable_forwarding_with_override(Some(7), accountable_from_bool(true));
67-
test_accountable_forwarding_with_override(Some(3), accountable_from_bool(false));
88+
test_accountable_forwarding_with_override(None, false);
89+
test_accountable_forwarding_with_override(Some(7), true);
90+
test_accountable_forwarding_with_override(Some(3), false);
6891
}

0 commit comments

Comments
 (0)