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 <avalanche/voterecord.h> | #include <avalanche/voterecord.h> | ||||
#include <base58.h> | |||||
#include <chain.h> | #include <chain.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <key_io.h> | |||||
#include <net_processing.h> // For ::PeerManager | #include <net_processing.h> // For ::PeerManager | ||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <util/translation.h> // For bilingual_str | #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> | ||||
▲ Show 20 Lines • Show All 1,260 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(quorum_detection) { | ||||
orphanProof(proof1); | orphanProof(proof1); | ||||
processor->withPeerManager([&](avalanche::PeerManager &pm) { | processor->withPeerManager([&](avalanche::PeerManager &pm) { | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), 0); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), 0); | ||||
BOOST_CHECK_EQUAL(pm.getConnectedPeersScore(), 0); | BOOST_CHECK_EQUAL(pm.getConnectedPeersScore(), 0); | ||||
}); | }); | ||||
BOOST_CHECK(processor->isQuorumEstablished()); | BOOST_CHECK(processor->isQuorumEstablished()); | ||||
// Reset the processor using a local proof that has enough stake for a | |||||
// quorum and ensure the available quorum is recognized. | |||||
auto proof = GetProof(); | |||||
gArgs.ForceSetArg("-avaminquorumstake", ToString(proof->getScore())); | |||||
gArgs.ForceSetArg("-avaproof", proof->ToHex()); | |||||
gArgs.ForceSetArg("-avamasterkey", EncodeSecret(masterpriv)); | |||||
processor = Processor::MakeProcessor(*m_node.args, *m_node.chain, | |||||
m_node.connman.get(), error); | |||||
// We have an active quorum but don't actually have any peers. | |||||
BOOST_CHECK(processor != nullptr); | |||||
BOOST_CHECK(processor->isQuorumEstablished()); | |||||
processor->withPeerManager([&](avalanche::PeerManager &pm) { | |||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), 0); | |||||
BOOST_CHECK_EQUAL(pm.getConnectedPeersScore(), 0); | |||||
}); | |||||
gArgs.ClearForcedArg("-avaminquorumstake"); | gArgs.ClearForcedArg("-avaminquorumstake"); | ||||
gArgs.ClearForcedArg("-avaminquorumconnectedstakeratio"); | gArgs.ClearForcedArg("-avaminquorumconnectedstakeratio"); | ||||
gArgs.ClearForcedArg("-avaproof"); | |||||
gArgs.ClearForcedArg("-avamasterkey"); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(quorum_detection_parameter_validation) { | BOOST_AUTO_TEST_CASE(quorum_detection_parameter_validation) { | ||||
// Create vector of tuples of <min stake, min ratio, success bool> | // Create vector of tuples of <min stake, min ratio, success bool> | ||||
std::vector<std::tuple<std::string, std::string, bool>> tests = { | std::vector<std::tuple<std::string, std::string, bool>> tests = { | ||||
// Both parameters are invalid | // Both parameters are invalid | ||||
{"", "", false}, | {"", "", false}, | ||||
{"-1", "-1", false}, | {"-1", "-1", false}, | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |