5#include <test/data/blockfilters.json.h>
8#include <blockfilter.h>
17#include <boost/test/unit_test.hpp>
19BOOST_AUTO_TEST_SUITE(blockfilter_tests)
24 for (
int i = 0; i < 100; ++i) {
27 included_elements.insert(std::move(element1));
31 excluded_elements.insert(std::move(element2));
34 GCSFilter filter({0, 0, 10, 1 << 10}, included_elements);
35 for (
const auto& element : included_elements) {
38 auto insertion = excluded_elements.insert(element);
40 excluded_elements.erase(insertion.first);
59 CScript included_scripts[5], excluded_scripts[4];
62 included_scripts[0] << std::vector<unsigned char>(0, 65) <<
OP_CHECKSIG;
69 included_scripts[3] << OP_0 << std::vector<unsigned char>(3, 32);
73 excluded_scripts[0] << OP_RETURN << std::vector<unsigned char>(4, 40);
76 excluded_scripts[1] << std::vector<unsigned char>(5, 33) <<
OP_CHECKSIG;
83 tx_1.
vout.emplace_back(100, included_scripts[0]);
84 tx_1.
vout.emplace_back(200, included_scripts[1]);
85 tx_1.
vout.emplace_back(0, excluded_scripts[0]);
88 tx_2.
vout.emplace_back(300, included_scripts[2]);
89 tx_2.
vout.emplace_back(0, excluded_scripts[2]);
90 tx_2.
vout.emplace_back(400, excluded_scripts[3]);
97 block_undo.
vtxundo.emplace_back();
98 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(500, included_scripts[3]), 1000,
true);
99 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(600, included_scripts[4]), 10000,
false);
100 block_undo.
vtxundo.back().vprevout.emplace_back(
CTxOut(700, excluded_scripts[3]), 100000,
false);
116 stream << block_filter;
117 stream >> block_filter2;
133 if (!
json.read(json_tests::blockfilters) || !
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;
151 test[pos++].
getInt<
int>();
155 BOOST_REQUIRE(
DecodeHexBlk(block, test[pos++].get_str()));
158 block_undo.
vtxundo.emplace_back();
161 for (
unsigned int ii = 0; ii < prev_scripts.
size(); ii++) {
162 std::vector<unsigned char> raw_script =
ParseHex(prev_scripts[ii].get_str());
163 CTxOut txout(0,
CScript(raw_script.begin(), raw_script.end()));
164 tx_undo.
vprevout.emplace_back(txout, 0,
false);
168 std::vector<unsigned char> filter_basic =
ParseHex(test[pos++].get_str());
175 BOOST_CHECK(computed_header_basic == filter_header_basic);
const std::string & BlockFilterTypeName(BlockFilterType filter_type)
Get the human-readable name for a filter type.
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
BOOST_AUTO_TEST_CASE(gcsfilter_test)
#define Assert(val)
Identity function.
Complete block filter struct as defined in BIP 157.
const uint256 & GetBlockHash() const LIFETIMEBOUND
const std::vector< unsigned char > & GetEncodedFilter() const LIFETIMEBOUND
uint256 ComputeHeader(const uint256 &prev_header) const
Compute the filter header given the previous one.
const GCSFilter & GetFilter() const LIFETIMEBOUND
BlockFilterType GetFilterType() const
std::vector< CTransactionRef > vtx
Undo information for a CBlock.
std::vector< CTxUndo > vtxundo
Serialized script, used inside transaction inputs and outputs.
An output of a transaction.
Undo information for a CTransaction.
std::vector< Coin > vprevout
Double ended buffer combining vector and stream-like interfaces.
This implements a Golomb-coded set as defined in BIP 158.
std::vector< unsigned char > Element
std::unordered_set< Element, ByteVectorHash > ElementSet
const Params & GetParams() const LIFETIMEBOUND
bool Match(const Element &element) const
Checks if the element may be in the set.
const std::vector< unsigned char > & GetEncoded() const LIFETIMEBOUND
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const UniValue & get_array() const
static std::optional< uint256 > FromHex(std::string_view str)
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
BOOST_AUTO_TEST_SUITE_END()
char const * json() noexcept
Template to generate JSON data.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
A mutable version of CTransaction.
std::vector< CTxOut > vout
uint32_t m_M
Inverse false positive rate.
uint8_t m_P
Golomb-Rice coding parameter.