Bitcoin Core
31.99.0
P2P Digital Currency
src
test
banman_tests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2021-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
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
>
13
14
#include <boost/test/unit_test.hpp>
15
16
BOOST_FIXTURE_TEST_SUITE
(banman_tests,
BasicTestingSetup
)
17
18
BOOST_AUTO_TEST_CASE
(file)
19
{
20
NodeClockContext
clock_ctx{777
s
};
21
const
fs::path banlist_path{m_args.GetDataDirBase() /
"banlist_test"
};
22
{
23
const
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
};
30
BOOST_REQUIRE(
WriteBinaryFile
(banlist_path +
".json"
, entries_write));
31
{
32
// The invalid entries will be dropped, but the valid one remains
33
ASSERT_DEBUG_LOG
(
"Dropping entry with unparseable address or subnet (aaaaaaaaa) from ban list"
);
34
ASSERT_DEBUG_LOG
(
"Dropping entry with unknown version (2) from ban list"
);
35
BanMan
banman{banlist_path,
/*client_interface=*/
nullptr
,
/*default_ban_time=*/
0};
36
banmap_t
entries_read;
37
banman.
GetBanned
(entries_read);
38
BOOST_CHECK_EQUAL
(entries_read.size(), 1);
39
}
40
}
41
}
42
43
BOOST_AUTO_TEST_SUITE_END
()
banman.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(file)
Definition:
banman_tests.cpp:18
BanMan
Definition:
banman.h:64
BanMan::GetBanned
void GetBanned(banmap_t &banmap) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
Definition:
banman.cpp:174
NodeClockContext
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition:
time.h:40
BOOST_FIXTURE_TEST_SUITE
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
test_vectors_musig2_generate.s
tuple s
Definition:
test_vectors_musig2_generate.py:72
banmap_t
std::map< CSubNet, CBanEntry > banmap_t
Definition:
net_types.h:41
netbase.h
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition:
object.cpp:17
WriteBinaryFile
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
Write contents of std::string to a file.
Definition:
readwritefile.cpp:36
readwritefile.h
setup_common.h
streams.h
BasicTestingSetup
Basic testing setup.
Definition:
setup_common.h:61
logging.h
ASSERT_DEBUG_LOG
#define ASSERT_DEBUG_LOG(message)
Definition:
logging.h:42
time.h
Generated on Wed Apr 15 2026 20:00:29 for Bitcoin Core by
1.9.4