Skip to content

Commit da498d7

Browse files
authored
Merge pull request #1120 from jkczyz/2021-10-test-refactors
Pre-scoring test clean-ups
2 parents 2144166 + d4ec090 commit da498d7

10 files changed

+164
-400
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ const FRESHNESS_TIMER: u64 = 60;
6060
#[cfg(test)]
6161
const FRESHNESS_TIMER: u64 = 1;
6262

63-
#[cfg(not(debug_assertions))]
63+
#[cfg(all(not(test), not(debug_assertions)))]
6464
const PING_TIMER: u64 = 5;
6565
/// Signature operations take a lot longer without compiler optimisations.
6666
/// Increasing the ping timer allows for this but slower devices will be disconnected if the
6767
/// timeout is reached.
68-
#[cfg(debug_assertions)]
68+
#[cfg(all(not(test), debug_assertions))]
6969
const PING_TIMER: u64 = 30;
70+
#[cfg(test)]
71+
const PING_TIMER: u64 = 1;
7072

7173
/// Trait which handles persisting a [`ChannelManager`] to disk.
7274
///

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,8 +2615,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26152615
let revocation_sig_claim = (input.witness.len() == 3 && HTLCType::scriptlen_to_htlctype(input.witness[2].len()) == Some(HTLCType::OfferedHTLC) && input.witness[1].len() == 33)
26162616
|| (input.witness.len() == 3 && HTLCType::scriptlen_to_htlctype(input.witness[2].len()) == Some(HTLCType::AcceptedHTLC) && input.witness[1].len() == 33);
26172617
let accepted_preimage_claim = input.witness.len() == 5 && HTLCType::scriptlen_to_htlctype(input.witness[4].len()) == Some(HTLCType::AcceptedHTLC);
2618+
#[cfg(not(fuzzing))]
26182619
let accepted_timeout_claim = input.witness.len() == 3 && HTLCType::scriptlen_to_htlctype(input.witness[2].len()) == Some(HTLCType::AcceptedHTLC) && !revocation_sig_claim;
26192620
let offered_preimage_claim = input.witness.len() == 3 && HTLCType::scriptlen_to_htlctype(input.witness[2].len()) == Some(HTLCType::OfferedHTLC) && !revocation_sig_claim;
2621+
#[cfg(not(fuzzing))]
26202622
let offered_timeout_claim = input.witness.len() == 5 && HTLCType::scriptlen_to_htlctype(input.witness[4].len()) == Some(HTLCType::OfferedHTLC);
26212623

26222624
let mut payment_preimage = PaymentPreimage([0; 32]);

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 24 additions & 91 deletions
Large diffs are not rendered by default.

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,12 +5943,9 @@ mod tests {
59435943
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
59445944
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
59455945
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
5946-
let logger = test_utils::TestLogger::new();
59475946

59485947
// First, send a partial MPP payment.
5949-
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
5950-
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5951-
let (payment_preimage, our_payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[1]);
5948+
let (route, our_payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], 100_000);
59525949
let payment_id = PaymentId([42; 32]);
59535950
// Use the utility function send_payment_along_path to send the payment with MPP data which
59545951
// indicates there are more HTLCs coming.
@@ -6201,12 +6198,9 @@ mod tests {
62016198
let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
62026199
let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
62036200
let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
6204-
let logger = test_utils::TestLogger::new();
62056201

62066202
// Marshall an MPP route.
6207-
let (_, payment_hash, _) = get_payment_preimage_hash!(&nodes[3]);
6208-
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
6209-
let mut route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[3].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &[], 100000, TEST_FINAL_CLTV, &logger).unwrap();
6203+
let (mut route, payment_hash, _, _) = get_route_and_payment_hash!(&nodes[0], nodes[3], 100000);
62106204
let path = route.paths[0].clone();
62116205
route.paths.push(path);
62126206
route.paths[0][0].pubkey = nodes[1].node.get_our_node_id();

lightning/src/ln/functional_test_utils.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,17 @@ macro_rules! commitment_signed_dance {
972972
#[macro_export]
973973
macro_rules! get_payment_preimage_hash {
974974
($dest_node: expr) => {
975+
{
976+
get_payment_preimage_hash!($dest_node, None)
977+
}
978+
};
979+
($dest_node: expr, $min_value_msat: expr) => {
975980
{
976981
let mut payment_count = $dest_node.network_payment_count.borrow_mut();
977982
let payment_preimage = PaymentPreimage([*payment_count; 32]);
978983
*payment_count += 1;
979984
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner());
980-
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, None, 7200, 0).unwrap();
985+
let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, 0).unwrap();
981986
(payment_preimage, payment_hash, payment_secret)
982987
}
983988
}
@@ -986,13 +991,17 @@ macro_rules! get_payment_preimage_hash {
986991
#[cfg(test)]
987992
macro_rules! get_route_and_payment_hash {
988993
($send_node: expr, $recv_node: expr, $recv_value: expr) => {{
989-
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node);
994+
get_route_and_payment_hash!($send_node, $recv_node, vec![], $recv_value, TEST_FINAL_CLTV)
995+
}};
996+
($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{
997+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node, Some($recv_value));
990998
let net_graph_msg_handler = &$send_node.net_graph_msg_handler;
991-
let route = get_route(&$send_node.node.get_our_node_id(),
992-
&net_graph_msg_handler.network_graph,
993-
&$recv_node.node.get_our_node_id(), None,
994-
Some(&$send_node.node.list_usable_channels().iter().map(|a| a).collect::<Vec<_>>()),
995-
&Vec::new(), $recv_value, TEST_FINAL_CLTV, $send_node.logger).unwrap();
999+
let route = ::routing::router::get_route(
1000+
&$send_node.node.get_our_node_id(), &net_graph_msg_handler.network_graph,
1001+
&$recv_node.node.get_our_node_id(), Some(::ln::features::InvoiceFeatures::known()),
1002+
Some(&$send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
1003+
&$last_hops, $recv_value, $cltv, $send_node.logger
1004+
).unwrap();
9961005
(route, payment_hash, payment_preimage, payment_secret)
9971006
}}
9981007
}

0 commit comments

Comments
 (0)