use chain::chaininterface;
use chain::transaction::OutPoint;
use chain::keysinterface::KeysInterface;
-use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash};
+use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
use ln::channelmonitor::{ChannelMonitor, ManyChannelMonitor};
use ln::router::{Route, Router, RouterReadArgs};
use ln::features::InitFeatures;
}
}
+macro_rules! get_local_commitment_txn {
+ ($node: expr, $channel_id: expr) => {
+ {
+ let mut monitors = $node.chan_monitor.simple_monitor.monitors.lock().unwrap();
+ let mut commitment_txn = None;
+ for (funding_txo, monitor) in monitors.iter_mut() {
+ if funding_txo.to_channel_id() == $channel_id {
+ commitment_txn = Some(monitor.get_latest_local_commitment_txn());
+ break;
+ }
+ }
+ commitment_txn.unwrap()
+ }
+ }
+}
+
+macro_rules! unwrap_send_err {
+ ($res: expr, $all_failed: expr, $type: pat, $check: expr) => {
+ match &$res {
+ &Err(PaymentSendFailure::AllFailedRetrySafe(ref fails)) if $all_failed => {
+ assert_eq!(fails.len(), 1);
+ match fails[0] {
+ $type => { $check },
+ _ => panic!(),
+ }
+ },
+ &Err(PaymentSendFailure::PartialFailure(ref fails)) if !$all_failed => {
+ assert_eq!(fails.len(), 1);
+ match fails[0] {
+ Err($type) => { $check },
+ _ => panic!(),
+ }
+ },
+ _ => panic!(),
+ }
+ }
+}
+
pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_chan_value: u64, expected_user_chan_id: u64) -> ([u8; 32], Transaction, OutPoint) {
let chan_id = *node.network_chan_count.borrow();
let events = $node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentReceived { ref payment_hash, amt } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_secret, amt } => {
assert_eq!($expected_payment_hash, *payment_hash);
+ assert_eq!(None, *payment_secret);
assert_eq!($expected_recv_value, amt);
},
_ => panic!("Unexpected event"),
}
}
-pub fn send_along_route_with_hash<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash) {
+pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>) {
let mut payment_event = {
- origin_node.node.send_payment(route, our_payment_hash).unwrap();
+ origin_node.node.send_payment(route, our_payment_hash, &our_payment_secret).unwrap();
check_added_monitors!(origin_node, 1);
let mut events = origin_node.node.get_and_clear_pending_msg_events();
let events_2 = node.node.get_and_clear_pending_events();
assert_eq!(events_2.len(), 1);
match events_2[0] {
- Event::PaymentReceived { ref payment_hash, amt } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_secret, amt } => {
assert_eq!(our_payment_hash, *payment_hash);
+ assert_eq!(our_payment_secret, *payment_secret);
assert_eq!(amt, recv_value);
},
_ => panic!("Unexpected event"),
}
}
+pub fn send_along_route_with_hash<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash) {
+ send_along_route_with_secret(origin_node, route, expected_route, recv_value, our_payment_hash, None);
+}
+
pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash) {
let (our_payment_preimage, our_payment_hash) = get_payment_preimage_hash!(origin_node);
send_along_route_with_hash(origin_node, route, expected_route, recv_value, our_payment_hash);
(our_payment_preimage, our_payment_hash)
}
-pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_preimage: PaymentPreimage, expected_amount: u64) {
- assert!(expected_route.last().unwrap().node.claim_funds(our_payment_preimage, expected_amount));
+pub fn claim_payment_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_preimage: PaymentPreimage, our_payment_secret: Option<PaymentSecret>, expected_amount: u64) {
+ assert!(expected_route.last().unwrap().node.claim_funds(our_payment_preimage, &our_payment_secret, expected_amount));
check_added_monitors!(expected_route.last().unwrap(), 1);
let mut next_msgs: Option<(msgs::UpdateFulfillHTLC, msgs::CommitmentSigned)> = None;
}
}
+pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_preimage: PaymentPreimage, expected_amount: u64) {
+ claim_payment_along_route_with_secret(origin_node, expected_route, skip_last, our_payment_preimage, None, expected_amount);
+}
+
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage, expected_amount: u64) {
claim_payment_along_route(origin_node, expected_route, false, our_payment_preimage, expected_amount);
}
pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash) {
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
- assert_eq!(route.hops.len(), expected_route.len());
- for (node, hop) in expected_route.iter().zip(route.hops.iter()) {
+ assert_eq!(route.paths.len(), 1);
+ assert_eq!(route.paths[0].len(), expected_route.len());
+ for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {
assert_eq!(hop.pubkey, node.node.get_our_node_id());
}
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
- assert_eq!(route.hops.len(), expected_route.len());
- for (node, hop) in expected_route.iter().zip(route.hops.iter()) {
+ assert_eq!(route.paths.len(), 1);
+ assert_eq!(route.paths[0].len(), expected_route.len());
+ for (node, hop) in expected_route.iter().zip(route.paths[0].iter()) {
assert_eq!(hop.pubkey, node.node.get_our_node_id());
}
let (_, our_payment_hash) = get_payment_preimage_hash!(origin_node);
-
- let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
- match err {
- APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"),
- _ => panic!("Unknown error variants"),
- };
+ unwrap_send_err!(origin_node.node.send_payment(route, our_payment_hash, &None), true, APIError::ChannelUnavailable { err },
+ assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"));
}
pub fn send_payment<'a, 'b, 'c>(origin: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64, expected_value: u64) {
}
pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], skip_last: bool, our_payment_hash: PaymentHash) {
- assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash));
+ assert!(expected_route.last().unwrap().node.fail_htlc_backwards(&our_payment_hash, &None));
expect_pending_htlcs_forwardable!(expected_route.last().unwrap());
check_added_monitors!(expected_route.last().unwrap(), 1);