Skip to content

Commit

Permalink
Merge #29688: test: remove duplicated ban test
Browse files Browse the repository at this point in the history
e30e862 test: remove duplicated ban test (brunoerg)

Pull request description:

  Test the ban list is preserved through restart has been done by both `rpc_setban` and `p2p_disconnect_ban`. Since `p2p_disconnect_ban` does it in a more elegant way, we can keep only it and remove the other one.

  https://github.com/bitcoin/bitcoin/blob/bf1b6383dbbfdd0c96a161d4693a48bf3a6b6150/test/functional/p2p_disconnect_ban.py#L74-L110

ACKs for top commit:
  achow101:
    ACK e30e862
  tdb3:
    ACK for e30e862.
  hernanmarino:
    tested ACK e30e862
  BrandonOdiwuor:
    ACK e30e862
  alfonsoromanz:
    ACK e30e862

Tree-SHA512: e89624f23011e6ffd76c31b2933b8386711e1d2c03366d6b3ea850484a4fd571f69971cdbc75ce2f546d541cb3fc7f4d495a5a011217d879746414e3286ac111
  • Loading branch information
achow101 committed Apr 23, 2024
2 parents 4aa18ce + e30e862 commit 7c17f20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
8 changes: 5 additions & 3 deletions test/functional/p2p_disconnect_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def run_test(self):
self.nodes[1].setmocktime(old_time)
self.nodes[1].setban("127.0.0.0/32", "add")
self.nodes[1].setban("127.0.0.0/24", "add")
self.nodes[1].setban("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion", "add")
self.nodes[1].setban("192.168.0.1", "add", 1) # ban for 1 seconds
self.nodes[1].setban("2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19", "add", 1000) # ban for 1000 seconds
listBeforeShutdown = self.nodes[1].listbanned()
Expand All @@ -85,13 +86,13 @@ def run_test(self):
self.log.info("setban: test banning with absolute timestamp")
self.nodes[1].setban("192.168.0.2", "add", old_time + 120, True)

# Move time forward by 3 seconds so the third ban has expired
# Move time forward by 3 seconds so the fourth ban has expired
self.nodes[1].setmocktime(old_time + 3)
assert_equal(len(self.nodes[1].listbanned()), 4)
assert_equal(len(self.nodes[1].listbanned()), 5)

self.log.info("Test ban_duration and time_remaining")
for ban in self.nodes[1].listbanned():
if ban["address"] in ["127.0.0.0/32", "127.0.0.0/24"]:
if ban["address"] in ["127.0.0.0/32", "127.0.0.0/24", "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"]:
assert_equal(ban["ban_duration"], 86400)
assert_equal(ban["time_remaining"], 86397)
elif ban["address"] == "2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19":
Expand All @@ -108,6 +109,7 @@ def run_test(self):
assert_equal("127.0.0.0/32", listAfterShutdown[1]['address'])
assert_equal("192.168.0.2/32", listAfterShutdown[2]['address'])
assert_equal("/19" in listAfterShutdown[3]['address'], True)
assert_equal("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion", listAfterShutdown[4]['address'])

# Clear ban lists
self.nodes[1].clearbanned()
Expand Down
10 changes: 0 additions & 10 deletions test/functional/rpc_setban.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,10 @@ def run_test(self):
assert self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)

self.log.info("Test the ban list is preserved through restart")

self.restart_node(1)
assert self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)

node.setban(tor_addr, "remove")
assert not self.is_banned(self.nodes[1], tor_addr)
assert not self.is_banned(node, ip_addr)

self.restart_node(1)
assert not self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)

self.log.info("Test -bantime")
self.restart_node(1, ["-bantime=1234"])
self.nodes[1].setban("127.0.0.1", "add")
Expand Down

0 comments on commit 7c17f20

Please sign in to comment.