Skip to content

Commit 6b7a3d8

Browse files
Put test utilities behind a feature flag.
The utilities will still be part of cfg(test). The purpose of this is to enable other crates in the workspace to use the test utilities.
1 parent b7c308b commit 6b7a3d8

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

lightning/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Still missing tons of error-handling. See GitHub issues for suggested projects i
1212

1313
[features]
1414
fuzztarget = ["bitcoin/fuzztarget"]
15+
_test-utils = ["hex", "regex"]
1516
# Unlog messages superior at targeted level.
1617
max_level_off = []
1718
max_level_error = []
@@ -25,6 +26,9 @@ unsafe_revoked_tx_signing = []
2526
[dependencies]
2627
bitcoin = "0.23"
2728

29+
hex = { version = "0.3", optional = true }
30+
regex = { version = "0.1.80", optional = true }
31+
2832
[dev-dependencies.bitcoin]
2933
version = "0.23"
3034
features = ["bitcoinconsensus"]

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use std::io::Error;
6161

6262
/// An update generated by the underlying Channel itself which contains some new information the
6363
/// ChannelMonitor should be made aware of.
64-
#[cfg_attr(test, derive(PartialEq))]
64+
#[cfg_attr(any(test, feature = "_test-utils"), derive(PartialEq))]
6565
#[derive(Clone)]
6666
#[must_use]
6767
pub struct ChannelMonitorUpdate {
@@ -635,7 +635,7 @@ enum OnchainEvent {
635635
const SERIALIZATION_VERSION: u8 = 1;
636636
const MIN_SERIALIZATION_VERSION: u8 = 1;
637637

638-
#[cfg_attr(test, derive(PartialEq))]
638+
#[cfg_attr(any(test, feature = "_test-utils"), derive(PartialEq))]
639639
#[derive(Clone)]
640640
pub(crate) enum ChannelMonitorUpdateStep {
641641
LatestLocalCommitmentTXInfo {
@@ -857,7 +857,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
857857
secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
858858
}
859859

860-
#[cfg(any(test, feature = "fuzztarget"))]
860+
#[cfg(any(test, feature = "fuzztarget", feature = "_test-utils"))]
861861
/// Used only in testing and fuzztarget to check serialization roundtrips don't change the
862862
/// underlying object
863863
impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {

lightning/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! generated/etc. This makes it a good candidate for tight integration into an existing wallet
1919
//! instead of having a rather-separate lightning appendage to a wallet.
2020
21-
#![cfg_attr(not(feature = "fuzztarget"), deny(missing_docs))]
21+
#![cfg_attr(not(any(feature = "fuzztarget", feature = "_test-utils")), deny(missing_docs))]
2222
#![forbid(unsafe_code)]
2323

2424
// In general, rust is absolutely horrid at supporting users doing things like,
@@ -28,8 +28,8 @@
2828
#![allow(ellipsis_inclusive_range_patterns)]
2929

3030
extern crate bitcoin;
31-
#[cfg(test)] extern crate hex;
32-
#[cfg(test)] extern crate regex;
31+
#[cfg(any(test, feature = "_test-utils"))] extern crate hex;
32+
#[cfg(any(test, feature = "_test-utils"))] extern crate regex;
3333

3434
#[macro_use]
3535
pub mod util;

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
403403
last_block_hash: Mutex<BlockHash>,
404404
secp_ctx: Secp256k1<secp256k1::All>,
405405

406-
#[cfg(test)]
406+
#[cfg(any(test, feature = "_test-utils"))]
407407
pub(super) channel_state: Mutex<ChannelHolder<ChanSigner>>,
408-
#[cfg(not(test))]
408+
#[cfg(not(any(test, feature = "_test-utils")))]
409409
channel_state: Mutex<ChannelHolder<ChanSigner>>,
410410
our_network_key: SecretKey,
411411

lightning/src/ln/functional_test_utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ macro_rules! get_event_msg {
261261
}
262262
}
263263

264+
#[allow(unused_macros)]
264265
macro_rules! get_htlc_update_msgs {
265266
($node: expr, $node_id: expr) => {
266267
{
@@ -277,6 +278,7 @@ macro_rules! get_htlc_update_msgs {
277278
}
278279
}
279280

281+
#[allow(unused_macros)]
280282
macro_rules! get_feerate {
281283
($node: expr, $channel_id: expr) => {
282284
{
@@ -287,6 +289,7 @@ macro_rules! get_feerate {
287289
}
288290
}
289291

292+
#[allow(unused_macros)]
290293
macro_rules! get_local_commitment_txn {
291294
($node: expr, $channel_id: expr) => {
292295
{
@@ -325,6 +328,7 @@ macro_rules! unwrap_send_err {
325328
}
326329
}
327330

331+
#[macro_export]
328332
macro_rules! check_added_monitors {
329333
($node: expr, $count: expr) => {
330334
{
@@ -539,6 +543,7 @@ macro_rules! get_closing_signed_broadcast {
539543
}
540544
}
541545

546+
#[macro_export]
542547
macro_rules! check_closed_broadcast {
543548
($node: expr, $with_error_msg: expr) => {{
544549
let events = $node.node.get_and_clear_pending_msg_events();
@@ -765,6 +770,7 @@ macro_rules! expect_pending_htlcs_forwardable {
765770
}}
766771
}
767772

773+
#[allow(unused_macros)]
768774
macro_rules! expect_payment_received {
769775
($node: expr, $expected_payment_hash: expr, $expected_recv_value: expr) => {
770776
let events = $node.node.get_and_clear_pending_events();
@@ -793,6 +799,7 @@ macro_rules! expect_payment_sent {
793799
}
794800
}
795801

802+
#[allow(unused_macros)]
796803
macro_rules! expect_payment_failed {
797804
($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
798805
let events = $node.node.get_and_clear_pending_events();
@@ -1270,6 +1277,7 @@ pub fn get_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec<Node<'a, 'b,
12701277
}
12711278
}
12721279

1280+
#[allow(unused_macros)]
12731281
macro_rules! get_channel_value_stat {
12741282
($node: expr, $channel_id: expr) => {{
12751283
let chan_lock = $node.node.channel_state.lock().unwrap();

lightning/src/ln/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ mod channel;
3434
mod onion_utils;
3535
mod wire;
3636

37-
#[cfg(test)]
37+
#[cfg(any(test, feature = "_test-utils"))]
3838
#[macro_use]
39-
pub(crate) mod functional_test_utils;
39+
pub mod functional_test_utils;
4040
#[cfg(test)]
4141
mod functional_tests;
4242
#[cfg(test)]

lightning/src/util/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub(crate) mod macro_logger;
3232
pub mod logger;
3333
pub mod config;
3434

35-
#[cfg(test)]
36-
pub(crate) mod test_utils;
35+
#[cfg(any(test, feature = "_test-utils"))]
36+
pub mod test_utils;
3737

3838
/// impls of traits that add exra enforcement on the way they're called. Useful for detecting state
3939
/// machine errors and used in fuzz targets and tests.
40-
#[cfg(any(test, feature = "fuzztarget"))]
40+
#[cfg(any(test, feature = "fuzztarget", feature = "_test-utils"))]
4141
pub mod enforcing_trait_impls;

0 commit comments

Comments
 (0)