Merge bitcoin/bitcoin#26794: test: test banlist database recreation

4bdcf57158 test: test banlist database recreation (brunoerg)

Pull request description:

  This PR adds test coverage for 'banlist database recreation'. If it wasn't able to read ban db (in `LoadBanlist`), so it should create a new (an empty, ofc) one.
  d8bdee0fc8/src/banman.cpp (L28-L45)

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 4bdcf57158

Tree-SHA512: d9d0cd0c4b3797189dff00d3a634878188e7cf51e78346601fc97e2bf78c495561705214062bb42ab8e491e0d111f8bfcf74dbc801768bc02cf2b45f162aad85
This commit is contained in:
fanquake 2023-04-27 10:06:34 +01:00
commit 03cb2fce4a
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test node disconnect and ban behavior"""
import time
from pathlib import Path
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
@ -36,6 +37,17 @@ class DisconnectBanTest(BitcoinTestFramework):
self.log.info("clearbanned: successfully clear ban list")
self.nodes[1].clearbanned()
assert_equal(len(self.nodes[1].listbanned()), 0)
self.log.info('Test banlist database recreation')
self.stop_node(1)
target_file = self.nodes[1].chain_path / "banlist.json"
Path.unlink(target_file)
with self.nodes[1].assert_debug_log(["Recreating the banlist database"]):
self.start_node(1)
assert Path.exists(target_file)
assert_equal(self.nodes[1].listbanned(), [])
self.nodes[1].setban("127.0.0.0/24", "add")
self.log.info("setban: fail to ban an already banned subnet")