-
Notifications
You must be signed in to change notification settings - Fork 38.7k
tests: add coverage to feature_addrman.py #28176
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
ismaelsadeeq
left a comment
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.
Concept ACK on adding test coverage to feature_addrman
You could make it more standard by calculating the maximum len_new and len_tried with the real values of ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT, ADDRMAN_BUCKET_SIZE.
This reduced magic numbers and make it easier to update if any of the constants were to be updated in a future PR.
you can calculate them in a first commit
diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py
index 7877f9d302..191a68d612 100755
--- a/test/functional/feature_addrman.py
+++ b/test/functional/feature_addrman.py
@@ -14,7 +14,9 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import ErrorMatch
from test_framework.util import assert_equal
-
+ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
+ADDRMAN_TRIED_BUCKET_COUNT = 1 << 8
+ADDRMAN_BUCKET_SIZE = 1 << 6
def serialize_addrman(
*,
format=1,
@@ -117,17 +119,19 @@ class AddrmanTest(BitcoinTestFramework):
self.log.info("Check that corrupt addrman cannot be read (len_tried)")
self.stop_node(0)
+ max_len_tried = ADDRMAN_TRIED_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
write_addrman(peers_dat, len_tried=-1)
self.nodes[0].assert_start_raises_init_error(
- expected_msg=init_error("Corrupt AddrMan serialization: nTried=-1, should be in \\[0, 16384\\]:.*"),
+ expected_msg=init_error(f"Corrupt AddrMan serialization: nTried=-1, should be in \\[0, {max_len_tried}\\]:.*"),
match=ErrorMatch.FULL_REGEX,
)
self.log.info("Check that corrupt addrman cannot be read (len_new)")
self.stop_node(0)
+ max_len_n_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
write_addrman(peers_dat, len_new=-1)
self.nodes[0].assert_start_raises_init_error(
- expected_msg=init_error("Corrupt AddrMan serialization: nNew=-1, should be in \\[0, 65536\\]:.*"),
+ expected_msg=init_error(f"Corrupt AddrMan serialization: nNew=-1, should be in \\[0, {max_len_n_new}\\]:.*"),
match=ErrorMatch.FULL_REGEX,
)then use them for the test coverage in second commit
diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py
index 191a68d612..eb7eaaf9df 100755
--- a/test/functional/feature_addrman.py
+++ b/test/functional/feature_addrman.py
@@ -126,6 +126,13 @@ class AddrmanTest(BitcoinTestFramework):
match=ErrorMatch.FULL_REGEX,
)
+ self.log.info("Check that corrupt addrman cannot be read (large len_tried)")
+ write_addrman(peers_dat, len_tried=max_len_tried + 1)
+ self.nodes[0].assert_start_raises_init_error(
+ expected_msg=init_error(f"Corrupt AddrMan serialization: nTried={max_len_tried + 1}, should be in \\[0, {max_len_tried}\\]:.*"),
+ match=ErrorMatch.FULL_REGEX,
+ )
+
self.log.info("Check that corrupt addrman cannot be read (len_new)")
self.stop_node(0)
max_len_n_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
@@ -135,6 +142,14 @@ class AddrmanTest(BitcoinTestFramework):
match=ErrorMatch.FULL_REGEX,
)
+ self.log.info("Check that corrupt addrman cannot be read (large len_new)")
+ self.stop_node(0)
+ write_addrman(peers_dat, len_new=max_len_n_new + 1)
+ self.nodes[0].assert_start_raises_init_error(
+ expected_msg=init_error(f"Corrupt AddrMan serialization: nNew={max_len_n_new + 1}, should be in \\[0, {max_len_n_new}\\]:.*"),
+ match=ErrorMatch.FULL_REGEX,
+ )
+c9ecdac to
4b84a69
Compare
Makes sense took your two commits e309230 and 19921ce squashed them into one and added you as coauthor thanks for the review! |
|
CI failure is unrelated? |
yea I think so looks like the test is failing in |
4b84a69 to
eb195d6
Compare
stratospher
left a comment
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.
ACK eb195d6.
eb195d6 to
1b044a3
Compare
ismaelsadeeq
left a comment
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.
Tested ACK 1b044a309d48821ae014256eb56d0f83a1de969b
bcab758 to
d2f87a3
Compare
|
force pushed to d2f87a3 This addresses #28176 (comment) and moves the constant variables to the netutil.py file (cc @0xB10C) |
0xB10C
left a comment
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.
Code Review ACK d2f87a3f5bc6ac833fee6e5d05452ebe2e137f22
I added two new tests that will cover the nNew and nTried tests which add coverage to the if block by checking values larger than our range since we only check for negative values now Co-authored-by: ismaelsadeeq <[email protected]>
d2f87a3 to
380130d
Compare
|
ACK 380130d, code looks good to me 🍃 . |
|
Re-ACK 380130d |
380130d test: add coverage to feature_addrman.py (kevkevin) Pull request description: I added two new tests that will cover the nNew and nTried tests which add coverage to the if block by checking values larger than our range since we only check for negative values now adding coverage to these lines https://github.com/bitcoin/bitcoin/blob/master/src/addrman.cpp#L273 https://github.com/bitcoin/bitcoin/blob/master/src/addrman.cpp#L280 our test seem to only cover the `nTried < 0` and `nNew < 0` scenarios ACKs for top commit: ismaelsadeeq: ACK 380130d, code looks good to me 🍃 . 0xB10C: Re-ACK 380130d Tree-SHA512: a063bd9ca4d2d536a27c8c22a28fb13759a96f19cd8ba6cb8879cf7f65046d4ff6e8f70df17feaffd0d0d08ef914cb18a11258d313a4841c811a7e7ae4df6d5b
I added two new tests that will cover the nNew and nTried tests which add coverage to the if block by checking values larger than our range since we only check for negative values now
adding coverage to these lines
https://github.com/bitcoin/bitcoin/blob/master/src/addrman.cpp#L273
https://github.com/bitcoin/bitcoin/blob/master/src/addrman.cpp#L280
our test seem to only cover the
nTried < 0andnNew < 0scenarios