mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
blockfilter: Simple test for GCSFilter construction and Match.
This commit is contained in:
parent
558c536e35
commit
53e7874e07
2 changed files with 35 additions and 0 deletions
|
@ -39,6 +39,7 @@ BITCOIN_TESTS =\
|
||||||
test/bip32_tests.cpp \
|
test/bip32_tests.cpp \
|
||||||
test/blockchain_tests.cpp \
|
test/blockchain_tests.cpp \
|
||||||
test/blockencodings_tests.cpp \
|
test/blockencodings_tests.cpp \
|
||||||
|
test/blockfilter_tests.cpp \
|
||||||
test/bloom_tests.cpp \
|
test/bloom_tests.cpp \
|
||||||
test/bswap_tests.cpp \
|
test/bswap_tests.cpp \
|
||||||
test/checkqueue_tests.cpp \
|
test/checkqueue_tests.cpp \
|
||||||
|
|
34
src/test/blockfilter_tests.cpp
Normal file
34
src/test/blockfilter_tests.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) 2018 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <blockfilter.h>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(blockfilter_tests)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(gcsfilter_test)
|
||||||
|
{
|
||||||
|
GCSFilter::ElementSet included_elements, excluded_elements;
|
||||||
|
for (int i = 0; i < 100; ++i) {
|
||||||
|
GCSFilter::Element element1(32);
|
||||||
|
element1[0] = i;
|
||||||
|
included_elements.insert(std::move(element1));
|
||||||
|
|
||||||
|
GCSFilter::Element element2(32);
|
||||||
|
element2[1] = i;
|
||||||
|
excluded_elements.insert(std::move(element2));
|
||||||
|
}
|
||||||
|
|
||||||
|
GCSFilter filter(0, 0, 10, 1 << 10, included_elements);
|
||||||
|
for (const auto& element : included_elements) {
|
||||||
|
BOOST_CHECK(filter.Match(element));
|
||||||
|
|
||||||
|
auto insertion = excluded_elements.insert(element);
|
||||||
|
BOOST_CHECK(filter.MatchAny(excluded_elements));
|
||||||
|
excluded_elements.erase(insertion.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in a new issue