X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Ffunctional_test_utils.rs;h=bf3e192b252b3d7fd14fbc542d16c313304279ad;hb=04d0cca87293f5a47812d19920686755892f8446;hp=5983e4e2871cea3bc4306ee32dc20829036e05d2;hpb=bcdd85227949d17c9a98a9fc0b666bce4a97c856;p=rust-lightning diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 5983e4e2..bf3e192b 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -17,7 +17,6 @@ use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use ln::channelmanager::{ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, PaymentId}; use routing::network_graph::{NetGraphMsgHandler, NetworkGraph}; use routing::router::{Payee, Route, get_route}; -use routing::scorer::Scorer; use ln::features::{InitFeatures, InvoiceFeatures}; use ln::msgs; use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler}; @@ -243,10 +242,9 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { // Check that if we serialize the Router, we can deserialize it again. { let mut w = test_utils::TestVecWriter(Vec::new()); - let network_graph_ser = &self.net_graph_msg_handler.network_graph; - network_graph_ser.write(&mut w).unwrap(); + self.network_graph.write(&mut w).unwrap(); let network_graph_deser = ::read(&mut io::Cursor::new(&w.0)).unwrap(); - assert!(network_graph_deser == *self.net_graph_msg_handler.network_graph); + assert!(network_graph_deser == *self.network_graph); let net_graph_msg_handler = NetGraphMsgHandler::new( &network_graph_deser, Some(self.chain_source), self.logger ); @@ -485,9 +483,9 @@ macro_rules! unwrap_send_err { _ => panic!(), } }, - &Err(PaymentSendFailure::PartialFailure(ref fails)) if !$all_failed => { - assert_eq!(fails.len(), 1); - match fails[0] { + &Err(PaymentSendFailure::PartialFailure { ref results, .. }) if !$all_failed => { + assert_eq!(results.len(), 1); + match results[0] { Err($type) => { $check }, _ => panic!(), } @@ -709,6 +707,14 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec { { + $( + for outp in $spends_txn.output.iter() { + assert!(outp.value >= outp.script_pubkey.dust_value().as_sat(), "Input tx output didn't meet dust limit"); + } + )* + for outp in $tx.output.iter() { + assert!(outp.value >= outp.script_pubkey.dust_value().as_sat(), "Spending tx output didn't meet dust limit"); + } let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| { $( if out_point.txid == $spends_txn.txid() { @@ -1001,7 +1007,7 @@ macro_rules! get_payment_preimage_hash { let payment_preimage = PaymentPreimage([*payment_count; 32]); *payment_count += 1; let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()); - let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, 0).unwrap(); + let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200).unwrap(); (payment_preimage, payment_hash, payment_secret) } } @@ -1014,13 +1020,12 @@ macro_rules! get_route_and_payment_hash { }}; ($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{ let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node, Some($recv_value)); - let payee = $crate::routing::router::Payee::new($recv_node.node.get_our_node_id()) + let payee = $crate::routing::router::Payee::from_node_id($recv_node.node.get_our_node_id()) .with_features($crate::ln::features::InvoiceFeatures::known()) .with_route_hints($last_hops); - let net_graph_msg_handler = &$send_node.net_graph_msg_handler; - let scorer = ::routing::scorer::Scorer::with_fixed_penalty(0); + let scorer = ::util::test_utils::TestScorer::with_fixed_penalty(0); let route = ::routing::router::get_route( - &$send_node.node.get_our_node_id(), &payee, &net_graph_msg_handler.network_graph, + &$send_node.node.get_our_node_id(), &payee, $send_node.network_graph, Some(&$send_node.node.list_usable_channels().iter().collect::>()), $recv_value, $cltv, $send_node.logger, &scorer ).unwrap(); @@ -1082,24 +1087,65 @@ macro_rules! expect_payment_received { } } +#[cfg(test)] +macro_rules! expect_payment_sent_without_paths { + ($node: expr, $expected_payment_preimage: expr) => { + expect_payment_sent!($node, $expected_payment_preimage, None::, false); + }; + ($node: expr, $expected_payment_preimage: expr, $expected_fee_msat_opt: expr) => { + expect_payment_sent!($node, $expected_payment_preimage, $expected_fee_msat_opt, false); + } +} + macro_rules! expect_payment_sent { ($node: expr, $expected_payment_preimage: expr) => { - expect_payment_sent!($node, $expected_payment_preimage, None::); + expect_payment_sent!($node, $expected_payment_preimage, None::, true); }; ($node: expr, $expected_payment_preimage: expr, $expected_fee_msat_opt: expr) => { + expect_payment_sent!($node, $expected_payment_preimage, $expected_fee_msat_opt, true); + }; + ($node: expr, $expected_payment_preimage: expr, $expected_fee_msat_opt: expr, $expect_paths: expr) => { let events = $node.node.get_and_clear_pending_events(); let expected_payment_hash = PaymentHash(Sha256::hash(&$expected_payment_preimage.0).into_inner()); - assert_eq!(events.len(), 1); - match events[0] { - Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => { + if $expect_paths { + assert!(events.len() > 1); + } else { + assert_eq!(events.len(), 1); + } + let expected_payment_id = match events[0] { + Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => { assert_eq!($expected_payment_preimage, *payment_preimage); assert_eq!(expected_payment_hash, *payment_hash); assert!(fee_paid_msat.is_some()); if $expected_fee_msat_opt.is_some() { assert_eq!(*fee_paid_msat, $expected_fee_msat_opt); } + payment_id.unwrap() }, _ => panic!("Unexpected event"), + }; + if $expect_paths { + for i in 1..events.len() { + match events[i] { + Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => { + assert_eq!(payment_id, expected_payment_id); + assert_eq!(payment_hash, Some(expected_payment_hash)); + }, + _ => panic!("Unexpected event"), + } + } + } + } +} + +#[cfg(test)] +macro_rules! expect_payment_path_successful { + ($node: expr) => { + let events = $node.node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match events[0] { + Event::PaymentPathSuccessful { .. } => {}, + _ => panic!("Unexpected event"), } } } @@ -1353,12 +1399,11 @@ pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: pub const TEST_FINAL_CLTV: u32 = 70; pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) { - let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id()) + let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) .with_features(InvoiceFeatures::known()); - let net_graph_msg_handler = &origin_node.net_graph_msg_handler; - let scorer = Scorer::with_fixed_penalty(0); + let scorer = test_utils::TestScorer::with_fixed_penalty(0); let route = get_route( - &origin_node.node.get_our_node_id(), &payee, &net_graph_msg_handler.network_graph, + &origin_node.node.get_our_node_id(), &payee, &origin_node.network_graph, Some(&origin_node.node.list_usable_channels().iter().collect::>()), recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); assert_eq!(route.paths.len(), 1); @@ -1372,11 +1417,10 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: } pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) { - let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id()) + let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id()) .with_features(InvoiceFeatures::known()); - let net_graph_msg_handler = &origin_node.net_graph_msg_handler; - let scorer = Scorer::with_fixed_penalty(0); - let route = get_route(&origin_node.node.get_our_node_id(), &payee, &net_graph_msg_handler.network_graph, None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); + let scorer = test_utils::TestScorer::with_fixed_penalty(0); + let route = get_route(&origin_node.node.get_our_node_id(), &payee, origin_node.network_graph, None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap(); 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()) { @@ -1742,7 +1786,7 @@ pub fn handle_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec(nodes: &Vec>, a: usize, b: usize) { - handle_announce_close_broadcast_events(nodes, a, b, false, "Commitment or closing transaction was confirmed on chain."); + handle_announce_close_broadcast_events(nodes, a, b, false, "Channel closed because commitment or closing transaction was confirmed on chain."); } #[cfg(test)]