Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | struct AvalancheTestingSetup : public TestChain100Setup { | ||||
std::vector<CInv> getInvsForNextPoll() { | std::vector<CInv> getInvsForNextPoll() { | ||||
return AvalancheTest::getInvsForNextPoll(*m_processor); | return AvalancheTest::getInvsForNextPoll(*m_processor); | ||||
} | } | ||||
uint64_t getRound() const { return AvalancheTest::getRound(*m_processor); } | uint64_t getRound() const { return AvalancheTest::getRound(*m_processor); } | ||||
bool registerVotes(NodeId nodeid, const avalanche::Response &response, | bool registerVotes(NodeId nodeid, const avalanche::Response &response, | ||||
std::vector<avalanche::BlockUpdate> &updates) { | std::vector<avalanche::BlockUpdate> &blockUpdates) { | ||||
int banscore; | int banscore; | ||||
std::string error; | std::string error; | ||||
return m_processor->registerVotes(nodeid, response, updates, banscore, | std::vector<avalanche::ProofUpdate> proofUpdates; | ||||
error); | return m_processor->registerVotes(nodeid, response, blockUpdates, | ||||
proofUpdates, banscore, error); | |||||
} | } | ||||
}; | }; | ||||
struct BlockOnlyTestingContext { | struct BlockOnlyTestingContext { | ||||
AvalancheTestingSetup *fixture; | AvalancheTestingSetup *fixture; | ||||
std::vector<BlockUpdate> updates; | std::vector<BlockUpdate> updates; | ||||
uint32_t invType; | uint32_t invType; | ||||
Show All 11 Lines | struct BlockOnlyTestingContext { | ||||
uint256 getVoteItemId(const CBlockIndex *pindex) const { | uint256 getVoteItemId(const CBlockIndex *pindex) const { | ||||
return pindex->GetBlockHash(); | return pindex->GetBlockHash(); | ||||
} | } | ||||
bool registerVotes(NodeId nodeid, const avalanche::Response &response, | bool registerVotes(NodeId nodeid, const avalanche::Response &response, | ||||
std::string &error) { | std::string &error) { | ||||
int banscore; | int banscore; | ||||
return fixture->m_processor->registerVotes(nodeid, response, updates, | std::vector<avalanche::ProofUpdate> proofUpdates; | ||||
banscore, error); | return fixture->m_processor->registerVotes( | ||||
nodeid, response, updates, proofUpdates, banscore, error); | |||||
} | } | ||||
bool registerVotes(NodeId nodeid, const avalanche::Response &response) { | bool registerVotes(NodeId nodeid, const avalanche::Response &response) { | ||||
std::string error; | std::string error; | ||||
return registerVotes(nodeid, response, error); | return registerVotes(nodeid, response, error); | ||||
} | } | ||||
bool addToReconcile(const CBlockIndex *pindex) { | bool addToReconcile(const CBlockIndex *pindex) { | ||||
return fixture->m_processor->addBlockToReconcile(pindex); | return fixture->m_processor->addBlockToReconcile(pindex); | ||||
Show All 11 Lines | std::vector<Vote> buildVotesForItems(uint32_t error, | ||||
for (auto &item : reverse_iterate(items)) { | for (auto &item : reverse_iterate(items)) { | ||||
votes.emplace_back(error, item->GetBlockHash()); | votes.emplace_back(error, item->GetBlockHash()); | ||||
} | } | ||||
return votes; | return votes; | ||||
} | } | ||||
}; | }; | ||||
struct ProofOnlyTestingContext { | |||||
AvalancheTestingSetup *fixture; | |||||
std::vector<ProofUpdate> updates; | |||||
uint32_t invType; | |||||
ProofOnlyTestingContext(AvalancheTestingSetup *_fixture) | |||||
: fixture(_fixture), invType(MSG_AVA_PROOF) {} | |||||
std::shared_ptr<Proof> buildVoteItem() const { return fixture->GetProof(); } | |||||
uint256 getVoteItemId(const std::shared_ptr<Proof> &proof) const { | |||||
return proof->getId(); | |||||
} | |||||
bool registerVotes(NodeId nodeid, const avalanche::Response &response, | |||||
std::string &error) { | |||||
int banscore; | |||||
std::vector<avalanche::BlockUpdate> blockUpdates; | |||||
return fixture->m_processor->registerVotes( | |||||
nodeid, response, blockUpdates, updates, banscore, error); | |||||
} | |||||
bool registerVotes(NodeId nodeid, const avalanche::Response &response) { | |||||
std::string error; | |||||
return registerVotes(nodeid, response, error); | |||||
} | |||||
bool addToReconcile(const std::shared_ptr<Proof> &proof) { | |||||
fixture->m_processor->addProofToReconcile(proof, true); | |||||
return true; | |||||
} | |||||
std::vector<Vote> | |||||
buildVotesForItems(uint32_t error, | |||||
std::vector<std::shared_ptr<Proof>> &&items) { | |||||
size_t numItems = items.size(); | |||||
std::vector<Vote> votes; | |||||
votes.reserve(numItems); | |||||
// Votes are sorted by high score first | |||||
std::sort(items.begin(), items.end(), ProofSharedPointerComparator()); | |||||
for (auto &item : items) { | |||||
votes.emplace_back(error, item->getId()); | |||||
} | |||||
return votes; | |||||
} | |||||
}; | |||||
} // namespace | } // namespace | ||||
BOOST_FIXTURE_TEST_SUITE(processor_tests, AvalancheTestingSetup) | BOOST_FIXTURE_TEST_SUITE(processor_tests, AvalancheTestingSetup) | ||||
// FIXME A std::tuple can be used instead of boost::mpl::list after boost 1.67 | // FIXME A std::tuple can be used instead of boost::mpl::list after boost 1.67 | ||||
typedef boost::mpl::list<BlockOnlyTestingContext> voteItemTestingContexts; | typedef boost::mpl::list<BlockOnlyTestingContext, ProofOnlyTestingContext> | ||||
voteItemTestingContexts; | |||||
#define REGISTER_VOTE_AND_CHECK(vr, vote, state, finalized, confidence) \ | #define REGISTER_VOTE_AND_CHECK(vr, vote, state, finalized, confidence) \ | ||||
vr.registerVote(NO_NODE, vote); \ | vr.registerVote(NO_NODE, vote); \ | ||||
BOOST_CHECK_EQUAL(vr.isAccepted(), state); \ | BOOST_CHECK_EQUAL(vr.isAccepted(), state); \ | ||||
BOOST_CHECK_EQUAL(vr.hasFinalized(), finalized); \ | BOOST_CHECK_EQUAL(vr.hasFinalized(), finalized); \ | ||||
BOOST_CHECK_EQUAL(vr.getConfidence(), confidence); | BOOST_CHECK_EQUAL(vr.getConfidence(), confidence); | ||||
BOOST_AUTO_TEST_CASE(vote_record) { | BOOST_AUTO_TEST_CASE(vote_record) { | ||||
▲ Show 20 Lines • Show All 888 Lines • Show Last 20 Lines |