Skip to content

Commit 87aadef

Browse files
committed
demo two exposed functional tests
1 parent 15e7493 commit 87aadef

21 files changed

+131
-96
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"lightning-transaction-sync",
1414
"possiblyrandom",
1515
"ext-test-macro",
16+
"ext-functional-test-demo",
1617
]
1718

1819
exclude = [

ext-functional-test-demo/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "ext-functional-tester"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
lightning = { path = "../lightning", features = ["_test_utils"] }

ext-functional-test-demo/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use lightning::util::dyn_signer::{DynKeysInterfaceTrait, DynSigner};
8+
use lightning::util::test_utils::{TestSignerFactory, SIGNER_FACTORY};
9+
use std::panic::catch_unwind;
10+
use std::sync::Arc;
11+
use std::time::Duration;
12+
13+
struct BrokenSignerFactory();
14+
15+
impl TestSignerFactory for BrokenSignerFactory {
16+
fn make_signer(
17+
&self, _seed: &[u8; 32], _now: Duration,
18+
) -> Box<dyn DynKeysInterfaceTrait<EcdsaSigner = DynSigner>> {
19+
panic!()
20+
}
21+
}
22+
23+
#[test]
24+
fn test_functional() {
25+
lightning::ln::functional_tests::test_insane_channel_opens();
26+
lightning::ln::functional_tests::fake_network_test();
27+
28+
SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory()));
29+
catch_unwind(|| lightning::ln::functional_tests::fake_network_test()).unwrap_err();
30+
}
31+
}

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,8 @@ mod tests {
19181918
failure: PathFailure::OnPath { network_update: None },
19191919
path: path.clone(),
19201920
short_channel_id: Some(scored_scid),
1921+
error_code: None,
1922+
error_data: None,
19211923
});
19221924
let event = $receive.expect("PaymentPathFailed not handled within deadline");
19231925
match event {
@@ -1935,6 +1937,8 @@ mod tests {
19351937
failure: PathFailure::OnPath { network_update: None },
19361938
path: path.clone(),
19371939
short_channel_id: None,
1940+
error_code: None,
1941+
error_data: None,
19381942
});
19391943
let event = $receive.expect("PaymentPathFailed not handled within deadline");
19401944
match event {

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
16281628
/// Unsafe test-only version of `broadcast_latest_holder_commitment_txn` used by our test framework
16291629
/// to bypass HolderCommitmentTransaction state update lockdown after signature and generate
16301630
/// revoked commitment transaction.
1631-
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
1631+
#[cfg(any(test, feature = "_test_utils", feature = "unsafe_revoked_tx_signing"))]
16321632
pub fn unsafe_get_latest_holder_commitment_txn<L: Deref>(&self, logger: &L) -> Vec<Transaction>
16331633
where L::Target: Logger {
16341634
let mut inner = self.inner.lock().unwrap();
@@ -1917,7 +1917,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
19171917
self.inner.lock().unwrap().counterparty_payment_script = script;
19181918
}
19191919

1920-
#[cfg(test)]
1920+
#[cfg(any(test, feature = "_test_utils"))]
19211921
pub fn do_signer_call<F: FnMut(&Signer) -> ()>(&self, mut f: F) {
19221922
let inner = self.inner.lock().unwrap();
19231923
f(&inner.onchain_tx_handler.signer);
@@ -3621,7 +3621,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36213621
}
36223622
}
36233623

3624-
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
3624+
#[cfg(any(test, feature = "_test_utils", feature = "unsafe_revoked_tx_signing"))]
36253625
/// Note that this includes possibly-locktimed-in-the-future transactions!
36263626
fn unsafe_get_latest_holder_commitment_txn<L: Deref>(
36273627
&mut self, logger: &WithChannelMonitor<L>

lightning/src/chain/onchaintx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11641164
MaybeSignedTransaction(tx)
11651165
}
11661166

1167-
#[cfg(any(test, feature="unsafe_revoked_tx_signing"))]
1167+
#[cfg(any(test, feature="_test_utils", feature="unsafe_revoked_tx_signing"))]
11681168
pub(crate) fn get_fully_signed_copy_holder_tx(&mut self, funding_redeemscript: &Script) -> Transaction {
11691169
let sig = self.signer.unsafe_sign_holder_commitment(&self.holder_commitment, &self.secp_ctx).expect("sign holder commitment");
11701170
self.holder_commitment.add_holder_sig(funding_redeemscript, sig)

lightning/src/events/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ pub enum Event {
803803
/// If this is `Some`, then the corresponding channel should be avoided when the payment is
804804
/// retried. May be `None` for older [`Event`] serializations.
805805
short_channel_id: Option<u64>,
806-
#[cfg(test)]
806+
#[cfg(any(test, feature = "_test_utils"))]
807807
error_code: Option<u16>,
808-
#[cfg(test)]
808+
#[cfg(any(test, feature = "_test_utils"))]
809809
error_data: Option<Vec<u8>>,
810810
},
811811
/// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
@@ -1213,9 +1213,9 @@ impl Writeable for Event {
12131213
&Event::PaymentPathFailed {
12141214
ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure,
12151215
ref path, ref short_channel_id,
1216-
#[cfg(test)]
1216+
#[cfg(any(test, feature = "_test_utils"))]
12171217
ref error_code,
1218-
#[cfg(test)]
1218+
#[cfg(any(test, feature = "_test_utils"))]
12191219
ref error_data,
12201220
} => {
12211221
3u8.write(writer)?;
@@ -1489,10 +1489,12 @@ impl MaybeReadable for Event {
14891489
},
14901490
3u8 => {
14911491
let mut f = || {
1492-
#[cfg(test)]
1493-
let error_code = Readable::read(reader)?;
1494-
#[cfg(test)]
1495-
let error_data = Readable::read(reader)?;
1492+
#[cfg(any(test, feature = "_test_utils"))]
1493+
1494+
let error_code = Readable::read(reader)?;
1495+
#[cfg(any(test, feature = "_test_utils"))]
1496+
1497+
let error_data = Readable::read(reader)?;
14961498
let mut payment_hash = PaymentHash([0; 32]);
14971499
let mut payment_failed_permanently = false;
14981500
let mut network_update = None;
@@ -1521,9 +1523,11 @@ impl MaybeReadable for Event {
15211523
failure,
15221524
path: Path { hops: path.unwrap(), blinded_tail },
15231525
short_channel_id,
1524-
#[cfg(test)]
1526+
#[cfg(any(test, feature = "_test_utils"))]
1527+
15251528
error_code,
1526-
#[cfg(test)]
1529+
#[cfg(any(test, feature = "_test_utils"))]
1530+
15271531
error_data,
15281532
}))
15291533
};

lightning/src/ln/channel.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,6 @@ pub(crate) fn commitment_tx_base_weight(channel_type_features: &ChannelTypeFeatu
847847
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { COMMITMENT_TX_BASE_ANCHOR_WEIGHT } else { COMMITMENT_TX_BASE_WEIGHT }
848848
}
849849

850-
#[cfg(not(test))]
851-
const COMMITMENT_TX_WEIGHT_PER_HTLC: u64 = 172;
852-
#[cfg(test)]
853850
pub const COMMITMENT_TX_WEIGHT_PER_HTLC: u64 = 172;
854851

855852
pub const ANCHOR_OUTPUT_VALUE_SATOSHI: u64 = 330;
@@ -1125,10 +1122,7 @@ pub(crate) struct ShutdownResult {
11251122
/// the channel. Sadly, there isn't really a good number for this - if we expect to have no new
11261123
/// HTLCs for days we may need this to suffice for feerate increases across days, but that may
11271124
/// leave the channel less usable as we hold a bigger reserve.
1128-
#[cfg(any(fuzzing, test))]
11291125
pub const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE: u64 = 2;
1130-
#[cfg(not(any(fuzzing, test)))]
1131-
const FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE: u64 = 2;
11321126

11331127
/// If we fail to see a funding transaction confirmed on-chain within this many blocks after the
11341128
/// channel creation on an inbound channel, we simply force-close and move on.
@@ -1373,10 +1367,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13731367

13741368
/// The minimum and maximum absolute fee, in satoshis, we are willing to place on the closing
13751369
/// transaction. These are set once we reach `closing_negotiation_ready`.
1376-
#[cfg(test)]
13771370
pub(crate) closing_fee_limits: Option<(u64, u64)>,
1378-
#[cfg(not(test))]
1379-
closing_fee_limits: Option<(u64, u64)>,
13801371

13811372
/// If we remove an HTLC (or fee update), commit, and receive our counterparty's
13821373
/// `revoke_and_ack`, we remove all knowledge of said HTLC (or fee update). However, the latest
@@ -1402,35 +1393,20 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14021393

14031394
counterparty_dust_limit_satoshis: u64,
14041395

1405-
#[cfg(test)]
14061396
pub(super) holder_dust_limit_satoshis: u64,
1407-
#[cfg(not(test))]
1408-
holder_dust_limit_satoshis: u64,
14091397

1410-
#[cfg(test)]
14111398
pub(super) counterparty_max_htlc_value_in_flight_msat: u64,
1412-
#[cfg(not(test))]
1413-
counterparty_max_htlc_value_in_flight_msat: u64,
14141399

1415-
#[cfg(test)]
14161400
pub(super) holder_max_htlc_value_in_flight_msat: u64,
1417-
#[cfg(not(test))]
1418-
holder_max_htlc_value_in_flight_msat: u64,
14191401

14201402
/// minimum channel reserve for self to maintain - set by them.
14211403
counterparty_selected_channel_reserve_satoshis: Option<u64>,
14221404

1423-
#[cfg(test)]
14241405
pub(super) holder_selected_channel_reserve_satoshis: u64,
1425-
#[cfg(not(test))]
1426-
holder_selected_channel_reserve_satoshis: u64,
14271406

14281407
counterparty_htlc_minimum_msat: u64,
14291408
holder_htlc_minimum_msat: u64,
1430-
#[cfg(test)]
14311409
pub counterparty_max_accepted_htlcs: u16,
1432-
#[cfg(not(test))]
1433-
counterparty_max_accepted_htlcs: u16,
14341410
holder_max_accepted_htlcs: u16,
14351411
minimum_depth: Option<u32>,
14361412

@@ -1534,7 +1510,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15341510
/// The unique identifier used to re-derive the private key material for the channel through
15351511
/// [`SignerProvider::derive_channel_signer`].
15361512
#[cfg(not(test))]
1537-
channel_keys_id: [u8; 32],
1513+
pub(crate) channel_keys_id: [u8; 32],
15381514
#[cfg(test)]
15391515
pub channel_keys_id: [u8; 32],
15401516

@@ -2217,7 +2193,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22172193
}
22182194

22192195
/// Returns the holder signer for this channel.
2220-
#[cfg(test)]
2196+
#[cfg(any(test, feature = "_test_utils"))]
22212197
pub fn get_signer(&self) -> &ChannelSignerType<SP> {
22222198
return &self.holder_signer
22232199
}

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,7 +4082,8 @@ where
40824082
})
40834083
}
40844084

4085-
#[cfg(test)]
4085+
#[cfg(any(test, feature = "_test_utils"))]
4086+
40864087
pub(crate) fn test_send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
40874088
let _lck = self.total_consistency_lock.read().unwrap();
40884089
self.send_payment_along_path(SendAlongPathArgs {
@@ -4254,7 +4255,8 @@ where
42544255
&self.pending_events, |args| self.send_payment_along_path(args))
42554256
}
42564257

4257-
#[cfg(test)]
4258+
#[cfg(any(test, feature = "_test_utils"))]
4259+
42584260
pub(super) fn test_send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, keysend_preimage: Option<PaymentPreimage>, payment_id: PaymentId, recv_value_msat: Option<u64>, onion_session_privs: Vec<[u8; 32]>) -> Result<(), PaymentSendFailure> {
42594261
let best_block_height = self.best_block.read().unwrap().height;
42604262
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -4263,7 +4265,8 @@ where
42634265
best_block_height, |args| self.send_payment_along_path(args))
42644266
}
42654267

4266-
#[cfg(test)]
4268+
#[cfg(any(test, feature = "_test_utils"))]
4269+
42674270
pub(crate) fn test_add_new_pending_payment(&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route: &Route) -> Result<Vec<[u8; 32]>, PaymentSendFailure> {
42684271
let best_block_height = self.best_block.read().unwrap().height;
42694272
self.pending_outbound_payments.test_add_new_pending_payment(payment_hash, recipient_onion, payment_id, route, None, &self.entropy_source, best_block_height)

0 commit comments

Comments
 (0)