Changeset View
Changeset View
Standalone View
Standalone View
src/test/pmt_tests.cpp
// Copyright (c) 2012-2016 The Bitcoin Core developers | // Copyright (c) 2012-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "arith_uint256.h" | #include "arith_uint256.h" | ||||
#include "consensus/merkle.h" | #include "consensus/merkle.h" | ||||
#include "merkleblock.h" | #include "merkleblock.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "streams.h" | #include "streams.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include "test/test_random.h" | #include "test/test_random.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "version.h" | #include "version.h" | ||||
#include <vector> | #include <vector> | ||||
#include <boost/assign/list_of.hpp> | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
class CPartialMerkleTreeTester : public CPartialMerkleTree { | class CPartialMerkleTreeTester : public CPartialMerkleTree { | ||||
public: | public: | ||||
// flip one bit in one of the hashes - this should break the authentication | // flip one bit in one of the hashes - this should break the authentication | ||||
void Damage() { | void Damage() { | ||||
unsigned int n = insecure_rand() % vHash.size(); | unsigned int n = insecure_rand() % vHash.size(); | ||||
int bit = insecure_rand() % 256; | int bit = insecure_rand() % 256; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | for (int i = 0; i < 12; i++) { | ||||
uint256 merkleRoot3 = pmt3.ExtractMatches(vMatchTxid3, vIndex); | uint256 merkleRoot3 = pmt3.ExtractMatches(vMatchTxid3, vIndex); | ||||
BOOST_CHECK(merkleRoot3 != merkleRoot1); | BOOST_CHECK(merkleRoot3 != merkleRoot1); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(pmt_malleability) { | BOOST_AUTO_TEST_CASE(pmt_malleability) { | ||||
std::vector<uint256> vTxid = boost::assign::list_of(ArithToUint256(1))( | std::vector<uint256> vTxid = { | ||||
ArithToUint256(2))(ArithToUint256(3))(ArithToUint256(4))( | ArithToUint256(1), ArithToUint256(2), ArithToUint256(3), | ||||
ArithToUint256(5))(ArithToUint256(6))(ArithToUint256(7))( | ArithToUint256(4), ArithToUint256(5), ArithToUint256(6), | ||||
ArithToUint256(8))(ArithToUint256(9))(ArithToUint256(10))( | ArithToUint256(7), ArithToUint256(8), ArithToUint256(9), | ||||
ArithToUint256(9))(ArithToUint256(10)); | ArithToUint256(10), ArithToUint256(9), ArithToUint256(10)}; | ||||
std::vector<bool> vMatch = boost::assign::list_of(false)(false)(false)( | std::vector<bool> vMatch = {false, false, false, false, false, false, | ||||
false)(false)(false)(false)(false)(false)(true)(true)(false); | false, false, false, true, true, false}; | ||||
CPartialMerkleTree tree(vTxid, vMatch); | CPartialMerkleTree tree(vTxid, vMatch); | ||||
std::vector<unsigned int> vIndex; | std::vector<unsigned int> vIndex; | ||||
BOOST_CHECK(tree.ExtractMatches(vTxid, vIndex).IsNull()); | BOOST_CHECK(tree.ExtractMatches(vTxid, vIndex).IsNull()); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |