Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockfilter_tests.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(gcsfilter_default_constructor) { | ||||
const GCSFilter::Params ¶ms = filter.GetParams(); | const GCSFilter::Params ¶ms = filter.GetParams(); | ||||
BOOST_CHECK_EQUAL(params.m_siphash_k0, 0); | BOOST_CHECK_EQUAL(params.m_siphash_k0, 0); | ||||
BOOST_CHECK_EQUAL(params.m_siphash_k1, 0); | BOOST_CHECK_EQUAL(params.m_siphash_k1, 0); | ||||
BOOST_CHECK_EQUAL(params.m_P, 0); | BOOST_CHECK_EQUAL(params.m_P, 0); | ||||
BOOST_CHECK_EQUAL(params.m_M, 1); | BOOST_CHECK_EQUAL(params.m_M, 1); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(blockfilter_basic_test) { | BOOST_AUTO_TEST_CASE(blockfilter_basic_test) { | ||||
CScript included_scripts[5], excluded_scripts[3]; | CScript included_scripts[5], excluded_scripts[4]; | ||||
// First two are outputs on a single transaction. | // First two are outputs on a single transaction. | ||||
included_scripts[0] << std::vector<uint8_t>(0, 65) << OP_CHECKSIG; | included_scripts[0] << std::vector<uint8_t>(0, 65) << OP_CHECKSIG; | ||||
included_scripts[1] << OP_DUP << OP_HASH160 << std::vector<uint8_t>(1, 20) | included_scripts[1] << OP_DUP << OP_HASH160 << std::vector<uint8_t>(1, 20) | ||||
<< OP_EQUALVERIFY << OP_CHECKSIG; | << OP_EQUALVERIFY << OP_CHECKSIG; | ||||
// Third is an output on in a second transaction. | // Third is an output on in a second transaction. | ||||
included_scripts[2] << OP_1 << std::vector<uint8_t>(2, 33) << OP_1 | included_scripts[2] << OP_1 << std::vector<uint8_t>(2, 33) << OP_1 | ||||
<< OP_CHECKMULTISIG; | << OP_CHECKMULTISIG; | ||||
// Last two are spent by a single transaction. | // Last two are spent by a single transaction. | ||||
included_scripts[3] << OP_0 << std::vector<uint8_t>(3, 32); | included_scripts[3] << OP_0 << std::vector<uint8_t>(3, 32); | ||||
included_scripts[4] << OP_4 << OP_ADD << OP_8 << OP_EQUAL; | included_scripts[4] << OP_4 << OP_ADD << OP_8 << OP_EQUAL; | ||||
// OP_RETURN output is an output on the second transaction. | // OP_RETURN output is an output on the second transaction. | ||||
excluded_scripts[0] << OP_RETURN << std::vector<uint8_t>(4, 40); | excluded_scripts[0] << OP_RETURN << std::vector<uint8_t>(4, 40); | ||||
// This script is not related to the block at all. | // This script is not related to the block at all. | ||||
excluded_scripts[1] << std::vector<uint8_t>(5, 33) << OP_CHECKSIG; | excluded_scripts[1] << std::vector<uint8_t>(5, 33) << OP_CHECKSIG; | ||||
// OP_RETURN is non-standard since it's not followed by a data push, but is | |||||
// still excluded from filter. | |||||
excluded_scripts[2] << OP_RETURN << OP_4 << OP_ADD << OP_8 << OP_EQUAL; | |||||
CMutableTransaction tx_1; | CMutableTransaction tx_1; | ||||
tx_1.vout.emplace_back(100 * SATOSHI, included_scripts[0]); | tx_1.vout.emplace_back(100 * SATOSHI, included_scripts[0]); | ||||
tx_1.vout.emplace_back(200 * SATOSHI, included_scripts[1]); | tx_1.vout.emplace_back(200 * SATOSHI, included_scripts[1]); | ||||
tx_1.vout.emplace_back(0 * SATOSHI, excluded_scripts[0]); | |||||
CMutableTransaction tx_2; | CMutableTransaction tx_2; | ||||
tx_2.vout.emplace_back(300 * SATOSHI, included_scripts[2]); | tx_2.vout.emplace_back(300 * SATOSHI, included_scripts[2]); | ||||
tx_2.vout.emplace_back(0 * SATOSHI, excluded_scripts[0]); | tx_2.vout.emplace_back(0 * SATOSHI, excluded_scripts[2]); | ||||
// Script is empty | // Script is empty | ||||
tx_2.vout.emplace_back(400 * SATOSHI, excluded_scripts[2]); | tx_2.vout.emplace_back(400 * SATOSHI, excluded_scripts[3]); | ||||
CBlock block; | CBlock block; | ||||
block.vtx.push_back(MakeTransactionRef(tx_1)); | block.vtx.push_back(MakeTransactionRef(tx_1)); | ||||
block.vtx.push_back(MakeTransactionRef(tx_2)); | block.vtx.push_back(MakeTransactionRef(tx_2)); | ||||
CBlockUndo block_undo; | CBlockUndo block_undo; | ||||
block_undo.vtxundo.emplace_back(); | block_undo.vtxundo.emplace_back(); | ||||
block_undo.vtxundo.back().vprevout.emplace_back( | block_undo.vtxundo.back().vprevout.emplace_back( | ||||
CTxOut(500 * SATOSHI, included_scripts[3]), 1000, true); | CTxOut(500 * SATOSHI, included_scripts[3]), 1000, true); | ||||
block_undo.vtxundo.back().vprevout.emplace_back( | block_undo.vtxundo.back().vprevout.emplace_back( | ||||
CTxOut(600 * SATOSHI, included_scripts[4]), 10000, false); | CTxOut(600 * SATOSHI, included_scripts[4]), 10000, false); | ||||
block_undo.vtxundo.back().vprevout.emplace_back( | block_undo.vtxundo.back().vprevout.emplace_back( | ||||
CTxOut(700 * SATOSHI, excluded_scripts[2]), 100000, false); | CTxOut(700 * SATOSHI, excluded_scripts[3]), 100000, false); | ||||
BlockFilter block_filter(BlockFilterType::BASIC, block, block_undo); | BlockFilter block_filter(BlockFilterType::BASIC, block, block_undo); | ||||
const GCSFilter &filter = block_filter.GetFilter(); | const GCSFilter &filter = block_filter.GetFilter(); | ||||
for (const CScript &script : included_scripts) { | for (const CScript &script : included_scripts) { | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
filter.Match(GCSFilter::Element(script.begin(), script.end()))); | filter.Match(GCSFilter::Element(script.begin(), script.end()))); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |