-
Notifications
You must be signed in to change notification settings - Fork 412
allow functional tests to be used externally with a dynamic signer factory #3016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheBlueMatt
merged 5 commits into
lightningdevkit:main
from
lightning-signer:2024-04-ext-test
Mar 4, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adf2f68
Introduce xtest macro for externally-visible tests
devrandom 60222d0
Add a MutGlobal utility
devrandom 17cd6e3
Introduce DynSigner, a dynamically dispatched signer
devrandom e41e756
Expose functional tests under _externalize_tests feature flag
devrandom 9d8a91a
Run externalized tests in CI
devrandom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "ext-functional-tester" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[features] | ||
test-broken = [] | ||
|
||
[dependencies] | ||
lightning = { path = "../lightning", features = ["_externalize_tests"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
fn main() { | ||
println!("{} tests were exported", lightning::get_xtests().len()); | ||
} | ||
|
||
#[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; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
struct BrokenSignerFactory(); | ||
|
||
impl TestSignerFactory for BrokenSignerFactory { | ||
fn make_signer( | ||
&self, _seed: &[u8; 32], _now: Duration, | ||
) -> Box<dyn DynKeysInterfaceTrait<EcdsaSigner = DynSigner>> { | ||
panic!() | ||
} | ||
} | ||
|
||
#[cfg(feature = "test-broken")] | ||
#[test] | ||
fn test_broken() { | ||
SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory())); | ||
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()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.