Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show All 14 Lines | |||||
// 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> | ||||
#include <optional> | |||||
using namespace avalanche; | using namespace avalanche; | ||||
namespace avalanche { | namespace avalanche { | ||||
namespace { | namespace { | ||||
struct AvalancheTest { | struct AvalancheTest { | ||||
static void runEventLoop(avalanche::Processor &p) { p.runEventLoop(); } | static void runEventLoop(avalanche::Processor &p) { p.runEventLoop(); } | ||||
static std::vector<CInv> getInvsForNextPoll(Processor &p) { | static std::vector<CInv> getInvsForNextPoll(Processor &p) { | ||||
▲ Show 20 Lines • Show All 935 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(destructor) { | ||||
// Now that avalanche is destroyed, there is no more scheduled tasks. | // Now that avalanche is destroyed, there is no more scheduled tasks. | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | ||||
// Wait for the scheduler to stop. | // Wait for the scheduler to stop. | ||||
s.stop(true); | s.stop(true); | ||||
schedulerThread.join(); | schedulerThread.join(); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(proof_accessors) { | |||||
constexpr int numProofs = 10; | |||||
std::vector<Proof> proofs; | |||||
proofs.reserve(numProofs); | |||||
for (int i = 0; i < numProofs; i++) { | |||||
proofs.push_back(GetProof()); | |||||
} | |||||
for (int i = 0; i < numProofs; i++) { | |||||
BOOST_CHECK(m_processor->addProof(proofs[i])); | |||||
// Fail to add an existing proof | |||||
BOOST_CHECK(!m_processor->addProof(proofs[i])); | |||||
for (int added = 0; added <= i; added++) { | |||||
std::optional<Proof> proof = | |||||
m_processor->getProof(proofs[added].getId()); | |||||
BOOST_CHECK(proof); | |||||
BOOST_CHECK_EQUAL(proof->getId(), proofs[added].getId()); | |||||
} | |||||
for (int missing = i + 1; missing < numProofs; missing++) { | |||||
BOOST_CHECK(!m_processor->getProof(proofs[missing].getId())); | |||||
} | |||||
} | |||||
// No stake, copied from proof_tests.cpp | |||||
const std::string badProofHex( | |||||
"96527eae083f1f24625f049d9e54bb9a2102a93d98bf42ab90cfc0bf9e7c634ed76a7" | |||||
"3e95b02cacfd357b64e4fb6c92e92dd00"); | |||||
bilingual_str error; | |||||
Proof badProof; | |||||
BOOST_CHECK(Proof::FromHex(badProof, badProofHex, error)); | |||||
BOOST_CHECK(!m_processor->addProof(badProof)); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |