Merge #14172: Refactor and add tests for BlockFilter construction

e4ed8ce2c8 blockfilter: Remove default clause in switch statement. (Jim Posen)
c30620983d blockfilter: Additional constructors for BlockFilter. (Jim Posen)
20b812993a blockfilter: Refactor GCS params into struct. (Jim Posen)

Pull request description:

  These commits have been split out of #14121 because they are fairly independent and that PR is very large.

Tree-SHA512: b9643b159e114df50a295f433e807afe6082db55a2a3a17401c1509b850c71bf5011ab3638863b46663709726be4445be6fde1dec514aec7696135497a9f0183
This commit is contained in:
MarcoFalke
2018-12-22 14:16:30 +01:00
4 changed files with 99 additions and 49 deletions

View File

@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(gcsfilter_test)
excluded_elements.insert(std::move(element2));
}
GCSFilter filter(0, 0, 10, 1 << 10, included_elements);
GCSFilter filter({0, 0, 10, 1 << 10}, included_elements);
for (const auto& element : included_elements) {
BOOST_CHECK(filter.Match(element));
@@ -39,6 +39,19 @@ BOOST_AUTO_TEST_CASE(gcsfilter_test)
}
}
BOOST_AUTO_TEST_CASE(gcsfilter_default_constructor)
{
GCSFilter filter;
BOOST_CHECK_EQUAL(filter.GetN(), 0);
BOOST_CHECK_EQUAL(filter.GetEncoded().size(), 1);
const GCSFilter::Params& params = filter.GetParams();
BOOST_CHECK_EQUAL(params.m_siphash_k0, 0);
BOOST_CHECK_EQUAL(params.m_siphash_k1, 0);
BOOST_CHECK_EQUAL(params.m_P, 0);
BOOST_CHECK_EQUAL(params.m_M, 1);
}
BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
{
CScript included_scripts[5], excluded_scripts[3];
@@ -88,6 +101,17 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
for (const CScript& script : excluded_scripts) {
BOOST_CHECK(!filter.Match(GCSFilter::Element(script.begin(), script.end())));
}
// Test serialization/unserialization.
BlockFilter block_filter2;
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
stream << block_filter;
stream >> block_filter2;
BOOST_CHECK_EQUAL(block_filter.GetFilterType(), block_filter2.GetFilterType());
BOOST_CHECK_EQUAL(block_filter.GetBlockHash(), block_filter2.GetBlockHash());
BOOST_CHECK(block_filter.GetEncodedFilter() == block_filter2.GetEncodedFilter());
}
BOOST_AUTO_TEST_CASE(blockfilters_json_test)