Skip to content

Conversation

@kevkevinpal
Copy link
Contributor

@kevkevinpal kevkevinpal commented Jul 28, 2023

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 28, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ismaelsadeeq, 0xB10C
Stale ACK stratospher

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the Tests label Jul 28, 2023
@achow101 achow101 requested a review from theStack September 20, 2023 17:16
Copy link
Member

@ismaelsadeeq ismaelsadeeq left a 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,
+        )
+

see e309230 and 19921ce

@kevkevinpal kevkevinpal force-pushed the test-addrman-large-vals branch 2 times, most recently from c9ecdac to 4b84a69 Compare September 25, 2023 05:13
@kevkevinpal
Copy link
Contributor Author

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
then use them for the test coverage in second commit

see e309230 and 19921ce

Makes sense took your two commits e309230 and 19921ce squashed them into one and added you as coauthor thanks for the review!

@ismaelsadeeq
Copy link
Member

CI failure is unrelated?

@kevkevinpal
Copy link
Contributor Author

CI failure is unrelated?

yea I think so looks like the test is failing in test/functional/wallet_fundrawtransaction.py

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

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

ACK eb195d6.

@kevkevinpal kevkevinpal force-pushed the test-addrman-large-vals branch from eb195d6 to 1b044a3 Compare September 29, 2023 16:53
Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

Tested ACK 1b044a309d48821ae014256eb56d0f83a1de969b

@kevkevinpal kevkevinpal force-pushed the test-addrman-large-vals branch 2 times, most recently from bcab758 to d2f87a3 Compare September 30, 2023 19:26
@kevkevinpal
Copy link
Contributor Author

force pushed to d2f87a3

This addresses #28176 (comment) and moves the constant variables to the netutil.py file (cc @0xB10C)

Copy link
Contributor

@0xB10C 0xB10C left a 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

@DrahtBot DrahtBot requested review from ismaelsadeeq and stratospher and removed request for stratospher October 1, 2023 10:06
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]>
@kevkevinpal kevkevinpal force-pushed the test-addrman-large-vals branch from d2f87a3 to 380130d Compare October 2, 2023 03:44
@ismaelsadeeq
Copy link
Member

ACK 380130d, code looks good to me 🍃 .
Tests passed this branch rebased on master.

@DrahtBot DrahtBot requested review from 0xB10C and stratospher and removed request for ismaelsadeeq and stratospher October 2, 2023 10:24
@0xB10C
Copy link
Contributor

0xB10C commented Oct 2, 2023

Re-ACK 380130d

@DrahtBot DrahtBot requested review from stratospher and removed request for 0xB10C and stratospher October 2, 2023 10:25
@fanquake fanquake merged commit 8909667 into bitcoin:master Oct 2, 2023
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 5, 2023
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
@bitcoin bitcoin locked and limited conversation to collaborators Oct 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants