-
Notifications
You must be signed in to change notification settings - Fork 339
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
12
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 }}
Could not load tags
Nothing to show
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac2eae7
fix non-local macro in doctest
devrandom 2c7c4b8
fix check-cfg-flags.py
devrandom 8764062
externally visible test macro
devrandom e19a406
mut-global utility
devrandom 37c040d
introduce DynSigner and TestSignerFactory
devrandom 6e074ee
taproot
devrandom 8eb8b4d
expose one functional test
devrandom 3805ac1
demo two exposed functional tests
devrandom ef8f13d
expose rest of functional tests
devrandom affc49e
f mut_global
devrandom c6114cc
f fuzz DynSigner
devrandom 445e611
f invoice
devrandom File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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,7 @@ | ||
[package] | ||
name = "ext-functional-tester" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[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,31 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} | ||
|
||
#[cfg(test)] | ||
mod 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!() | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_functional() { | ||
lightning::ln::functional_tests::test_insane_channel_opens(); | ||
lightning::ln::functional_tests::fake_network_test(); | ||
|
||
SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory())); | ||
catch_unwind(|| lightning::ln::functional_tests::fake_network_test()).unwrap_err(); | ||
} | ||
} |
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,14 @@ | ||
[package] | ||
name = "ext-test-macro" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
syn = { version = "1.0", features = ["full"] } | ||
quote = "1.0" | ||
proc-macro2 = "1.0" |
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,73 @@ | ||
use proc_macro::TokenStream; | ||
use proc_macro2::TokenStream as TokenStream2; | ||
use quote::quote; | ||
use syn::{parse2, ItemFn, ItemMod}; | ||
|
||
/// An exposed test. This is a test that will run locally and also be | ||
/// made available to other crates that want to run it in their own context. | ||
/// | ||
/// For example: | ||
/// ```rust | ||
/// use ext_test_macro::xtest; | ||
/// | ||
/// fn f1() {} | ||
/// | ||
/// #[xtest(feature = "_test_utils")] | ||
/// pub fn test_f1() { | ||
/// f1(); | ||
/// } | ||
/// ``` | ||
/// | ||
/// May also be applied to modules, like so: | ||
/// | ||
/// ```rust | ||
/// use ext_test_macro::xtest; | ||
/// | ||
/// #[xtest(feature = "_test_utils")] | ||
/// pub mod tests { | ||
/// use super::*; | ||
/// | ||
/// fn f1() {} | ||
/// | ||
/// #[xtest] | ||
/// pub fn test_f1() { | ||
/// f1(); | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// Which will include the module if we are testing or the `externalize-the-tests` feature | ||
/// is on. | ||
#[proc_macro_attribute] | ||
pub fn xtest(attrs: TokenStream, item: TokenStream) -> TokenStream { | ||
let input = syn::parse_macro_input!(item as TokenStream2); | ||
let attrs = syn::parse_macro_input!(attrs as TokenStream2); | ||
|
||
let expanded = if is_module_definition(input.clone()) { | ||
let cfg = if attrs.is_empty() { | ||
quote! { #[cfg(test)] } | ||
} else { | ||
quote! { #[cfg(any(test, #attrs))] } | ||
}; | ||
quote! { | ||
#cfg | ||
#input | ||
} | ||
} else if is_function_definition(input.clone()) { | ||
quote! { | ||
#[cfg_attr(test, ::core::prelude::v1::test)] | ||
#input | ||
} | ||
} else { | ||
panic!("xtest can only be applied to functions or modules"); | ||
}; | ||
expanded.into() | ||
} | ||
|
||
fn is_module_definition(input: TokenStream2) -> bool { | ||
parse2::<ItemMod>(input).is_ok() | ||
} | ||
|
||
fn is_function_definition(input: TokenStream2) -> bool { | ||
parse2::<ItemFn>(input).is_ok() | ||
} |
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.
I wonder if we should call this more generally
ldk-macros
? Currently, we usebdk-macros
to provide a dual blocking/async interface inlightning-transaction-sync
. However, thebdk-macros
crate is basically going away with BDK 1.0, so we might want to include the corresponding functionality here?(cc @TheBlueMatt)