Skip to content

Commit a06d158

Browse files
committed
Add test for PathParameterError introduced in previous commit
- Also modify the unwrap_send_err!() macro to handle the PathParameterError
1 parent 9bd1cc7 commit a06d158

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lightning/src/ln/functional_test_utils.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,14 @@ macro_rules! unwrap_send_err {
948948
_ => panic!(),
949949
}
950950
},
951-
_ => panic!(),
951+
&Err(PaymentSendFailure::PathParameterError(ref result)) if !$all_failed => {
952+
assert_eq!(result.len(), 1);
953+
match result[0] {
954+
Err($type) => { $check },
955+
_ => panic!(),
956+
}
957+
},
958+
_ => {panic!()},
952959
}
953960
}
954961
}

lightning/src/ln/functional_tests.rs

+24
Original file line numberDiff line numberDiff line change
@@ -6204,6 +6204,30 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() {
62046204
check_added_monitors!(nodes[0], 1);
62056205
}
62066206

6207+
#[test]
6208+
fn test_payment_route_reaching_same_channel_twice() {
6209+
//A route should not go through the same channel twice
6210+
//It is enforced when constructing a route.
6211+
let chanmon_cfgs = create_chanmon_cfgs(2);
6212+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
6213+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
6214+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
6215+
let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0);
6216+
6217+
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 0)
6218+
.with_bolt11_features(nodes[1].node.bolt11_invoice_features()).unwrap();
6219+
let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, 100000000);
6220+
6221+
// Extend the path by itself, essentially simulating route going through same channel twice
6222+
let cloned_hops = route.paths[0].hops.clone();
6223+
route.paths[0].hops.extend_from_slice(&cloned_hops);
6224+
6225+
unwrap_send_err!(nodes[0].node.send_payment_with_route(&route, our_payment_hash,
6226+
RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)
6227+
), false, APIError::InvalidRoute { ref err },
6228+
assert_eq!(err, &"Path went through the same channel twice"));
6229+
}
6230+
62076231
// BOLT 2 Requirements for the Sender when constructing and sending an update_add_htlc message.
62086232
// BOLT 2 Requirement: MUST NOT offer amount_msat it cannot pay for in the remote commitment transaction at the current feerate_per_kw (see "Updating Fees") while maintaining its channel reserve.
62096233
//TODO: I don't believe this is explicitly enforced when sending an HTLC but as the Fee aspect of the BOLT specs is in flux leaving this as a TODO.

0 commit comments

Comments
 (0)