Skip to content

Commit

Permalink
run externalized tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Dec 29, 2024
1 parent f9ce0cc commit 5849f4b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ext-functional-test-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ name = "ext-functional-tester"
version = "0.1.0"
edition = "2021"

[features]
test-broken = []

[dependencies]
lightning = { path = "../lightning", features = ["_test_utils"] }
40 changes: 35 additions & 5 deletions ext-functional-test-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 5849f4b

Please sign in to comment.