LCOV - code coverage report
Current view: top level - src/test - merkleblock_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 34 34 100.0 %
Date: 2020-09-26 01:30:44 Functions: 16 16 100.0 %

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

Generated by: LCOV version 1.15