Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
merkleblock_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2012-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <merkleblock.h>
6#include <test/util/common.h>
8#include <uint256.h>
9
10#include <boost/test/unit_test.hpp>
11
12#include <set>
13#include <vector>
14
16
17
22{
23 CBlock block = getBlock13b8a();
24
25 std::set<Txid> txids;
26
27 // Last txn in block.
28 constexpr Txid txhash1{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"};
29
30 // Second txn in block.
31 constexpr Txid txhash2{"f9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07"};
32
33 txids.insert(txhash1);
34 txids.insert(txhash2);
35
36 CMerkleBlock merkleBlock(block, txids);
37
38 BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
39
40 // vMatchedTxn is only used when bloom filter is specified.
41 BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0U);
42
43 std::vector<Txid> vMatched;
44 std::vector<unsigned int> vIndex;
45
46 BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
47 BOOST_CHECK_EQUAL(vMatched.size(), 2U);
48
49 // Ordered by occurrence in depth-first tree traversal.
52
55}
56
57
63{
64 CBlock block = getBlock13b8a();
65
66 std::set<Txid> txids2;
67 txids2.insert(Txid{"c0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"});
69
70 BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
71 BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0U);
72
73 std::vector<Txid> vMatched;
74 std::vector<unsigned int> vIndex;
75
76 BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
78 BOOST_CHECK_EQUAL(vIndex.size(), 0U);
79}
80
uint256 hashMerkleRoot
Definition block.h:32
uint256 GetHash() const
Definition block.cpp:15
Definition block.h:74
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
std::string GetHex() const
Definition uint256.cpp:11
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)
Create a CMerkleBlock using a list of txids which will be found in the given block.
#define BOOST_CHECK_EQUAL(v1, v2)
Definition object.cpp:17
CBlock getBlock13b8a()
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73