Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2012-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <merkleblock.h>6#include <test/util/common.h>7#include <test/util/setup_common.h>8#include <uint256.h>10#include <boost/test/unit_test.hpp>12#include <set>13#include <vector>15BOOST_AUTO_TEST_SUITE(merkleblock_tests)17/**18* Create a CMerkleBlock using a list of txids which will be found in the19* given block.20*/21BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)22{23CBlock block = getBlock13b8a();25std::set<Txid> txids;27// Last txn in block.28constexpr Txid txhash1{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"};30// Second txn in block.31constexpr Txid txhash2{"f9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07"};33txids.insert(txhash1);34txids.insert(txhash2);36CMerkleBlock merkleBlock(block, txids);38BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());40// vMatchedTxn is only used when bloom filter is specified.41BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0U);43std::vector<Txid> vMatched;44std::vector<unsigned int> vIndex;46BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());47BOOST_CHECK_EQUAL(vMatched.size(), 2U);49// Ordered by occurrence in depth-first tree traversal.50BOOST_CHECK_EQUAL(vMatched[0], txhash2);51BOOST_CHECK_EQUAL(vIndex[0], 1U);53BOOST_CHECK_EQUAL(vMatched[1], txhash1);54BOOST_CHECK_EQUAL(vIndex[1], 8U);55}58/**59* Create a CMerkleBlock using a list of txids which will not be found in the60* given block.61*/62BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_not_found)63{64CBlock block = getBlock13b8a();66std::set<Txid> txids2;67txids2.insert(Txid{"c0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"});68CMerkleBlock merkleBlock(block, txids2);70BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());71BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0U);73std::vector<Txid> vMatched;74std::vector<unsigned int> vIndex;76BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());77BOOST_CHECK_EQUAL(vMatched.size(), 0U);78BOOST_CHECK_EQUAL(vIndex.size(), 0U);79}81BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.