Skip to content

Commit e41e756

Browse files
committed
Expose functional tests under _externalize_tests feature flag
Also, introduce TestSignerFactory, a factory for dynamic signers and ext-functional-test-demo crate for testing this machinery.
1 parent 17cd6e3 commit e41e756

32 files changed

+559
-490
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ lightning-rapid-gossip-sync/res/full_graph.lngossip
1313
lightning-custom-message/target
1414
lightning-transaction-sync/target
1515
lightning-dns-resolver/target
16+
ext-functional-test-demo/target
1617
no-std-check/target
1718
msrv-no-dev-deps-check/target

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ members = [
2121

2222
exclude = [
2323
"lightning-transaction-sync",
24+
"ext-functional-test-demo",
2425
"no-std-check",
2526
"msrv-no-dev-deps-check",
2627
"bench",

ci/ci-tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ cargo check --verbose --color always
112112
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
113113
popd
114114

115+
echo -e "\n\Running functional tests from outside the workspace"
116+
pushd ext-functional-test-demo
117+
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
118+
cargo test --color always
119+
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
120+
popd
121+
115122
# Test that we can build downstream code with only the "release pins".
116123
pushd msrv-no-dev-deps-check
117124
PIN_RELEASE_DEPS

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 = ["_externalize_tests"] }

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!("{} tests were exported", lightning::get_xtests().len());
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+
}

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ use bitcoin::secp256k1::schnorr;
7979
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
8080

8181
use lightning::io::Cursor;
82+
use lightning::util::dyn_signer::DynSigner;
8283
use std::cmp::{self, Ordering};
8384
use std::mem;
8485
use std::sync::atomic;
@@ -375,6 +376,7 @@ impl SignerProvider for KeyProvider {
375376
channel_keys_id,
376377
);
377378
let revoked_commitment = self.make_enforcement_state_cell(keys.commitment_seed);
379+
let keys = DynSigner::new(keys);
378380
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false)
379381
}
380382

fuzz/src/full_stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
7575
use bitcoin::secp256k1::schnorr;
7676
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
7777

78+
use lightning::util::dyn_signer::DynSigner;
7879
use std::cell::RefCell;
7980
use std::cmp;
8081
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
@@ -439,7 +440,7 @@ impl SignerProvider for KeyProvider {
439440
let ctr = channel_keys_id[0];
440441
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
441442
TestChannelSigner::new_with_revoked(
442-
if inbound {
443+
DynSigner::new(if inbound {
443444
InMemorySigner::new(
444445
&secp_ctx,
445446
SecretKey::from_slice(&[
@@ -509,7 +510,7 @@ impl SignerProvider for KeyProvider {
509510
channel_keys_id,
510511
channel_keys_id,
511512
)
512-
},
513+
}),
513514
state,
514515
false,
515516
)

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,8 @@ mod tests {
25502550
failure: PathFailure::OnPath { network_update: None },
25512551
path: path.clone(),
25522552
short_channel_id: Some(scored_scid),
2553+
error_code: None,
2554+
error_data: None,
25532555
});
25542556
let event = $receive.expect("PaymentPathFailed not handled within deadline");
25552557
match event {
@@ -2567,6 +2569,8 @@ mod tests {
25672569
failure: PathFailure::OnPath { network_update: None },
25682570
path: path.clone(),
25692571
short_channel_id: None,
2572+
error_code: None,
2573+
error_data: None,
25702574
});
25712575
let event = $receive.expect("PaymentPathFailed not handled within deadline");
25722576
match event {

lightning-macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn drop_legacy_field_definition(expr: TokenStream) -> TokenStream {
306306
///
307307
/// fn f1() {}
308308
///
309-
/// #[xtest(feature = "_test_utils")]
309+
/// #[xtest(feature = "_externalize_tests")]
310310
/// pub fn test_f1() {
311311
/// f1();
312312
/// }

lightning/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1818
[features]
1919
# Internal test utilities exposed to other repo crates
2020
_test_utils = ["regex", "bitcoin/bitcoinconsensus", "lightning-types/_test_utils"]
21-
21+
_externalize_tests = ["inventory", "_test_utils"]
2222
# Allow signing of local transactions that may have been revoked or will be revoked, for functional testing (e.g. justice tx handling).
2323
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
2424
unsafe_revoked_tx_signing = []
@@ -48,10 +48,12 @@ regex = { version = "1.5.6", optional = true }
4848
backtrace = { version = "0.3", optional = true }
4949

5050
libm = { version = "0.2", default-features = false }
51+
inventory = { version = "0.3", optional = true }
5152

5253
[dev-dependencies]
5354
regex = "1.5.6"
5455
lightning-types = { version = "0.3.0", path = "../lightning-types", features = ["_test_utils"] }
56+
lightning-macros = { path = "../lightning-macros" }
5557

5658
[dev-dependencies.bitcoin]
5759
version = "0.32.2"

0 commit comments

Comments
 (0)