Use unique_ptr for pdbCopy (Db) and fix potential memory leak
[bitcoinplatinum.git] / src / test / merkleblock_tests.cpp
blob3e66c6f2c66276c6fc2e1daee0604c42132d9560
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.
5 #include "merkleblock.h"
6 #include "uint256.h"
7 #include "test/test_bitcoin.h"
9 #include <boost/test/unit_test.hpp>
12 BOOST_FIXTURE_TEST_SUITE(merkleblock_tests, BasicTestingSetup)
14 /**
15 * Create a CMerkleBlock using a list of txids which will be found in the
16 * given block.
18 BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)
20 CBlock block = getBlock13b8a();
22 std::set<uint256> txids;
24 // Last txn in block.
25 uint256 txhash1 = uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20");
27 // Second txn in block.
28 uint256 txhash2 = uint256S("0xf9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07");
30 txids.insert(txhash1);
31 txids.insert(txhash2);
33 CMerkleBlock merkleBlock(block, txids);
35 BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
37 // vMatchedTxn is only used when bloom filter is specified.
38 BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
40 std::vector<uint256> vMatched;
41 std::vector<unsigned int> vIndex;
43 BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
44 BOOST_CHECK_EQUAL(vMatched.size(), 2);
46 // Ordered by occurrence in depth-first tree traversal.
47 BOOST_CHECK_EQUAL(vMatched[0].ToString(), txhash2.ToString());
48 BOOST_CHECK_EQUAL(vIndex[0], 1);
50 BOOST_CHECK_EQUAL(vMatched[1].ToString(), txhash1.ToString());
51 BOOST_CHECK_EQUAL(vIndex[1], 8);
55 /**
56 * Create a CMerkleBlock using a list of txids which will not be found in the
57 * given block.
59 BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_not_found)
61 CBlock block = getBlock13b8a();
63 std::set<uint256> txids2;
64 txids2.insert(uint256S("0xc0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
65 CMerkleBlock merkleBlock(block, txids2);
67 BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
68 BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
70 std::vector<uint256> vMatched;
71 std::vector<unsigned int> vIndex;
73 BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
74 BOOST_CHECK_EQUAL(vMatched.size(), 0);
75 BOOST_CHECK_EQUAL(vIndex.size(), 0);
78 BOOST_AUTO_TEST_SUITE_END()