]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Prefer fully-specified paths in test macros
authorMatt Corallo <git@bluematt.me>
Sun, 17 Oct 2021 21:23:51 +0000 (21:23 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 26 Nov 2021 20:40:51 +0000 (20:40 +0000)
This avoids macros being context-specific use-dependent.

lightning-persister/src/lib.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/monitor_tests.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/payment_tests.rs
lightning/src/ln/reorg_tests.rs
lightning/src/ln/shutdown_tests.rs

index eba0692485a551403b0ae40dc4e74909a2c1bb71..b853b5796b6e7e226fb2efae1d00495ef5de389d 100644 (file)
@@ -191,8 +191,7 @@ mod tests {
        use lightning::{check_closed_broadcast, check_closed_event, check_added_monitors};
        use lightning::ln::features::InitFeatures;
        use lightning::ln::functional_test_utils::*;
-       use lightning::ln::msgs::ErrorAction;
-       use lightning::util::events::{ClosureReason, Event, MessageSendEventsProvider, MessageSendEvent};
+       use lightning::util::events::{ClosureReason, MessageSendEventsProvider};
        use lightning::util::test_utils;
        use std::fs;
        #[cfg(target_os = "windows")]
index cb39b64a44834b83087bd415ee885aea4cf2f633..236b1e498f45ef26b86b1b5b5d46d870028e70ea 100644 (file)
@@ -19,11 +19,10 @@ use bitcoin::network::constants::Network;
 use chain::channelmonitor::ChannelMonitor;
 use chain::transaction::OutPoint;
 use chain::{ChannelMonitorUpdateErr, Listen, Watch};
-use ln::{PaymentPreimage, PaymentHash};
 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
 use ln::features::InitFeatures;
 use ln::msgs;
-use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
+use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
 use util::config::UserConfig;
 use util::enforcing_trait_impls::EnforcingSigner;
 use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason};
@@ -31,9 +30,6 @@ use util::errors::APIError;
 use util::ser::{ReadableArgs, Writeable};
 use util::test_utils::TestBroadcaster;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
-
 use ln::functional_test_utils::*;
 
 use util::test_utils;
index bf3e192b252b3d7fd14fbc542d16c313304279ad..000c31964d22c9e6773619f3eb52f53ab9a585fd 100644 (file)
@@ -33,8 +33,6 @@ use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
 use bitcoin::network::constants::Network;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
 use bitcoin::hash_types::BlockHash;
 
 use bitcoin::secp256k1::key::PublicKey;
@@ -337,9 +335,11 @@ pub fn create_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(node_a: &'a Node<'b,
        (announcement, as_update, bs_update, channel_id, tx)
 }
 
+#[macro_export]
 macro_rules! get_revoke_commit_msgs {
        ($node: expr, $node_id: expr) => {
                {
+                       use util::events::MessageSendEvent;
                        let events = $node.node.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 2);
                        (match events[0] {
@@ -401,13 +401,14 @@ macro_rules! get_event {
 }
 
 #[cfg(test)]
+#[macro_export]
 macro_rules! get_htlc_update_msgs {
        ($node: expr, $node_id: expr) => {
                {
                        let events = $node.node.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 1);
                        match events[0] {
-                               MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
+                               $crate::util::events::MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => {
                                        assert_eq!(*node_id, $node_id);
                                        (*updates).clone()
                                },
@@ -704,6 +705,7 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, '
        }
 }
 
+#[macro_export]
 macro_rules! check_spends {
        ($tx: expr, $($spends_txn: expr),*) => {
                {
@@ -768,6 +770,9 @@ macro_rules! get_closing_signed_broadcast {
 #[macro_export]
 macro_rules! check_closed_broadcast {
        ($node: expr, $with_error_msg: expr) => {{
+               use $crate::util::events::MessageSendEvent;
+               use $crate::ln::msgs::ErrorAction;
+
                let msg_events = $node.node.get_and_clear_pending_msg_events();
                assert_eq!(msg_events.len(), if $with_error_msg { 2 } else { 1 });
                match msg_events[0] {
@@ -795,6 +800,8 @@ macro_rules! check_closed_event {
                check_closed_event!($node, $events, $reason, false);
        };
        ($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {{
+               use $crate::util::events::Event;
+
                let events = $node.node.get_and_clear_pending_events();
                assert_eq!(events.len(), $events);
                let expected_reason = $reason;
@@ -1003,10 +1010,12 @@ macro_rules! get_payment_preimage_hash {
        };
        ($dest_node: expr, $min_value_msat: expr) => {
                {
+                       use bitcoin::hashes::Hash as _;
                        let mut payment_count = $dest_node.network_payment_count.borrow_mut();
-                       let payment_preimage = PaymentPreimage([*payment_count; 32]);
+                       let payment_preimage = $crate::ln::PaymentPreimage([*payment_count; 32]);
                        *payment_count += 1;
-                       let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
+                       let payment_hash = $crate::ln::PaymentHash(
+                               bitcoin::hashes::sha256::Hash::hash(&payment_preimage.0[..]).into_inner());
                        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,17 +1023,18 @@ macro_rules! get_payment_preimage_hash {
 }
 
 #[cfg(test)]
+#[macro_export]
 macro_rules! get_route_and_payment_hash {
        ($send_node: expr, $recv_node: expr, $recv_value: expr) => {{
-               get_route_and_payment_hash!($send_node, $recv_node, vec![], $recv_value, TEST_FINAL_CLTV)
+               $crate::get_route_and_payment_hash!($send_node, $recv_node, vec![], $recv_value, TEST_FINAL_CLTV)
        }};
        ($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 (payment_preimage, payment_hash, payment_secret) = $crate::get_payment_preimage_hash!($recv_node, Some($recv_value));
                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 scorer = ::util::test_utils::TestScorer::with_fixed_penalty(0);
-               let route = ::routing::router::get_route(
+               let scorer = $crate::util::test_utils::TestScorer::with_fixed_penalty(0);
+               let route = $crate::routing::router::get_route(
                        &$send_node.node.get_our_node_id(), &payee, $send_node.network_graph,
                        Some(&$send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
                        $recv_value, $cltv, $send_node.logger, &scorer
@@ -1088,6 +1098,7 @@ macro_rules! expect_payment_received {
 }
 
 #[cfg(test)]
+#[macro_export]
 macro_rules! expect_payment_sent_without_paths {
        ($node: expr, $expected_payment_preimage: expr) => {
                expect_payment_sent!($node, $expected_payment_preimage, None::<u64>, false);
@@ -1097,23 +1108,26 @@ macro_rules! expect_payment_sent_without_paths {
        }
 }
 
+#[macro_export]
 macro_rules! expect_payment_sent {
        ($node: expr, $expected_payment_preimage: expr) => {
-               expect_payment_sent!($node, $expected_payment_preimage, None::<u64>, true);
+               $crate::expect_payment_sent!($node, $expected_payment_preimage, None::<u64>, true);
        };
        ($node: expr, $expected_payment_preimage: expr, $expected_fee_msat_opt: expr) => {
-               expect_payment_sent!($node, $expected_payment_preimage, $expected_fee_msat_opt, true);
+               $crate::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) => {
+       ($node: expr, $expected_payment_preimage: expr, $expected_fee_msat_opt: expr, $expect_paths: expr) => { {
+               use bitcoin::hashes::Hash as _;
                let events = $node.node.get_and_clear_pending_events();
-               let expected_payment_hash = PaymentHash(Sha256::hash(&$expected_payment_preimage.0).into_inner());
+               let expected_payment_hash = $crate::ln::PaymentHash(
+                       bitcoin::hashes::sha256::Hash::hash(&$expected_payment_preimage.0).into_inner());
                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 } => {
+                       $crate::util::events::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());
@@ -1127,7 +1141,7 @@ macro_rules! expect_payment_sent {
                if $expect_paths {
                        for i in 1..events.len() {
                                match events[i] {
-                                       Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => {
+                                       $crate::util::events::Event::PaymentPathSuccessful { payment_id, payment_hash, .. } => {
                                                assert_eq!(payment_id, expected_payment_id);
                                                assert_eq!(payment_hash, Some(expected_payment_hash));
                                        },
@@ -1135,16 +1149,17 @@ macro_rules! expect_payment_sent {
                                }
                        }
                }
-       }
+       } }
 }
 
 #[cfg(test)]
+#[macro_export]
 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 { .. } => {},
+                       $crate::util::events::Event::PaymentPathSuccessful { .. } => {},
                        _ => panic!("Unexpected event"),
                }
        }
index f144dbd9ad61faab79d73e82def57ef91cfd7106..37c319c5799107b2e5bb97f282ed6f2d4a2f250e 100644 (file)
@@ -42,9 +42,6 @@ use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
-
 use bitcoin::secp256k1::Secp256k1;
 use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 
index cfde643bcb93c3ed80b49d102f082fed2a4d15d5..d836b736a98fe4985485f06d2d03d5ae4fd4d681 100644 (file)
 
 use chain::channelmonitor::{ANTI_REORG_DELAY, Balance};
 use chain::transaction::OutPoint;
-use ln::{channel, PaymentPreimage, PaymentHash};
+use ln::channel;
 use ln::channelmanager::BREAKDOWN_TIMEOUT;
 use ln::features::InitFeatures;
-use ln::msgs::{ChannelMessageHandler, ErrorAction};
+use ln::msgs::ChannelMessageHandler;
 use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
 use routing::network_graph::NetworkUpdate;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
-
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
 use bitcoin::secp256k1::Secp256k1;
index e80cf98d7b9b358e7713f21447a9f7516d5ed3f0..05b108fbf25e678e18f16cc36fb7c7a87793d44f 100644 (file)
@@ -12,7 +12,7 @@
 //! returned errors decode to the correct thing.
 
 use chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
-use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
+use ln::{PaymentHash, PaymentSecret};
 use ln::channelmanager::{HTLCForwardInfo, CLTV_FAR_FAR_AWAY};
 use ln::onion_utils;
 use routing::network_graph::NetworkUpdate;
@@ -26,7 +26,6 @@ use util::config::UserConfig;
 
 use bitcoin::hash_types::BlockHash;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash;
 
 use bitcoin::secp256k1;
index 7c9ff3199d15bfe53e2e72967866c85b7b1702ae..518ccd3b0efe5fd6fc75e4ba72eaadbec690205c 100644 (file)
 use chain::{ChannelMonitorUpdateErr, Confirm, Listen, Watch};
 use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor, LATENCY_GRACE_PERIOD_BLOCKS};
 use chain::transaction::OutPoint;
-use ln::{PaymentPreimage, PaymentHash};
 use ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, ChannelManagerReadArgs, PaymentId, PaymentSendFailure};
 use ln::features::InitFeatures;
 use ln::msgs;
-use ln::msgs::{ChannelMessageHandler, ErrorAction};
+use ln::msgs::ChannelMessageHandler;
 use util::events::{ClosureReason, Event, MessageSendEvent, MessageSendEventsProvider};
 use util::test_utils;
 use util::errors::APIError;
@@ -26,8 +25,6 @@ use util::enforcing_trait_impls::EnforcingSigner;
 use util::ser::{ReadableArgs, Writeable};
 use io;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
 use bitcoin::{Block, BlockHeader, BlockHash};
 
 use prelude::*;
index 5cd1a890c49d5d12c6438b7369121d579045609c..570dc3d0eeeece8d7a4f50d006e807d589b66d4e 100644 (file)
 use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
 use chain::transaction::OutPoint;
 use chain::{Confirm, Watch};
-use ln::PaymentHash;
 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs};
 use ln::features::InitFeatures;
-use ln::msgs::{ChannelMessageHandler, ErrorAction};
+use ln::msgs::ChannelMessageHandler;
 use routing::network_graph::NetworkUpdate;
 use util::enforcing_trait_impls::EnforcingSigner;
 use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
@@ -25,8 +24,6 @@ use util::ser::{ReadableArgs, Writeable};
 use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
 use bitcoin::hash_types::BlockHash;
 use bitcoin::secp256k1::Secp256k1;
 
index db76a2c760ccb917d6f98cbbd57735c0114156a8..ffd809bc70d148b3fc37d2301922f914a46d26df 100644 (file)
@@ -11,7 +11,6 @@
 
 use chain::keysinterface::KeysInterface;
 use chain::transaction::OutPoint;
-use ln::{PaymentPreimage, PaymentHash};
 use ln::channelmanager::PaymentSendFailure;
 use routing::router::{Payee, get_route};
 use routing::network_graph::NetworkUpdate;
@@ -28,9 +27,6 @@ use util::config::UserConfig;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::opcodes;
 
-use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::Hash;
-
 use regex;
 
 use core::default::Default;