Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockencodings_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-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 "blockencodings.h" | #include "blockencodings.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/merkle.h" | #include "consensus/merkle.h" | ||||
#include "random.h" | #include "random.h" | ||||
#include "rwcollection.h" | |||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
std::vector<std::pair<uint256, CTransactionRef>> extra_txn; | RWCollection<std::vector<std::pair<uint256, CTransactionRef>>> extra_txn; | ||||
struct RegtestingSetup : public TestingSetup { | struct RegtestingSetup : public TestingSetup { | ||||
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {} | RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {} | ||||
}; | }; | ||||
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup) | BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup) | ||||
static CBlock BuildBlockTestCase() { | static CBlock BuildBlockTestCase() { | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | // Do a simple ShortTxIDs RT | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << shortIDs; | stream << shortIDs; | ||||
CBlockHeaderAndShortTxIDs shortIDs2; | CBlockHeaderAndShortTxIDs shortIDs2; | ||||
stream >> shortIDs2; | stream >> shortIDs2; | ||||
PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | ||||
BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn) == | BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn.getReadView()) == | ||||
READ_STATUS_OK); | READ_STATUS_OK); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(0)); | BOOST_CHECK(partialBlock.IsTxAvailable(0)); | ||||
BOOST_CHECK(!partialBlock.IsTxAvailable(1)); | BOOST_CHECK(!partialBlock.IsTxAvailable(1)); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(2)); | BOOST_CHECK(partialBlock.IsTxAvailable(2)); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), | pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), | ||||
SHARED_TX_OFFSET + 1); | SHARED_TX_OFFSET + 1); | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | // Test with pre-forwarding tx 1, but not coinbase | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << shortIDs; | stream << shortIDs; | ||||
CBlockHeaderAndShortTxIDs shortIDs2; | CBlockHeaderAndShortTxIDs shortIDs2; | ||||
stream >> shortIDs2; | stream >> shortIDs2; | ||||
PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | ||||
BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn) == | BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn.getReadView()) == | ||||
READ_STATUS_OK); | READ_STATUS_OK); | ||||
BOOST_CHECK(!partialBlock.IsTxAvailable(0)); | BOOST_CHECK(!partialBlock.IsTxAvailable(0)); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(1)); | BOOST_CHECK(partialBlock.IsTxAvailable(1)); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(2)); | BOOST_CHECK(partialBlock.IsTxAvailable(2)); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), | pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), | ||||
SHARED_TX_OFFSET + 1); | SHARED_TX_OFFSET + 1); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | // Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << shortIDs; | stream << shortIDs; | ||||
CBlockHeaderAndShortTxIDs shortIDs2; | CBlockHeaderAndShortTxIDs shortIDs2; | ||||
stream >> shortIDs2; | stream >> shortIDs2; | ||||
PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | ||||
BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn) == | BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn.getReadView()) == | ||||
READ_STATUS_OK); | READ_STATUS_OK); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(0)); | BOOST_CHECK(partialBlock.IsTxAvailable(0)); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(1)); | BOOST_CHECK(partialBlock.IsTxAvailable(1)); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(2)); | BOOST_CHECK(partialBlock.IsTxAvailable(2)); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
pool.mapTx.find(block.vtx[1]->GetId())->GetSharedTx().use_count(), | pool.mapTx.find(block.vtx[1]->GetId())->GetSharedTx().use_count(), | ||||
SHARED_TX_OFFSET + 1); | SHARED_TX_OFFSET + 1); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | // Test simple header round-trip with only coinbase | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << shortIDs; | stream << shortIDs; | ||||
CBlockHeaderAndShortTxIDs shortIDs2; | CBlockHeaderAndShortTxIDs shortIDs2; | ||||
stream >> shortIDs2; | stream >> shortIDs2; | ||||
PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | PartiallyDownloadedBlock partialBlock(GetConfig(), &pool); | ||||
BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn) == | BOOST_CHECK(partialBlock.InitData(shortIDs2, extra_txn.getReadView()) == | ||||
READ_STATUS_OK); | READ_STATUS_OK); | ||||
BOOST_CHECK(partialBlock.IsTxAvailable(0)); | BOOST_CHECK(partialBlock.IsTxAvailable(0)); | ||||
CBlock block2; | CBlock block2; | ||||
std::vector<CTransactionRef> vtx_missing; | std::vector<CTransactionRef> vtx_missing; | ||||
BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == | BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == | ||||
READ_STATUS_OK); | READ_STATUS_OK); | ||||
BOOST_CHECK_EQUAL(block.GetHash().ToString(), | BOOST_CHECK_EQUAL(block.GetHash().ToString(), | ||||
Show All 31 Lines |