1a445343f6
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
// Copyright (c) 2012-2017 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <merkleblock.h>
|
|
#include <uint256.h>
|
|
#include <test/test_bitcoin.h>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(merkleblock_tests, BasicTestingSetup)
|
|
|
|
/**
|
|
* Create a CMerkleBlock using a list of txids which will be found in the
|
|
* given block.
|
|
*/
|
|
BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)
|
|
{
|
|
CBlock block = getBlock13b8a();
|
|
|
|
std::set<uint256> txids;
|
|
|
|
// Last txn in block.
|
|
uint256 txhash1 = uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20");
|
|
|
|
// Second txn in block.
|
|
uint256 txhash2 = uint256S("0xf9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07");
|
|
|
|
txids.insert(txhash1);
|
|
txids.insert(txhash2);
|
|
|
|
CMerkleBlock merkleBlock(block, txids);
|
|
|
|
BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
|
|
|
|
// vMatchedTxn is only used when bloom filter is specified.
|
|
BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
|
|
|
|
std::vector<uint256> vMatched;
|
|
std::vector<unsigned int> vIndex;
|
|
|
|
BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
|
|
BOOST_CHECK_EQUAL(vMatched.size(), 2);
|
|
|
|
// Ordered by occurrence in depth-first tree traversal.
|
|
BOOST_CHECK_EQUAL(vMatched[0].ToString(), txhash2.ToString());
|
|
BOOST_CHECK_EQUAL(vIndex[0], 1);
|
|
|
|
BOOST_CHECK_EQUAL(vMatched[1].ToString(), txhash1.ToString());
|
|
BOOST_CHECK_EQUAL(vIndex[1], 8);
|
|
}
|
|
|
|
|
|
/**
|
|
* Create a CMerkleBlock using a list of txids which will not be found in the
|
|
* given block.
|
|
*/
|
|
BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_not_found)
|
|
{
|
|
CBlock block = getBlock13b8a();
|
|
|
|
std::set<uint256> txids2;
|
|
txids2.insert(uint256S("0xc0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
|
|
CMerkleBlock merkleBlock(block, txids2);
|
|
|
|
BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
|
|
BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 0);
|
|
|
|
std::vector<uint256> vMatched;
|
|
std::vector<unsigned int> vIndex;
|
|
|
|
BOOST_CHECK_EQUAL(merkleBlock.txn.ExtractMatches(vMatched, vIndex).GetHex(), block.hashMerkleRoot.GetHex());
|
|
BOOST_CHECK_EQUAL(vMatched.size(), 0);
|
|
BOOST_CHECK_EQUAL(vIndex.size(), 0);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|