diff options
author | Jim Posen <jimpo@coinbase.com> | 2018-01-23 17:13:04 -0800 |
---|---|---|
committer | Jim Posen <jim.posen@gmail.com> | 2018-08-25 10:02:37 -0700 |
commit | 53e7874e079f9ddfe8b176f11d46e6b59c7283d5 (patch) | |
tree | a27a83b09fac2b81380dc68d3b33fcc4a423eec8 /src/test/blockfilter_tests.cpp | |
parent | 558c536e35a25594881693e6ff01d275c88d7af1 (diff) | |
download | bitcoin-53e7874e079f9ddfe8b176f11d46e6b59c7283d5.tar.xz |
blockfilter: Simple test for GCSFilter construction and Match.
Diffstat (limited to 'src/test/blockfilter_tests.cpp')
-rw-r--r-- | src/test/blockfilter_tests.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp new file mode 100644 index 0000000000..339a7fcfeb --- /dev/null +++ b/src/test/blockfilter_tests.cpp @@ -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() |