tests: add coverage to feature_addrman.py #28176

pull kevkevinpal wants to merge 1 commits into bitcoin:master from kevkevinpal:test-addrman-large-vals changing 2 files +25 −3
  1. kevkevinpal commented at 4:35 am on July 28, 2023: contributor

    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

  2. DrahtBot commented at 4:35 am on July 28, 2023: contributor

    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.

  3. DrahtBot added the label Tests on Jul 28, 2023
  4. achow101 requested review from theStack on Sep 20, 2023
  5. ismaelsadeeq commented at 11:23 am on September 24, 2023: member

    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.

     0diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py
     1index 7877f9d302..191a68d612 100755
     2--- a/test/functional/feature_addrman.py
     3+++ b/test/functional/feature_addrman.py
     4@@ -14,7 +14,9 @@ from test_framework.test_framework import BitcoinTestFramework
     5 from test_framework.test_node import ErrorMatch
     6 from test_framework.util import assert_equal
     7 
     8 -
     9+ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
    10+ADDRMAN_TRIED_BUCKET_COUNT = 1 << 8
    11+ADDRMAN_BUCKET_SIZE = 1 << 6
    12 def serialize_addrman(
    13     *,
    14     format=1,
    15@@ -117,17 +119,19 @@ class AddrmanTest(BitcoinTestFramework):
    16 
    17         self.log.info("Check that corrupt addrman cannot be read (len_tried)")
    18         self.stop_node(0)
    19+        max_len_tried = ADDRMAN_TRIED_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
    20         write_addrman(peers_dat, len_tried=-1)
    21         self.nodes[0].assert_start_raises_init_error(
    22-            expected_msg=init_error("Corrupt AddrMan serialization: nTried=-1, should be in \\[0, 16384\\]:.*"),
    23+            expected_msg=init_error(f"Corrupt AddrMan serialization: nTried=-1, should be in \\[0, {max_len_tried}\\]:.*"),
    24             match=ErrorMatch.FULL_REGEX,
    25         )
    26 
    27         self.log.info("Check that corrupt addrman cannot be read (len_new)")
    28         self.stop_node(0)
    29+        max_len_n_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
    30         write_addrman(peers_dat, len_new=-1)
    31         self.nodes[0].assert_start_raises_init_error(
    32-            expected_msg=init_error("Corrupt AddrMan serialization: nNew=-1, should be in \\[0, 65536\\]:.*"),
    33+            expected_msg=init_error(f"Corrupt AddrMan serialization: nNew=-1, should be in \\[0, {max_len_n_new}\\]:.*"),
    34             match=ErrorMatch.FULL_REGEX,
    35         )
    
     0diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py
     1index 191a68d612..eb7eaaf9df 100755
     2--- a/test/functional/feature_addrman.py
     3+++ b/test/functional/feature_addrman.py
     4@@ -126,6 +126,13 @@ class AddrmanTest(BitcoinTestFramework):
     5             match=ErrorMatch.FULL_REGEX,
     6         )
     7 
     8+        self.log.info("Check that corrupt addrman cannot be read (large len_tried)")
     9+        write_addrman(peers_dat, len_tried=max_len_tried + 1)
    10+        self.nodes[0].assert_start_raises_init_error(
    11+            expected_msg=init_error(f"Corrupt AddrMan serialization: nTried={max_len_tried + 1}, should be in \\[0, {max_len_tried}\\]:.*"),
    12+            match=ErrorMatch.FULL_REGEX,
    13+        )
    14+
    15         self.log.info("Check that corrupt addrman cannot be read (len_new)")
    16         self.stop_node(0)
    17         max_len_n_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
    18@@ -135,6 +142,14 @@ class AddrmanTest(BitcoinTestFramework):
    19             match=ErrorMatch.FULL_REGEX,
    20         )
    21 
    22+        self.log.info("Check that corrupt addrman cannot be read (large len_new)")
    23+        self.stop_node(0)
    24+        write_addrman(peers_dat, len_new=max_len_n_new + 1)
    25+        self.nodes[0].assert_start_raises_init_error(
    26+            expected_msg=init_error(f"Corrupt AddrMan serialization: nNew={max_len_n_new + 1}, should be in \\[0, {max_len_n_new}\\]:.*"),
    27+            match=ErrorMatch.FULL_REGEX,
    28+        )
    29+
    

    see https://github.com/bitcoin/bitcoin/commit/e309230694512b03c055409f5d70136ab51719f6 and https://github.com/bitcoin/bitcoin/commit/19921ce5e95624469e64d00bf9194b4a67c1ce95

  6. kevkevinpal force-pushed on Sep 25, 2023
  7. kevkevinpal force-pushed on Sep 25, 2023
  8. kevkevinpal commented at 5:15 am on September 25, 2023: contributor

    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 https://github.com/bitcoin/bitcoin/commit/e309230694512b03c055409f5d70136ab51719f6 and https://github.com/bitcoin/bitcoin/commit/19921ce5e95624469e64d00bf9194b4a67c1ce95 squashed them into one and added you as coauthor thanks for the review!

  9. DrahtBot added the label CI failed on Sep 25, 2023
  10. kevkevinpal requested review from ismaelsadeeq on Sep 25, 2023
  11. in test/functional/feature_addrman.py:19 in 4b84a695b0 outdated
    13@@ -14,7 +14,9 @@
    14 from test_framework.test_node import ErrorMatch
    15 from test_framework.util import assert_equal
    16 
    17-
    18+ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
    19+ADDRMAN_TRIED_BUCKET_COUNT = 1 << 8
    20+ADDRMAN_BUCKET_SIZE = 1 << 6
    


    ismaelsadeeq commented at 4:00 pm on September 25, 2023:
    nit: space between constant declarations and functions

    kevkevinpal commented at 4:00 am on September 28, 2023:
    pushed fix in eb195d6

    stratospher commented at 4:12 pm on September 29, 2023:
    maybe we could move these globals into a common file? it’s used in test/functional/rpc_net.py in #28523 too. (cc @0xB10C)

    kevkevinpal commented at 5:01 pm on September 29, 2023:

    maybe we could move these globals into a common file? it’s used in test/functional/rpc_net.py in #28523 too. (cc @0xB10C)

    the best places I can think to make these values common are test/functional/test_framework/util.py or test/functional/test_framework/netutil.py

  12. ismaelsadeeq commented at 4:01 pm on September 25, 2023: member
    CI failure is unrelated?
  13. kevkevinpal commented at 10:12 pm on September 25, 2023: contributor

    CI failure is unrelated?

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

  14. DrahtBot removed the label CI failed on Sep 27, 2023
  15. kevkevinpal force-pushed on Sep 28, 2023
  16. in test/functional/feature_addrman.py:139 in eb195d66bc outdated
    135             match=ErrorMatch.FULL_REGEX,
    136         )
    137 
    138         self.log.info("Check that corrupt addrman cannot be read (len_new)")
    139         self.stop_node(0)
    140+        max_len_n_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE
    


    stratospher commented at 4:19 pm on September 29, 2023:
    eb195d6: s/max_len_n_new/max_len_new for consistency in naming with max_len_tried?

    kevkevinpal commented at 4:53 pm on September 29, 2023:
    fixed in 1b044a3
  17. stratospher commented at 4:24 pm on September 29, 2023: contributor
    ACK eb195d6.
  18. kevkevinpal force-pushed on Sep 29, 2023
  19. ismaelsadeeq approved
  20. ismaelsadeeq commented at 12:23 pm on September 30, 2023: member
    Tested ACK 1b044a309d48821ae014256eb56d0f83a1de969b
  21. DrahtBot requested review from stratospher on Sep 30, 2023
  22. kevkevinpal force-pushed on Sep 30, 2023
  23. kevkevinpal force-pushed on Sep 30, 2023
  24. DrahtBot added the label CI failed on Sep 30, 2023
  25. kevkevinpal commented at 7:27 pm on September 30, 2023: contributor

    force pushed to d2f87a3

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

  26. DrahtBot removed the label CI failed on Sep 30, 2023
  27. in test/functional/test_framework/netutil.py:27 in d2f87a3f5b outdated
    24@@ -25,6 +25,10 @@
    25 STATE_LISTEN = '0A'
    26 # STATE_CLOSING = '0B'
    27 
    


    0xB10C commented at 9:51 am on October 1, 2023:

    nit

    0
    1# Address manager size constants as defined in addrman_impl.h
    

    kevkevinpal commented at 3:44 am on October 2, 2023:
    thanks! resolved in 380130d
  28. 0xB10C approved
  29. 0xB10C commented at 10:06 am on October 1, 2023: contributor
    Code Review ACK d2f87a3f5bc6ac833fee6e5d05452ebe2e137f22
  30. DrahtBot removed review request from stratospher on Oct 1, 2023
  31. DrahtBot requested review from ismaelsadeeq on Oct 1, 2023
  32. DrahtBot requested review from stratospher on Oct 1, 2023
  33. test: add coverage to feature_addrman.py
    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 <ask4ismailsadiq@gmail.com>
    380130d9d7
  34. kevkevinpal force-pushed on Oct 2, 2023
  35. ismaelsadeeq commented at 10:24 am on October 2, 2023: member
    ACK 380130d9d70f8f8d395949a51f43806f6e600efa, code looks good to me 🍃 . Tests passed this branch rebased on master.
  36. DrahtBot removed review request from ismaelsadeeq on Oct 2, 2023
  37. DrahtBot removed review request from stratospher on Oct 2, 2023
  38. DrahtBot requested review from stratospher on Oct 2, 2023
  39. DrahtBot requested review from 0xB10C on Oct 2, 2023
  40. 0xB10C commented at 10:25 am on October 2, 2023: contributor
    Re-ACK 380130d9d70f8f8d395949a51f43806f6e600efa
  41. DrahtBot removed review request from stratospher on Oct 2, 2023
  42. DrahtBot removed review request from 0xB10C on Oct 2, 2023
  43. DrahtBot requested review from stratospher on Oct 2, 2023
  44. fanquake merged this on Oct 2, 2023
  45. fanquake closed this on Oct 2, 2023

  46. Frank-GER referenced this in commit 06ffa121e7 on Oct 5, 2023
  47. bitcoin locked this on Oct 1, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-23 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me