-
Notifications
You must be signed in to change notification settings - Fork 377
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
allow functional tests to be used externally with a dynamic signer factory #3016
Open
devrandom
wants to merge
5
commits into
lightningdevkit:main
Choose a base branch
from
lightning-signer:2024-04-ext-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,441
−548
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
229d350
macro for externally-visible tests
devrandom 306ef04
mut-global utility
devrandom 4f05039
introduce DynSigner
devrandom 8e51713
expose functional tests under _test_utils feature flag
devrandom 14c854d
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 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 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 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 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 = ["_test_utils"] } |
This file contains 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 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 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 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 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much work would it be to just NIH this? Can we just have some global static
Vec
listing function pointers and names?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue is that you can't call non-const functions before
main()
, so it seems like you need to jump through the linker hacksinventory
is doing. and those hacks are target specific, so it wouldn't make a lot of sense to maintain them ourselves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a different approach would be to only inventory at the module level, requiring the
mod
to have anxtest
macro on it. then the inventorying can happen inside themod
macro invocation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure I understand what the approach is that you're suggesting, but...sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it's not possible to incrementally add to a global variable without
inventory
, I'm suggesting that tests are grouped into:and then the module level macro invocation will collect the tests inside the module in one swoop instead of incrementally.
This will require another level of
mod
inside the existing functional test mods. and it will also require adding a level of indent to a couple of thousand lines or so. Is that OK?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, duh. I mean in principle we could even wrap the entire crate/top-level module in an
#[xtest]
no? We could also just do it on thefuntional_tests
/etc modules directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has to be a single compilation unit. macros can't iterate on functions that are in another compilation unit, because they are not in the AST when the macro is invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, damn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what's the verdict?
inventory
ormod
+indent everything?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the current inventory-based code, I think.