From 5849f4b547ae617d2eafcb719c8d93abf3732b9b Mon Sep 17 00:00:00 2001 From: Devrandom Date: Sun, 29 Dec 2024 13:21:57 +0100 Subject: [PATCH] run externalized tests in CI --- ci/ci-tests.sh | 7 +++++ ext-functional-test-demo/Cargo.toml | 3 +++ ext-functional-test-demo/src/main.rs | 40 ++++++++++++++++++++++++---- lightning/src/ln/channelmanager.rs | 2 +- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/ci/ci-tests.sh b/ci/ci-tests.sh index fdc2634f52d..90283993a08 100755 --- a/ci/ci-tests.sh +++ b/ci/ci-tests.sh @@ -142,6 +142,13 @@ RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose # check that compile with no_std and serde works in lightning-invoice cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde +echo -e "\n\nRunning externalized integration tests" +pushd ext-functional-test-demo +cargo test --verbose --color always +cargo test --verbose --color always --features test-broken +[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean +popd + echo -e "\n\nTesting no_std build on a downstream no-std crate" # check no-std compatibility across dependencies pushd no-std-check diff --git a/ext-functional-test-demo/Cargo.toml b/ext-functional-test-demo/Cargo.toml index f86c78bd839..19a41f7fef9 100644 --- a/ext-functional-test-demo/Cargo.toml +++ b/ext-functional-test-demo/Cargo.toml @@ -3,5 +3,8 @@ name = "ext-functional-tester" version = "0.1.0" edition = "2021" +[features] +test-broken = [] + [dependencies] lightning = { path = "../lightning", features = ["_test_utils"] } diff --git a/ext-functional-test-demo/src/main.rs b/ext-functional-test-demo/src/main.rs index 4636e115015..943bacf85d4 100644 --- a/ext-functional-test-demo/src/main.rs +++ b/ext-functional-test-demo/src/main.rs @@ -3,7 +3,9 @@ fn main() { } #[cfg(test)] +#[allow(unused)] mod tests { + use lightning::ln::functional_tests::*; use lightning::util::dyn_signer::{DynKeysInterfaceTrait, DynSigner}; use lightning::util::test_utils::{TestSignerFactory, SIGNER_FACTORY}; use std::panic::catch_unwind; @@ -20,12 +22,40 @@ mod tests { } } + #[cfg(feature = "test-broken")] #[test] - fn test_functional() { - lightning::ln::functional_tests::test_insane_channel_opens(); - lightning::ln::functional_tests::fake_network_test(); - + fn test_broken() { SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory())); - catch_unwind(|| lightning::ln::functional_tests::fake_network_test()).unwrap_err(); + catch_unwind(|| fake_network_test()).unwrap_err(); + } + + #[cfg(not(feature = "test-broken"))] + #[test] + fn test_default_one() { + test_htlc_on_chain_success(); + } + + #[cfg(not(feature = "test-broken"))] + #[test] + fn test_default_all() { + let mut failed_tests = Vec::new(); + for test in lightning::get_xtests() { + print!("Running test: {}", test.test_name); + let mut pass = catch_unwind(|| (test.test_fn)()).is_ok(); + if test.should_panic { + pass = !pass; + } + if !pass { + failed_tests.push(test.test_name); + } + } + if !failed_tests.is_empty() { + println!("Failed tests:"); + for test in failed_tests.iter() { + println!("- {}", test); + } + } + println!("Done with {} failures", failed_tests.len()); + assert!(failed_tests.is_empty()); } } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ab860a8173c..1a6f81b6e49 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -11041,7 +11041,7 @@ where // Most of our tests were written when we only broadcasted // `channel_announcement`s once and then never re-broadcasted // them again, so disable the re-broadcasting entirely in tests - #[cfg(test)] + #[cfg(any(test, feature = "_test_utils"))] { should_announce = announcement_sigs.is_some(); }