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: introduce basic unit tests for instantsend #6606

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

PastaPastaPasta
Copy link
Member

What was done?

Introduce unit tests for some instantsend logic

How Has This Been Tested?

Running tests

Breaking Changes

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@PastaPastaPasta PastaPastaPasta added this to the 23 milestone Mar 2, 2025
Copy link

coderabbitai bot commented Mar 2, 2025

Walkthrough

The changes introduce a new test file, test/evo_islock_tests.cpp, into the test suite by adding it to the BITCOIN_TESTS variable in src/Makefile.test.include. This file contains a test suite for InstantSend functionality, which includes two test cases. The first test case, getrequestid, creates an instance of CInstantSendLock, computes hash values for both empty and populated inputs vectors, and verifies that the computed request ID matches the expected hash values. The second test case, deserialize_instantlock_from_realdata2, handles the deserialization of an InstantSend lock from a hex string, extracts expected values from various fields (such as txid, cycleHash, and signature), and checks for consistency with the computed values. The tests utilize the Boost Test framework for assertions and ensure that the lock’s serialization and hash computations function as expected.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26ea618 and 674d541.

📒 Files selected for processing (2)
  • src/Makefile.test.include (1 hunks)
  • src/test/evo_islock_tests.cpp (1 hunks)
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/test/evo_islock_tests.cpp

[error] 13-13: There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.

(unknownMacro)

🪛 GitHub Actions: Clang Diff Format Check
src/test/evo_islock_tests.cpp

[error] 1-1: Clang format differences found. Please run 'clang-format' to fix formatting issues.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
🔇 Additional comments (5)
src/Makefile.test.include (1)

114-114: Appropriate addition of the new test file.

The new test file test/evo_islock_tests.cpp has been properly added to the BITCOIN_TESTS variable, maintaining the alphabetical ordering convention of the test files list.

src/test/evo_islock_tests.cpp (4)

1-13: Well-organized test file structure with appropriate includes.

The file includes all necessary headers for testing InstantSend functionality and follows the project's standard test organization pattern.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 13-13: There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.

(unknownMacro)

🪛 GitHub Actions: Clang Diff Format Check

[error] 1-1: Clang format differences found. Please run 'clang-format' to fix formatting issues.


15-48: Well-structured test for the GetRequestId method.

This test effectively validates the GetRequestId() method of CInstantSendLock by:

  1. Testing with an empty inputs vector
  2. Testing with populated inputs vector
  3. Using appropriate hash verification

The test ensures that the request ID calculation is correct in both scenarios.


50-100: Comprehensive test for InstantSend lock deserialization.

This test thoroughly validates the deserialization of an InstantSend lock using real data:

  1. It verifies all critical fields (txid, cycleHash, signature, inputs)
  2. It checks the correct calculation of the request ID
  3. It validates the signature is properly handled

The use of real-world data ensures the test covers actual production scenarios.


1-103:

❓ Verification inconclusive

Code formatting needs to be fixed.

The CI pipeline indicates formatting issues with this file.


🏁 Script executed:

#!/bin/bash
# Run clang-format to see what formatting changes are needed
clang-format -style=file src/test/evo_islock_tests.cpp | diff -u src/test/evo_islock_tests.cpp -

Length of output: 5120


Formatting Compliance Issue in evo_islock_tests.cpp

It appears that the CI pipeline is flagging formatting problems, but the verification script failed to run clang-format (it reported "clang-format: command not found"). Please ensure that clang-format is installed and available in the CI environment (or run it locally) so you can generate a proper diff. Once the tool is available, reformat the file according to the project's style guidelines and verify that all formatting issues are resolved.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 13-13: There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.

(unknownMacro)

🪛 GitHub Actions: Clang Diff Format Check

[error] 1-1: Clang format differences found. Please run 'clang-format' to fix formatting issues.

✨ Finishing Touches
  • 📝 Generate Docstrings

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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

// Now add two dummy inputs to the lock
islock.inputs.clear();
// Construct two dummy outpoints (using uint256S for a dummy hash)
COutPoint op1(uint256S("0x0000000000000000000000000000000000000000000000000000000000000001"), 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: coule use uint256::ONE and uint256::TWO here

Comment on lines +41 to +44
CHashWriter hw(SER_GETHASH, 0);
hw << std::string_view("islock");
hw << islock.inputs;
const uint256 expected = hw.GetHash();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: refactor it to a function so far as it is used twice (see below)

BOOST_CHECK_EQUAL(input.n, expectedInputN);

// Compute the expected request ID: it is the hash of the constant prefix "islock" followed by the inputs.
CHashWriter hw(SER_GETHASH, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: refactor it to a function so far as it is used twice

ss >> islock;

// Verify the calculated signHash
auto signHash = llmq::BuildSignHash(Consensus::LLMQType::LLMQ_60_75, uint256S(quorumHash), islock.GetRequestId(), islock.txid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's add one more unit test with other quorum type to be sure that this argument is used?

I think a check such as BOOST_CHECK(signHash.ToString() != expectedSignHash) is enough.

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.

2 participants