5 #include <test/data/blockfilters.json.h>
8 #include <blockfilter.h>
15 #include <boost/test/unit_test.hpp>
22 for (
int i = 0; i < 100; ++i) {
25 included_elements.insert(std::move(element1));
29 excluded_elements.insert(std::move(element2));
32 GCSFilter filter({0, 0, 10, 1 << 10}, included_elements);
33 for (
const auto& element : included_elements) {
36 auto insertion = excluded_elements.insert(element);
38 excluded_elements.erase(insertion.first);
57 CScript included_scripts[5], excluded_scripts[4];
60 included_scripts[0] << std::vector<unsigned char>(0, 65) <<
OP_CHECKSIG;
67 included_scripts[3] << OP_0 << std::vector<unsigned char>(3, 32);
71 excluded_scripts[0] << OP_RETURN << std::vector<unsigned char>(4, 40);
74 excluded_scripts[1] << std::vector<unsigned char>(5, 33) <<
OP_CHECKSIG;
81 tx_1.
vout.emplace_back(100, included_scripts[0]);
82 tx_1.
vout.emplace_back(200, included_scripts[1]);
83 tx_1.
vout.emplace_back(0, excluded_scripts[0]);
86 tx_2.
vout.emplace_back(300, included_scripts[2]);
87 tx_2.
vout.emplace_back(0, excluded_scripts[2]);
88 tx_2.
vout.emplace_back(400, excluded_scripts[3]);
95 block_undo.
vtxundo.emplace_back();
96 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(500, included_scripts[3]), 1000,
true);
97 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(600, included_scripts[4]), 10000,
false);
98 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(700, excluded_scripts[3]), 100000,
false);
103 for (
const CScript& script : included_scripts) {
106 for (
const CScript& script : excluded_scripts) {
114 stream << block_filter;
115 stream >> block_filter2;
119 BOOST_CHECK(block_filter.GetEncodedFilter() == block_filter2.GetEncodedFilter());
131 std::string json_data(json_tests::blockfilters,
132 json_tests::blockfilters +
sizeof(json_tests::blockfilters));
133 if (!
json.read(json_data) || !
json.isArray()) {
134 BOOST_ERROR(
"Parse error.");
139 for (
unsigned int i = 0; i < tests.
size(); i++) {
141 std::string strTest = test.
write();
143 if (test.
size() == 1) {
145 }
else if (test.
size() < 7) {
146 BOOST_ERROR(
"Bad test: " << strTest);
150 unsigned int pos = 0;
156 BOOST_REQUIRE(
DecodeHexBlk(block, test[pos++].get_str()));
159 block_undo.
vtxundo.emplace_back();
162 for (
unsigned int ii = 0; ii < prev_scripts.
size(); ii++) {
163 std::vector<unsigned char> raw_script =
ParseHex(prev_scripts[ii].get_str());
164 CTxOut txout(0,
CScript(raw_script.begin(), raw_script.end()));
165 tx_undo.
vprevout.emplace_back(txout, 0,
false);
168 uint256 prev_filter_header_basic;
170 std::vector<unsigned char> filter_basic =
ParseHex(test[pos++].get_str());
178 BOOST_CHECK(computed_header_basic == filter_header_basic);