LCOV - code coverage report
Current view: top level - src/test - merkleblock_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 27 27 100.0 %
Date: 2025-02-23 09:33:43 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2012-2017 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 "uint256.h"
       7             : #include "test/test_pivx.h"
       8             : #include "test/util/blocksutil.h"
       9             : 
      10             : #include <boost/test/unit_test.hpp>
      11             : 
      12             : 
      13             : BOOST_FIXTURE_TEST_SUITE(merkleblock_tests, BasicTestingSetup)
      14             : 
      15             : /**
      16             :  * Create a CMerkleBlock using a list of txids which will be found in the
      17             :  * given block.
      18             :  */
      19           2 : BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)
      20             : {
      21           1 :     CBlock block = getBlock13b8a();
      22             : 
      23           2 :     std::set<uint256> txids;
      24             : 
      25             :     // Last txn in block.
      26           1 :     uint256 txhash1 = uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20");
      27             : 
      28             :     // Second txn in block.
      29           1 :     uint256 txhash2 = uint256S("0xf9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07");
      30             : 
      31           1 :     txids.insert(txhash1);
      32           1 :     txids.insert(txhash2);
      33             : 
      34           2 :     CMerkleBlock merkleBlock(block, txids);
      35             : 
      36           3 :     BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
      37             : 
      38             :     // vMatchedTxn is only used when bloom filter is specified.
      39           1 :     BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
      40             : 
      41           2 :     std::vector<uint256> vMatched;
      42             : 
      43           3 :     BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched).GetHex(), block.hashMerkleRoot.GetHex());
      44           1 :     BOOST_CHECK_EQUAL(vMatched.size(), 2);
      45             : 
      46             :     // Ordered by occurrence in depth-first tree traversal.
      47           3 :     BOOST_CHECK_EQUAL(vMatched[0].ToString(), txhash2.ToString());
      48             : 
      49           3 :     BOOST_CHECK_EQUAL(vMatched[1].ToString(), txhash1.ToString());
      50           1 : }
      51             : 
      52             : 
      53             : /**
      54             :  * Create a CMerkleBlock using a list of txids which will not be found in the
      55             :  * given block.
      56             :  */
      57           2 : BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_not_found)
      58             : {
      59           1 :     CBlock block = getBlock13b8a();
      60             : 
      61           2 :     std::set<uint256> txids2;
      62           2 :     txids2.insert(uint256S("0xc0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
      63           2 :     CMerkleBlock merkleBlock(block, txids2);
      64             : 
      65           3 :     BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
      66           1 :     BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
      67             : 
      68           2 :     std::vector<uint256> vMatched;
      69             : 
      70           3 :     BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched).GetHex(), block.hashMerkleRoot.GetHex());
      71           1 :     BOOST_CHECK_EQUAL(vMatched.size(), 0);
      72           1 : }
      73             : 
      74             : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.14