test: add coverage for `-bantime` #26604

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2022-11-setban-bantime-test changing 1 files +7 −1
  1. brunoerg commented at 6:38 PM on November 29, 2022: contributor

    This PR adds test coverage for -bantime. This flag sets the time in seconds how long the IP is banned (in the case you don't explicitly set bantime when using setban).

  2. DrahtBot commented at 6:38 PM on November 29, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK MarcoFalke

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26863 (test: merge banning test from p2p_disconnect_ban to rpc_setban by brunoerg)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Tests on Nov 29, 2022
  4. in test/functional/rpc_setban.py:78 in 9be1a6c373 outdated
      70 | @@ -70,6 +71,11 @@ def run_test(self):
      71 |          assert not self.is_banned(node, tor_addr)
      72 |          assert not self.is_banned(node, ip_addr)
      73 |  
      74 | +        self.log.info("Test -bantime")
      75 | +        self.restart_node(1, ["-bantime=1234"])
      76 | +        self.nodes[1].setban("127.0.0.1", "add")
      77 | +        banned = self.nodes[1].listbanned()[0]
      78 | +        assert_equal(banned['ban_duration'], 1234)
    


    unknown commented at 9:34 AM on December 1, 2022:

    The assert_equal function should be called with the expected value as the first argument and the actual value as the second argument.

            assert_equal(1234, banned['ban_duration'])
    

    unknown commented at 9:35 AM on December 1, 2022:

    It is generally a good idea to include a descriptive error message in the call to assert_equal so that it is clear what the error is if the assertion fails.

            assert_equal(1234, banned['ban_duration'], "ban_duration is not equal to 1234")
    

    maflcko commented at 9:45 AM on December 1, 2022:

    The assertion will already print this when hit


    brunoerg commented at 1:52 PM on December 1, 2022:

    The assertion will already print this when hit

    Yes, there is no need to include a message.


    maflcko commented at 3:57 PM on April 28, 2023:

    Pretty sure this will lead to a race when the rpc is dispatched after a one second sleep?


    brunoerg commented at 5:11 PM on April 29, 2023:

    Where is/why the one second sleep?


    maflcko commented at 9:05 AM on April 30, 2023:

    Ah sorry. You are checking the ban_duration, not time_remaining. So this is fine. For reference, the output with the CPU put to sleep for a second looked like:

    {
    "address": "127.0.0.1/32", 
    "ban_created": 1682845373, 
    "banned_until": 1682846607, 
    "ban_duration": 1234, 
    "time_remaining": 1233
    }
    
  5. in test/functional/rpc_setban.py:77 in 9be1a6c373 outdated
      70 | @@ -70,6 +71,11 @@ def run_test(self):
      71 |          assert not self.is_banned(node, tor_addr)
      72 |          assert not self.is_banned(node, ip_addr)
      73 |  
      74 | +        self.log.info("Test -bantime")
      75 | +        self.restart_node(1, ["-bantime=1234"])
      76 | +        self.nodes[1].setban("127.0.0.1", "add")
      77 | +        banned = self.nodes[1].listbanned()[0]
    


    unknown commented at 9:36 AM on December 1, 2022:

    The code should check the return value of self.nodes[1].listbanned() to make sure it is not empty before trying to access the first element. If the list is empty, then the ban on 127.0.0.1 was not successful, and the code should fail the test.


    unknown commented at 9:39 AM on December 1, 2022:

    It would be more readable if the code assigned the return value of self.nodes[1].listbanned() to a variable, and then accessed the first element of the list using that variable.

            banned_list = self.nodes[1].listbanned()
            assert len(banned_list) > 0, "Failed to ban 127.0.0.1"
            banned = banned_list[0]
    

    maflcko commented at 9:44 AM on December 1, 2022:

    [i] already asserts and fails the test


    ismaelsadeeq commented at 11:31 PM on March 15, 2023:

    tAck but how about adding another coverage to test the ban remaining time after the bantime elapsed.

    time.sleep(secs) banned = self.nodes[1].listbanned()[0] assert_equal(banned["time_remaining"],0)

  6. unknown changes_requested
  7. unknown commented at 9:40 AM on December 1, 2022: none

    Concept ACK

    I was testing ChatGPT to see if it can review pull requests and it suggested 4 improvements that make sense:

  8. brunoerg commented at 1:55 PM on December 1, 2022: contributor

    Thanks, @1440000bytes for your review. Interesting experiment using an AI, however, I believe it doesn't deal so well with some specific stuff from our framework. E.g. It doesn't know 100% what our assert functions do (perhaps the reason it suggested a text message on the assertion).

  9. test: add coverage for `-bantime` 9c18992bba
  10. brunoerg force-pushed on Mar 15, 2023
  11. maflcko commented at 9:05 AM on April 30, 2023: member

    lgtm ACK 9c18992bbaf649f8c5461d5e4dc39eb1a07ffc77

  12. maflcko assigned fanquake on Apr 30, 2023
  13. fanquake merged this on May 1, 2023
  14. fanquake closed this on May 1, 2023

  15. sidhujag referenced this in commit 933f6084f1 on May 1, 2023
  16. bitcoin locked this on Apr 30, 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: 2026-05-02 03:13 UTC

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