Skip to content
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

[Test] Add node-level tests with open+payment+close, with many checks #2814

Closed
wants to merge 1 commit into from

Conversation

optout21
Copy link
Contributor

@optout21 optout21 commented Jan 5, 2024

Add some new integration tests, for the common scenarios:

  • open channel, close it
  • open channel, make a payment, close channel

Test features:

  • node-level end-to-end tests
  • node-level steps (ChannelManager)
  • many checks, for messages, events, monitors, funding transaction, etc.

I suggest to include even if there is some level of duplication with other tests. If very similar tests exists, feel free to close.

@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (4deb263) 88.49% compared to head (7ca571f) 90.44%.
Report is 134 commits behind head on main.

Files Patch % Lines
lightning/src/ln/functional_tests.rs 97.90% 4 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2814      +/-   ##
==========================================
+ Coverage   88.49%   90.44%   +1.94%     
==========================================
  Files         114      120       +6     
  Lines       91935   104556   +12621     
  Branches    91935   104556   +12621     
==========================================
+ Hits        81359    94562   +13203     
+ Misses       8097     7598     -499     
+ Partials     2479     2396      -83     

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

@optout21 optout21 marked this pull request as ready for review January 5, 2024 12:57
@TheBlueMatt
Copy link
Collaborator

Nice. These looks like well-written tests, but its not clear to me exactly what they're testing that isn't already covered. There's a ton of noise in the codecov stats but scrolling through it (https://app.codecov.io/gh/lightningdevkit/rust-lightning/pull/2814/indirect-changes) I don't see any material new coverage at the line-level.

@optout21
Copy link
Contributor Author

Nice. These looks like well-written tests, but its not clear to me exactly what they're testing that isn't already covered. There's a ton of noise in the codecov stats but scrolling through it (https://app.codecov.io/gh/lightningdevkit/rust-lightning/pull/2814/indirect-changes) I don't see any material new coverage at the line-level.

I don't think this adds any new coverage, this is a very typical use case, and all parts of it should be covered by some tests.
I was looking for an integration-level test from where the steps of a typical use case are clearly visible: the API calls, and the messages exchanged between the peers. I haven't found exactly like this, so I put together one.
I will likely write similar style test for the splicing use case, but I thought one is useful for the regular open channel case as well.

Copy link

coderabbitai bot commented Jan 26, 2024

Walkthrough

The update introduces significant enhancements to the lightning library's functional testing capabilities, particularly around channel management and multisig transactions. By adding new functions and a dependency, it bolsters the testing of channel opening, closing, and payment processes, alongside the creation and verification of multisig transactions, streamlining the development and debugging of Lightning Network channels.

Changes

File Path Change Summary
lightning/src/ln/functional_tests.rs - Added ChannelHandshakeConfig import
- Introduced multisig transaction related functions
- Added hex crate dependency
- Enhanced channel open, close, and payment test functions

🐇✨
In the realm of code, where lightning strikes,
We weave the nets where digital gold lies.
Through open, close, in tests we trust,
Our channels strong, in Rust we must.
🌩️🔑💼

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 51d9ee3 and 7ca571f.
Files selected for processing (1)
  • lightning/src/ln/functional_tests.rs (3 hunks)
Additional comments: 7
lightning/src/ln/functional_tests.rs (7)
  • 38-38: The addition of ChannelHandshakeConfig to the import list is appropriate for the new functionality being tested. This change aligns with the PR's objective to enhance testing around channel operations.
  • 52-52: The introduction of the hex crate dependency is justified by the need to work with hexadecimal representations in the new test functions, particularly for verifying scripts and transactions. This change supports the PR's goal of comprehensive testing.
  • 68-98: The functions create_multisig_redeem_script, create_multisig_output_script, and verify_multisig_output_script are well-implemented, focusing on creating and verifying multisig scripts, which are crucial for funding transactions in Lightning Network channels. These additions are in line with the PR's objectives to simulate and verify channel operations comprehensively.
  • 100-107: The function get_funding_key correctly retrieves the funding key from a node for a given channel, which is essential for verifying funding transactions. This utility function enhances the test suite's ability to validate channel setups accurately.
  • 111-129: The function verify_funding_tx effectively locates and verifies the funding transaction output based on the expected value and funding keys. This function is crucial for ensuring the correctness of funding transactions in the test suite, aligning with the PR's goals.
  • 135-258: The test test_channel_open_and_close comprehensively simulates the process of opening and closing a channel, including the creation and verification of funding transactions. This test aligns with the PR's objectives by providing a detailed illustration of channel lifecycle operations. However, ensure that the hardcoded values, such as expected channel IDs and transaction lengths, are derived from a predictable setup to avoid flakiness in tests.
  • 263-431: The test test_channel_open_and_payment effectively simulates opening a channel, making a payment, and then closing the channel. This test provides a clear, step-by-step demonstration of a common use case in the Lightning Network, aligning with the PR's objectives to enhance the test suite's clarity and comprehensibility. Similar to the previous test, ensure that the hardcoded values and assumptions are based on a stable setup.

@TheBlueMatt
Copy link
Collaborator

This isn't a particularly representative example of how tests should be written, however. We have a large pile of utilities which implement the various steps involved here, which we strongly prefer to use where possible as it avoids having to update every test whenever any small thing changes, and allows us to instead simply update the utilities. Thus, I don't particularly think we should be upstreaming more fully-written tests like this unless it increases coverage.

@optout21
Copy link
Contributor Author

Retracting

@optout21 optout21 closed this Jan 31, 2024
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.

3 participants