Skip to content

Commit

Permalink
expose rest of functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Apr 26, 2024
1 parent 4d7a64c commit 4efd374
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 184 deletions.
2 changes: 1 addition & 1 deletion lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ where C::Target: chain::Filter,
}


#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub fn remove_monitor(&self, funding_txo: &OutPoint) -> ChannelMonitor<ChannelSigner> {
self.monitors.write().unwrap().remove(funding_txo).unwrap().monitor
}
Expand Down
11 changes: 4 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,7 @@ impl Readable for IrrevocablyResolvedHTLC {
/// returned block hash and the the current chain and then reconnecting blocks to get to the
/// best chain) upon deserializing the object!
pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
#[cfg(test)]
pub(crate) inner: Mutex<ChannelMonitorImpl<Signer>>,
#[cfg(not(test))]
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
}

impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
Expand Down Expand Up @@ -877,9 +874,9 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
// Obviously Correct (tm) if we just keep track of them explicitly.
outputs_to_watch: HashMap<Txid, Vec<(u32, ScriptBuf)>>,

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub onchain_tx_handler: OnchainTxHandler<Signer>,
#[cfg(not(test))]
#[cfg(not(any(test, feature = "_test_utils")))]
onchain_tx_handler: OnchainTxHandler<Signer>,

// This is set when the Channel[Manager] generated a ChannelMonitorUpdate which indicated the
Expand Down Expand Up @@ -2498,7 +2495,7 @@ macro_rules! fail_unbroadcast_htlcs {
// witness length match (ie is 136 bytes long). We generate one here which we also use in some
// in-line tests later.

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub fn deliberately_bogus_accepted_htlc_witness_program() -> Vec<u8> {
use bitcoin::blockdata::opcodes;
let mut ret = [opcodes::all::OP_NOP.to_u8(); 136];
Expand All @@ -2510,7 +2507,7 @@ pub fn deliberately_bogus_accepted_htlc_witness_program() -> Vec<u8> {
Vec::from(&ret[..])
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub fn deliberately_bogus_accepted_htlc_witness() -> Vec<Vec<u8>> {
vec![Vec::new(), Vec::new(), Vec::new(), Vec::new(), deliberately_bogus_accepted_htlc_witness_program().into()].into()
}
Expand Down
8 changes: 1 addition & 7 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,7 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
// Key is identifier of the pending claim request, i.e the txid of the initial claiming transaction generated by
// us and is immutable until all outpoint of the claimable set are post-anti-reorg-delay solved.
// Entry is cache of elements need to generate a bumped claiming transaction (see ClaimTxBumpMaterial)
#[cfg(test)] // Used in functional_test to verify sanitization
pub(crate) pending_claim_requests: HashMap<ClaimId, PackageTemplate>,
#[cfg(not(test))]
pending_claim_requests: HashMap<ClaimId, PackageTemplate>,

// Used to track external events that need to be forwarded to the `ChainMonitor`. This `Vec`
// essentially acts as an insertion-ordered `HashMap` – there should only ever be one occurrence
Expand All @@ -269,10 +266,7 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
// block height, and are immutable until the outpoint has enough confirmations to meet our
// [`ANTI_REORG_DELAY`]. The initial confirmation block height is used to remove the entry if
// the block gets disconnected.
#[cfg(test)] // Used in functional_test to verify sanitization
pub claimable_outpoints: HashMap<BitcoinOutPoint, (ClaimId, u32)>,
#[cfg(not(test))]
claimable_outpoints: HashMap<BitcoinOutPoint, (ClaimId, u32)>,
pub(crate) claimable_outpoints: HashMap<BitcoinOutPoint, (ClaimId, u32)>,

locktimed_packages: BTreeMap<u32, Vec<PackageTemplate>>,

Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::sign::type_resolver::ChannelSignerType;

use super::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub struct ChannelValueStat {
pub value_to_self_msat: u64,
pub channel_value_msat: u64,
Expand Down Expand Up @@ -6171,12 +6171,12 @@ impl<SP: Deref> Channel<SP> where
self.context.cur_counterparty_commitment_transaction_number + 2
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
&self.context.holder_signer
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub fn get_value_stat(&self) -> ChannelValueStat {
ChannelValueStat {
value_to_self_msat: self.context.value_to_self_msat,
Expand Down
8 changes: 1 addition & 7 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,10 +1889,7 @@ where
router: R,

/// See `ChannelManager` struct-level documentation for lock order requirements.
#[cfg(test)]
pub(super) best_block: RwLock<BestBlock>,
#[cfg(not(test))]
best_block: RwLock<BestBlock>,
secp_ctx: Secp256k1<secp256k1::All>,

/// Storage for PaymentSecrets and any requirements on future inbound payments before we will
Expand Down Expand Up @@ -1981,9 +1978,6 @@ where
/// required to access the channel with the `counterparty_node_id`.
///
/// See `ChannelManager` struct-level documentation for lock order requirements.
#[cfg(not(test))]
outpoint_to_peer: Mutex<HashMap<OutPoint, PublicKey>>,
#[cfg(test)]
pub(crate) outpoint_to_peer: Mutex<HashMap<OutPoint, PublicKey>>,

/// SCIDs (and outbound SCID aliases) -> `counterparty_node_id`s and `channel_id`s.
Expand Down Expand Up @@ -4567,7 +4561,7 @@ where
Ok(())
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> {
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, false, |_, tx| {
Ok(OutPoint { txid: tx.txid(), index: output_index })
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ impl<T: sealed::ShutdownAnySegwit> Features<T> {
}

impl<T: sealed::Wumbo> Features<T> {
#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
pub(crate) fn clear_wumbo(mut self) -> Self {
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
self
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ macro_rules! get_channel_ref {
}
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
macro_rules! get_feerate {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
Expand All @@ -949,7 +949,7 @@ macro_rules! get_feerate {
}
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
macro_rules! get_channel_type_features {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {
{
Expand Down Expand Up @@ -3473,7 +3473,7 @@ pub fn get_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec<Node<'a, 'b,
handle_announce_close_broadcast_events(nodes, a, b, false, "Channel closed because commitment or closing transaction was confirmed on chain.");
}

#[cfg(test)]
#[cfg(any(test, feature = "_test_utils"))]
macro_rules! get_channel_value_stat {
($node: expr, $counterparty_node: expr, $channel_id: expr) => {{
let peer_state_lock = $node.node.per_peer_state.read().unwrap();
Expand Down

0 comments on commit 4efd374

Please sign in to comment.