Skip to content

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
merged 5 commits into from
Mar 4, 2025

Conversation

devrandom
Copy link
Member

@devrandom devrandom commented Apr 24, 2024

  • dynamic signer factory
  • DynSigner
  • apply xtest macros
  • PoC external usage
  • run PoC in CI
  • fix PoC failure in fake_network_test and others

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 81.54206% with 79 lines in your changes missing coverage. Please review.

Project coverage is 88.56%. Comparing base (6cf270d) to head (21098e6).

Files with missing lines Patch % Lines
lightning-macros/src/lib.rs 45.45% 41 Missing and 1 partial ⚠️
lightning/src/util/dyn_signer.rs 68.62% 16 Missing ⚠️
lightning/src/util/test_channel_signer.rs 7.14% 13 Missing ⚠️
lightning/src/util/test_utils.rs 85.71% 3 Missing ⚠️
lightning/src/events/mod.rs 50.00% 2 Missing ⚠️
lightning/src/ln/onion_utils.rs 66.66% 2 Missing ⚠️
lightning/src/util/mut_global.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3016      +/-   ##
==========================================
- Coverage   88.61%   88.56%   -0.06%     
==========================================
  Files         149      152       +3     
  Lines      117091   117270     +179     
  Branches   117091   117270     +179     
==========================================
+ Hits       103765   103863      +98     
- Misses      10817    10889      +72     
- Partials     2509     2518       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from 9d4e233 to f341a0c Compare April 25, 2024 09:02
@devrandom devrandom force-pushed the 2024-04-ext-test branch 6 times, most recently from 87aadef to 4efd374 Compare April 26, 2024 08:19
@devrandom devrandom marked this pull request as ready for review April 26, 2024 08:20
@devrandom devrandom force-pushed the 2024-04-ext-test branch 3 times, most recently from 3c454d0 to ef8f13d Compare April 27, 2024 11:39
@devrandom devrandom force-pushed the 2024-04-ext-test branch 5 times, most recently from fd35254 to 2e2df96 Compare September 24, 2024 20:34
@devrandom
Copy link
Member Author

devrandom commented Sep 24, 2024

one more idea. it would be nice to collect all the tests of a file into a static array. this would require one of the following to automatically collect the array:

  • putting the functional tests inside mod {}
  • or, using the inventory or linkme crates as a dev dependency
  • or, using lazy_static, but we'll need a second macro, e.g. xtest_collect and compile error if it's forgotten will be a bit confusing this doesn't work because of constness requirements

@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from 84abf70 to 0a29d64 Compare September 25, 2024 12:32
@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from f987683 to dfda072 Compare February 27, 2025 00:12
@TheBlueMatt
Copy link
Collaborator

Ugh sorry this needs rebase after #3604. Should clean a few things up nicely though.

@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from 0734677 to fecc6c2 Compare March 1, 2025 03:11
@devrandom
Copy link
Member Author

no problem, rebase done

@devrandom devrandom force-pushed the 2024-04-ext-test branch 2 times, most recently from 6223c18 to 8db5ba6 Compare March 1, 2025 03:41
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, one last comment now that its been rebased, then I'm happy to land this 🎉

We want to allow functional tests to be run by other project,
allowing them to replace components, such as the signer.
Can be used for specifying dynamic components for tests, such as the signer.
wpaulino
wpaulino previously approved these changes Mar 3, 2025
DynSigner provides an abstraction for specifying an external signer
for functional tests.
Also, introduce TestSignerFactory, a factory for dynamic signers and ext-functional-test-demo crate for testing this machinery.
@devrandom
Copy link
Member Author

fixed rustfmt nit

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna go ahead and land this, but there's a few things we'll need to clean up in a followup.

@@ -4670,6 +4673,7 @@ where
///
/// LDK will not automatically retry this payment, though it may be manually re-sent after an
/// [`Event::PaymentFailed`] is generated.
#[cfg(any(test, feature = "_test_utils"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this wasn't removed.

@@ -515,8 +513,7 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
/// Toggles this node's signer to be available for the given signer operation.
/// This is useful for testing behavior for restoring an async signer that previously
/// could not return a signature immediately.
#[cfg(test)]
pub fn enable_channel_signer_op(&self, peer_id: &PublicKey, chan_id: &ChannelId, signer_op: SignerOp) {
pub fn enable_channel_signer_op(&self, peer_id: &PublicKey, chan_id: &ChannelId, signer_op: SignerOp) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and the next method down have indentation issues now.

error_code,
#[cfg(test)]
error_data, .. } => {
error_code,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, weird indentation here too.

@@ -2897,7 +2898,7 @@ fn claim_htlc_outputs() {
// transaction.
//
// This is a regression test for https://github.com/lightningdevkit/rust-lightning/issues/3537.
#[test]
#[xtest(feature = "_externalize_tests")]
fn test_multiple_package_conflicts() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing pub here

@@ -5046,7 +5047,7 @@ fn test_static_spendable_outputs_timeout_tx() {
check_spends!(spend_txn[2], node_txn[0], commitment_tx[0]); // All outputs
}

fn do_test_static_spendable_outputs_justice_tx_revoked_commitment_tx(split_tx: bool) {
pub fn do_test_static_spendable_outputs_justice_tx_revoked_commitment_tx(split_tx: bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be pub here.

do_test_max_dust_htlc_exposure_by_threshold_type(false, false);
do_test_max_dust_htlc_exposure_by_threshold_type(false, true);
do_test_max_dust_htlc_exposure_by_threshold_type(true, false);
do_test_max_dust_htlc_exposure_by_threshold_type(true, true);
}

#[test]
#[xtest(feature = "_externalize_tests")]
fn test_nondust_htlc_excess_fees_are_dust() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing pub

@@ -11941,7 +11942,7 @@ fn test_manual_funding_abandon() {
}));
}

#[test]
#[xtest(feature = "_externalize_tests")]
fn test_funding_signed_event() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing pub

@TheBlueMatt TheBlueMatt merged commit df68774 into lightningdevkit:main Mar 4, 2025
25 of 27 checks passed
devrandom added a commit to lightning-signer/rust-lightning that referenced this pull request Mar 4, 2025
TheBlueMatt added a commit that referenced this pull request Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants