|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
| 5 | +#include <test/test_bitcoin.h> |
| 6 | + |
5 | 7 | #include <blockfilter.h>
|
| 8 | +#include <serialize.h> |
| 9 | +#include <streams.h> |
6 | 10 |
|
7 | 11 | #include <boost/test/unit_test.hpp>
|
8 | 12 |
|
@@ -31,4 +35,53 @@ BOOST_AUTO_TEST_CASE(gcsfilter_test)
|
31 | 35 | }
|
32 | 36 | }
|
33 | 37 |
|
| 38 | +BOOST_AUTO_TEST_CASE(blockfilter_basic_test) |
| 39 | +{ |
| 40 | + CScript included_scripts[5], excluded_scripts[2]; |
| 41 | + |
| 42 | + // First two are outputs on a single transaction. |
| 43 | + included_scripts[0] << std::vector<unsigned char>(0, 65) << OP_CHECKSIG; |
| 44 | + included_scripts[1] << OP_DUP << OP_HASH160 << std::vector<unsigned char>(1, 20) << OP_EQUALVERIFY << OP_CHECKSIG; |
| 45 | + |
| 46 | + // Third is an output on in a second transaction. |
| 47 | + included_scripts[2] << OP_1 << std::vector<unsigned char>(2, 33) << OP_1 << OP_CHECKMULTISIG; |
| 48 | + |
| 49 | + // Last two are spent by a single transaction. |
| 50 | + included_scripts[3] << OP_0 << std::vector<unsigned char>(3, 32); |
| 51 | + included_scripts[4] << OP_4 << OP_ADD << OP_8 << OP_EQUAL; |
| 52 | + |
| 53 | + // OP_RETURN output is an output on the second transaction. |
| 54 | + excluded_scripts[0] << OP_RETURN << std::vector<unsigned char>(4, 40); |
| 55 | + |
| 56 | + // This script is not related to the block at all. |
| 57 | + excluded_scripts[1] << std::vector<unsigned char>(5, 33) << OP_CHECKSIG; |
| 58 | + |
| 59 | + CMutableTransaction tx_1; |
| 60 | + tx_1.vout.emplace_back(100, included_scripts[0]); |
| 61 | + tx_1.vout.emplace_back(200, included_scripts[1]); |
| 62 | + |
| 63 | + CMutableTransaction tx_2; |
| 64 | + tx_2.vout.emplace_back(300, included_scripts[2]); |
| 65 | + tx_2.vout.emplace_back(0, excluded_scripts[0]); |
| 66 | + |
| 67 | + CBlock block; |
| 68 | + block.vtx.push_back(MakeTransactionRef(tx_1)); |
| 69 | + block.vtx.push_back(MakeTransactionRef(tx_2)); |
| 70 | + |
| 71 | + CBlockUndo block_undo; |
| 72 | + block_undo.vtxundo.emplace_back(); |
| 73 | + block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(400, included_scripts[3]), 1000, true); |
| 74 | + block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(500, included_scripts[4]), 10000, false); |
| 75 | + |
| 76 | + BlockFilter block_filter(BlockFilterType::BASIC, block, block_undo); |
| 77 | + const GCSFilter& filter = block_filter.GetFilter(); |
| 78 | + |
| 79 | + for (const CScript& script : included_scripts) { |
| 80 | + BOOST_CHECK(filter.Match(GCSFilter::Element(script.begin(), script.end()))); |
| 81 | + } |
| 82 | + for (const CScript& script : excluded_scripts) { |
| 83 | + BOOST_CHECK(!filter.Match(GCSFilter::Element(script.begin(), script.end()))); |
| 84 | + } |
| 85 | +} |
| 86 | + |
34 | 87 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments