Skip to content

Commit 53e7874

Browse files
Jim Posenjimpo
authored andcommitted
blockfilter: Simple test for GCSFilter construction and Match.
1 parent 558c536 commit 53e7874

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ BITCOIN_TESTS =\
3939
test/bip32_tests.cpp \
4040
test/blockchain_tests.cpp \
4141
test/blockencodings_tests.cpp \
42+
test/blockfilter_tests.cpp \
4243
test/bloom_tests.cpp \
4344
test/bswap_tests.cpp \
4445
test/checkqueue_tests.cpp \

src/test/blockfilter_tests.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2018 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 <blockfilter.h>
6+
7+
#include <boost/test/unit_test.hpp>
8+
9+
BOOST_AUTO_TEST_SUITE(blockfilter_tests)
10+
11+
BOOST_AUTO_TEST_CASE(gcsfilter_test)
12+
{
13+
GCSFilter::ElementSet included_elements, excluded_elements;
14+
for (int i = 0; i < 100; ++i) {
15+
GCSFilter::Element element1(32);
16+
element1[0] = i;
17+
included_elements.insert(std::move(element1));
18+
19+
GCSFilter::Element element2(32);
20+
element2[1] = i;
21+
excluded_elements.insert(std::move(element2));
22+
}
23+
24+
GCSFilter filter(0, 0, 10, 1 << 10, included_elements);
25+
for (const auto& element : included_elements) {
26+
BOOST_CHECK(filter.Match(element));
27+
28+
auto insertion = excluded_elements.insert(element);
29+
BOOST_CHECK(filter.MatchAny(excluded_elements));
30+
excluded_elements.erase(insertion.first);
31+
}
32+
}
33+
34+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)