Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2021-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <banman.h>6#include <chainparams.h>7#include <netbase.h>8#include <streams.h>9#include <test/util/logging.h>10#include <test/util/setup_common.h>11#include <test/util/time.h>12#include <util/readwritefile.h>14#include <boost/test/unit_test.hpp>16BOOST_FIXTURE_TEST_SUITE(banman_tests, BasicTestingSetup)18BOOST_AUTO_TEST_CASE(file)19{20FakeNodeClock clock{777s};21const fs::path banlist_path{m_args.GetDataDirBase() / "banlist_test"};22{23const std::string entries_write{24"{ \"banned_nets\": ["25" { \"version\": 1, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"aaaaaaaaa\" },"26" { \"version\": 2, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"bbbbbbbbb\" },"27" { \"version\": 1, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"1.0.0.0/8\" }"28"] }",29};30BOOST_REQUIRE(WriteBinaryFile(banlist_path + ".json", entries_write));31{32// The invalid entries will be dropped, but the valid one remains33ASSERT_DEBUG_LOG("Dropping entry with unparseable address or subnet (aaaaaaaaa) from ban list");34ASSERT_DEBUG_LOG("Dropping entry with unknown version (2) from ban list");35BanMan banman{banlist_path, /*client_interface=*/nullptr, /*default_ban_time=*/0};36banmap_t entries_read;37banman.GetBanned(entries_read);38BOOST_CHECK_EQUAL(entries_read.size(), 1);39}40}41}43BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.