Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
// Copyright (c) 2018-2020 The Bitcoin developers | // Copyright (c) 2018-2020 The Bitcoin 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 <avalanche/processor.h> | #include <avalanche/processor.h> | ||||
#include <avalanche/delegationbuilder.h> | #include <avalanche/delegationbuilder.h> | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <avalanche/proofbuilder.h> | #include <avalanche/proofbuilder.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <net_processing.h> // For ::PeerManager | #include <net_processing.h> // For ::PeerManager | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <util/translation.h> // For bilingual_str | |||||
// D6970 moved LookupBlockIndex from chain.h to validation.h TODO: remove this | // D6970 moved LookupBlockIndex from chain.h to validation.h TODO: remove this | ||||
// when LookupBlockIndex is refactored out of validation | // when LookupBlockIndex is refactored out of validation | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | AvalancheTestingSetup() | ||||
m_connman = connman.get(); | m_connman = connman.get(); | ||||
m_node.connman = std::move(connman); | m_node.connman = std::move(connman); | ||||
m_node.peerman = std::make_unique<::PeerManager>( | m_node.peerman = std::make_unique<::PeerManager>( | ||||
config.GetChainParams(), *m_connman, m_node.banman.get(), | config.GetChainParams(), *m_connman, m_node.banman.get(), | ||||
*m_node.scheduler, *m_node.chainman, *m_node.mempool); | *m_node.scheduler, *m_node.chainman, *m_node.mempool); | ||||
m_node.chain = interfaces::MakeChain(m_node, config.GetChainParams()); | m_node.chain = interfaces::MakeChain(m_node, config.GetChainParams()); | ||||
// Get the processor ready. | // Get the processor ready. | ||||
m_processor = std::make_unique<Processor>( | bilingual_str error; | ||||
*m_node.chain, m_node.connman.get(), m_node.peerman.get()); | m_processor = Processor::MakeProcessor(*m_node.args, *m_node.chain, | ||||
m_node.connman.get(), | |||||
m_node.peerman.get(), error); | |||||
BOOST_CHECK(m_processor); | |||||
// The master private key we delegate to. | // The master private key we delegate to. | ||||
masterpriv.MakeNewKey(true); | masterpriv.MakeNewKey(true); | ||||
} | } | ||||
~AvalancheTestingSetup() { m_connman->ClearNodes(); } | ~AvalancheTestingSetup() { m_connman->ClearNodes(); } | ||||
CNode *ConnectNode(ServiceFlags nServices) { | CNode *ConnectNode(ServiceFlags nServices) { | ||||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | for (int i = 0; i < 6; i++) { | ||||
BOOST_CHECK(m_processor->isAccepted(pindex)); | BOOST_CHECK(m_processor->isAccepted(pindex)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 0); | BOOST_CHECK_EQUAL(updates.size(), 0); | ||||
} | } | ||||
// Now the state will flip. | // Now the state will flip. | ||||
registerNewVote(next(resp)); | registerNewVote(next(resp)); | ||||
BOOST_CHECK(!m_processor->isAccepted(pindex)); | BOOST_CHECK(!m_processor->isAccepted(pindex)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 1); | BOOST_CHECK_EQUAL(updates.size(), 1); | ||||
BOOST_CHECK(updates[0].getBlockIndex() == pindex); | BOOST_CHECK(updates[0].getBlockIndex() == pindex); | ||||
Lint: containerOutOfBounds: Out of bounds access in expression 'updates[0]' because 'updates' is empty. | |||||
BOOST_CHECK_EQUAL(updates[0].getStatus(), BlockUpdate::Status::Rejected); | BOOST_CHECK_EQUAL(updates[0].getStatus(), BlockUpdate::Status::Rejected); | ||||
Lint: containerOutOfBounds Out of bounds access in expression 'updates[0]' because 'updates' is empty. Lint: containerOutOfBounds: Out of bounds access in expression 'updates[0]' because 'updates' is empty. | |||||
updates = {}; | updates = {}; | ||||
// Now it is rejected, but we can vote for it numerous times. | // Now it is rejected, but we can vote for it numerous times. | ||||
for (int i = 1; i < AVALANCHE_FINALIZATION_SCORE; i++) { | for (int i = 1; i < AVALANCHE_FINALIZATION_SCORE; i++) { | ||||
registerNewVote(next(resp)); | registerNewVote(next(resp)); | ||||
BOOST_CHECK(!m_processor->isAccepted(pindex)); | BOOST_CHECK(!m_processor->isAccepted(pindex)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 0); | BOOST_CHECK_EQUAL(updates.size(), 0); | ||||
} | } | ||||
// As long as it is not finalized, we poll. | // As long as it is not finalized, we poll. | ||||
invs = getInvsForNextPoll(); | invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 1); | BOOST_CHECK_EQUAL(invs.size(), 1); | ||||
BOOST_CHECK_EQUAL(invs[0].type, MSG_BLOCK); | BOOST_CHECK_EQUAL(invs[0].type, MSG_BLOCK); | ||||
BOOST_CHECK(invs[0].hash == blockHash); | BOOST_CHECK(invs[0].hash == blockHash); | ||||
// Now finalize the decision. | // Now finalize the decision. | ||||
registerNewVote(next(resp)); | registerNewVote(next(resp)); | ||||
BOOST_CHECK(!m_processor->isAccepted(pindex)); | BOOST_CHECK(!m_processor->isAccepted(pindex)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 1); | BOOST_CHECK_EQUAL(updates.size(), 1); | ||||
BOOST_CHECK(updates[0].getBlockIndex() == pindex); | BOOST_CHECK(updates[0].getBlockIndex() == pindex); | ||||
Lint: containerOutOfBounds Out of bounds access in expression 'updates[0]' because 'updates' is empty. Lint: containerOutOfBounds: Out of bounds access in expression 'updates[0]' because 'updates' is empty. | |||||
BOOST_CHECK_EQUAL(updates[0].getStatus(), BlockUpdate::Status::Invalid); | BOOST_CHECK_EQUAL(updates[0].getStatus(), BlockUpdate::Status::Invalid); | ||||
Lint: containerOutOfBounds Out of bounds access in expression 'updates[0]' because 'updates' is empty. Lint: containerOutOfBounds: Out of bounds access in expression 'updates[0]' because 'updates' is empty. | |||||
updates = {}; | updates = {}; | ||||
// Once the decision is finalized, there is no poll for it. | // Once the decision is finalized, there is no poll for it. | ||||
invs = getInvsForNextPoll(); | invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 0); | BOOST_CHECK_EQUAL(invs.size(), 0); | ||||
// Adding the block twice does nothing. | // Adding the block twice does nothing. | ||||
BOOST_CHECK(m_processor->addBlockToReconcile(pindex)); | BOOST_CHECK(m_processor->addBlockToReconcile(pindex)); | ||||
▲ Show 20 Lines • Show All 522 Lines • Show Last 20 Lines |
Out of bounds access in expression 'updates[0]' because 'updates' is empty.