X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=6b4d2acd4d993263674d0f987a6b53bf62276609;hb=37c431ad687e338bdef2248a746c41eb013b3573;hp=ee09119b9e6c56dfcf6c1ccc61aca506e7ea4ccf;hpb=ae0d825d89ca0ac2489737d1b413e778650b093c;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index ee09119b..6b4d2acd 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -13,6 +13,7 @@ use crate::chain; use crate::chain::WatchedOutput; use crate::chain::chaininterface; use crate::chain::chaininterface::ConfirmationTarget; +#[cfg(test)] use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW; use crate::chain::chainmonitor; use crate::chain::chainmonitor::{MonitorUpdateId, UpdateOrigin}; @@ -23,8 +24,9 @@ use crate::routing::router::{CandidateRouteHop, FirstHopCandidate, PublicHopCand use crate::sign; use crate::events; use crate::events::bump_transaction::{WalletSource, Utxo}; -use crate::ln::ChannelId; +use crate::ln::types::ChannelId; use crate::ln::channelmanager::{ChannelDetails, self}; +#[cfg(test)] use crate::ln::chan_utils::CommitmentTransaction; use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use crate::ln::{msgs, wire}; @@ -396,12 +398,14 @@ impl<'a> chain::Watch for TestChainMonitor<'a> { } } +#[cfg(test)] struct JusticeTxData { justice_tx: Transaction, value: u64, commitment_number: u64, } +#[cfg(test)] pub(crate) struct WatchtowerPersister { persister: TestPersister, /// Upon a new commitment_signed, we'll get a @@ -415,6 +419,7 @@ pub(crate) struct WatchtowerPersister { destination_script: ScriptBuf, } +#[cfg(test)] impl WatchtowerPersister { #[cfg(test)] pub(crate) fn new(destination_script: ScriptBuf) -> Self { @@ -445,6 +450,7 @@ impl WatchtowerPersister { } } +#[cfg(test)] impl chainmonitor::Persist for WatchtowerPersister { fn persist_new_channel(&self, funding_txo: OutPoint, data: &channelmonitor::ChannelMonitor, id: MonitorUpdateId @@ -498,6 +504,10 @@ impl chainmonitor::Persist>::archive_persisted_channel(&self.persister, funding_txo); + } } pub struct TestPersister { @@ -546,6 +556,18 @@ impl chainmonitor::Persist {}, + None => { + // If the channel was not in the offchain_monitor_updates map, it should be in the + // chain_sync_monitor_persistences map. + assert!(self.chain_sync_monitor_persistences.lock().unwrap().remove(&funding_txo).is_some()); + } + }; + } } pub struct TestStore { @@ -762,12 +784,15 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { fn handle_stfu(&self, _their_node_id: &PublicKey, msg: &msgs::Stfu) { self.received_msg(wire::Message::Stfu(msg.clone())); } + #[cfg(splicing)] fn handle_splice(&self, _their_node_id: &PublicKey, msg: &msgs::Splice) { self.received_msg(wire::Message::Splice(msg.clone())); } + #[cfg(splicing)] fn handle_splice_ack(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceAck) { self.received_msg(wire::Message::SpliceAck(msg.clone())); } + #[cfg(splicing)] fn handle_splice_locked(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceLocked) { self.received_msg(wire::Message::SpliceLocked(msg.clone())); } @@ -1357,6 +1382,10 @@ impl TestChainSource { watched_outputs: Mutex::new(new_hash_set()), } } + pub fn remove_watched_txn_and_outputs(&self, outpoint: OutPoint, script_pubkey: ScriptBuf) { + self.watched_outputs.lock().unwrap().remove(&(outpoint, script_pubkey.clone())); + self.watched_txn.lock().unwrap().remove(&(outpoint.txid, script_pubkey)); + } } impl UtxoLookup for TestChainSource {