-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: develop
Are you sure you want to change the base?
test: introduce basic unit tests for instantsend #6606
Conversation
WalkthroughThe changes introduce a new test file, ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
src/test/evo_islock_tests.cpp
Outdated
// 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); |
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.
nit: coule use uint256::ONE
and uint256::TWO
here
src/test/evo_islock_tests.cpp
Outdated
CHashWriter hw(SER_GETHASH, 0); | ||
hw << std::string_view("islock"); | ||
hw << islock.inputs; | ||
const uint256 expected = hw.GetHash(); |
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.
nit: refactor it to a function so far as it is used twice (see below)
src/test/evo_islock_tests.cpp
Outdated
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); |
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.
nit: refactor it to a function so far as it is used twice
src/test/evo_islock_tests.cpp
Outdated
ss >> islock; | ||
|
||
// Verify the calculated signHash | ||
auto signHash = llmq::BuildSignHash(Consensus::LLMQType::LLMQ_60_75, uint256S(quorumHash), islock.GetRequestId(), islock.txid); |
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.
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.
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/test/evo_islock_tests.cpp (3)
69-69
: Document the BLS scheme settingSetting
bls::bls_legacy_scheme.store(false)
is critical for the test to work, but the reasoning behind this choice could be better documented. Consider adding a more detailed comment explaining why this setting is necessary and what would happen if it were set to true.
58-59
: DefinequorumHash
consistently with other variablesWhile most string variables use
std::string_view
,quorumHash
is defined asstd::string
. For consistency, consider usingstd::string_view
for all string constants or provide a comment explaining why this particular variable needs to be astd::string
.
1-104
: Overall test coverage is comprehensive but could be expandedThe implementation provides good basic coverage of the InstantSend functionality, with tests for request ID calculation and deserialization from real data. To further improve coverage, consider:
- Adding tests with different quorum types as previously suggested
- Testing the serialization process (not just deserialization)
- Adding tests for edge cases or error conditions
These tests provide a solid foundation but expanding them would further enhance the robustness of the codebase.
🧰 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)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
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)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: arm-linux-build / Build source
- GitHub Check: x86_64-w64-mingw32 / Build depends
- GitHub Check: x86_64-pc-linux-gnu / Build depends
- GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
- GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
🔇 Additional comments (6)
src/test/evo_islock_tests.cpp (6)
15-21
: Helper function well implementedThe
CalculateRequestId
function is cleanly implemented to mirror the internal functionality ofCInstantSendLock::GetRequestId()
. This is good practice for unit tests as it provides an independent verification mechanism.
23-48
: Test case covers empty and non-empty inputs correctlyThe
getrequestid
test case appropriately verifies the request ID calculation for both an empty inputs vector and one with dummy inputs. Good use ofuint256::ONE
anduint256::TWO
for creating test outpoints.
40-42
: Dummy outpoints correctly constructedGood use of the predefined constants
uint256::ONE
anduint256::TWO
for creating test outpoints rather than manually constructing arbitrary values.
50-102
: Consider adding a test with different quorum typesThe deserialization test is thorough, verifying multiple aspects of the deserialized data including hashes, transaction ID, cycle hash, inputs, and signature. However, as previously suggested, it would be beneficial to add a test with a different quorum type to ensure that parameter is properly handled.
You could add a variation of the current test where you use a different quorum type and verify that the signature hash changes, with something like:
// Test with a different quorum type auto signHashAlt = llmq::BuildSignHash(Consensus::LLMQType::LLMQ_400_60, uint256S(quorumHash), islock.GetRequestId(), islock.txid); BOOST_CHECK(signHashAlt != signHash);
77-80
: Add test for different quorum typesThis section tests only one quorum type (
LLMQ_60_75
). As previously suggested, it would be valuable to add a test case with a different quorum type to verify that theBuildSignHash
function properly handles different quorum types.
97-98
: Good verification of request ID calculationThe test correctly verifies that the calculated request ID matches the expected value derived from the inputs. This ensures consistency between the internal implementation and the test's expectations.
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.
utACK 53799cd
pls consider 98b20c8 |
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.