Skip to content

allow functional tests to be used externally with a dynamic signer factory - #3016

Merged
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
lightning-signer:2024-04-ext-test
Mar 4, 2025
Merged

allow functional tests to be used externally with a dynamic signer factory#3016
TheBlueMatt merged 5 commits into
lightningdevkit:mainfrom
lightning-signer:2024-04-ext-test

Conversation

@devrandom

@devrandomdevrandom commented Apr 24, 2024

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

Comment threadmut-global/src/lib.rs Outdated
@codecov-commenter

codecov-commenter commented Apr 24, 2024

Copy link
Copy Markdown

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 linesPatch %Lines
lightning-macros/src/lib.rs45.45%41 Missing and 1 partial ⚠️
lightning/src/util/dyn_signer.rs68.62%16 Missing ⚠️
lightning/src/util/test_channel_signer.rs7.14%13 Missing ⚠️
lightning/src/util/test_utils.rs85.71%3 Missing ⚠️
lightning/src/events/mod.rs50.00%2 Missing ⚠️
lightning/src/ln/onion_utils.rs66.66%2 Missing ⚠️
lightning/src/util/mut_global.rs96.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.

Comment threadext-test-macro/Cargo.toml Outdated
Comment threadlightning/src/sign/mod.rs Outdated
Comment threadlightning/src/sign/mod.rs Outdated
Comment threadlightning/src/util/mut_global.rs Outdated
@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 2 times, most recently from 9d4e233 to f341a0cCompareApril 25, 2024 09:02
Comment threadlightning/src/util/dyn_signer.rs Outdated
@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 6 times, most recently from 87aadef to 4efd374CompareApril 26, 2024 08:19
@devrandom
devrandom marked this pull request as ready for review April 26, 2024 08:20
@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 3 times, most recently from 3c454d0 to ef8f13dCompareApril 27, 2024 11:39
Comment threadlightning-invoice/src/utils.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/sign/mod.rs Outdated
Comment threadlightning/src/util/mod.rs Outdated
Comment threadlightning/Cargo.toml Outdated
Comment threadlightning/src/util/dyn_signer.rs Outdated
Comment threadlightning/src/util/dyn_signer.rs
@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 5 times, most recently from fd35254 to 2e2df96CompareSeptember 24, 2024 20:34
@devrandom

devrandom commented Sep 24, 2024

Copy link
Copy Markdown
MemberAuthor

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
devrandomforce-pushed the 2024-04-ext-test branch 2 times, most recently from 84abf70 to 0a29d64CompareSeptember 25, 2024 12:32
Comment threadlightning-macros/src/lib.rs Outdated
Comment threadlightning/src/util/dyn_signer.rs
Comment threadlightning/src/util/dyn_signer.rs Outdated
Comment threadlightning/src/util/mod.rs Outdated
Comment threadlightning/src/util/test_channel_signer.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
Comment threadlightning/src/ln/outbound_payment.rs Outdated
Comment threadlightning/src/routing/router.rs Outdated
Comment threadlightning/src/util/mod.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 2 times, most recently from f987683 to dfda072CompareFebruary 27, 2025 00:12
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

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

@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 2 times, most recently from 0734677 to fecc6c2CompareMarch 1, 2025 03:11
@devrandom

Copy link
Copy Markdown
MemberAuthor

no problem, rebase done

@devrandom
devrandomforce-pushed the 2024-04-ext-test branch 2 times, most recently from 6223c18 to 8db5ba6CompareMarch 1, 2025 03:41

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

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 🎉

Comment threadlightning/src/util/test_utils.rs Outdated
Comment threadlightning/src/util/mut_global.rs
Comment threadlightning/src/util/dyn_signer.rs Outdated
Comment threadlightning/src/util/dyn_signer.rs Outdated
Comment threadlightning/src/util/dyn_signer.rs Outdated
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
Copy Markdown
MemberAuthor

fixed rustfmt nit

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

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.

///
/// 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
Copy Markdown
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.

/// 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
Copy Markdown
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
Copy Markdown
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.

// 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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing pub here

}

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
Copy Markdown
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.


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing pub


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

Copy link
Copy Markdown
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:mainMar 4, 2025
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 freeto 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

@devrandom@codecov-commenter@TheBlueMatt@wpaulino@tnull