Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockencodings_tests.cpp
Show All 9 Lines | |||||
#include <pow.h> | #include <pow.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <streams.h> | #include <streams.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; | static std::vector<std::pair<TxHash, 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 COutPoint InsecureRandOutPoint() { | static COutPoint InsecureRandOutPoint() { | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | public: | ||||
explicit TestHeaderAndShortIDs(const CBlockHeaderAndShortTxIDs &orig) { | explicit TestHeaderAndShortIDs(const CBlockHeaderAndShortTxIDs &orig) { | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << orig; | stream << orig; | ||||
stream >> *this; | stream >> *this; | ||||
} | } | ||||
explicit TestHeaderAndShortIDs(const CBlock &block) | explicit TestHeaderAndShortIDs(const CBlock &block) | ||||
: TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs(block)) {} | : TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs(block)) {} | ||||
uint64_t GetShortID(const uint256 &txhash) const { | uint64_t GetShortID(const TxHash &txhash) const { | ||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); | ||||
stream << *this; | stream << *this; | ||||
CBlockHeaderAndShortTxIDs base; | CBlockHeaderAndShortTxIDs base; | ||||
stream >> base; | stream >> base; | ||||
return base.GetShortID(txhash); | return base.GetShortID(txhash); | ||||
} | } | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
Show All 30 Lines | BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) { | ||||
TxId txid; | TxId txid; | ||||
// Test with pre-forwarding tx 1, but not coinbase | // Test with pre-forwarding tx 1, but not coinbase | ||||
{ | { | ||||
TestHeaderAndShortIDs shortIDs(block); | TestHeaderAndShortIDs shortIDs(block); | ||||
shortIDs.prefilledtxn.resize(1); | shortIDs.prefilledtxn.resize(1); | ||||
shortIDs.prefilledtxn[0] = {1, block.vtx[1]}; | shortIDs.prefilledtxn[0] = {1, block.vtx[1]}; | ||||
shortIDs.shorttxids.resize(2); | shortIDs.shorttxids.resize(2); | ||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetId()); | shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash()); | ||||
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetId()); | shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash()); | ||||
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); | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) { | ||||
// Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool | // Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool | ||||
{ | { | ||||
TestHeaderAndShortIDs shortIDs(block); | TestHeaderAndShortIDs shortIDs(block); | ||||
shortIDs.prefilledtxn.resize(2); | shortIDs.prefilledtxn.resize(2); | ||||
shortIDs.prefilledtxn[0] = {0, block.vtx[0]}; | shortIDs.prefilledtxn[0] = {0, block.vtx[0]}; | ||||
// id == 1 as it is 1 after index 1 | // id == 1 as it is 1 after index 1 | ||||
shortIDs.prefilledtxn[1] = {1, block.vtx[2]}; | shortIDs.prefilledtxn[1] = {1, block.vtx[2]}; | ||||
shortIDs.shorttxids.resize(1); | shortIDs.shorttxids.resize(1); | ||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetId()); | shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash()); | ||||
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); | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |