Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | std::set<VoteStatus> status{ | ||||
VoteStatus::Accepted, | VoteStatus::Accepted, | ||||
VoteStatus::Finalized, | VoteStatus::Finalized, | ||||
}; | }; | ||||
for (auto s : status) { | for (auto s : status) { | ||||
BlockUpdate abu(pindex, s); | BlockUpdate abu(pindex, s); | ||||
// The use of BOOST_CHECK instead of BOOST_CHECK_EQUAL prevents from | // The use of BOOST_CHECK instead of BOOST_CHECK_EQUAL prevents from | ||||
// having to define operator<<() for each argument type. | // having to define operator<<() for each argument type. | ||||
BOOST_CHECK(abu.getBlockIndex() == pindex); | BOOST_CHECK(abu.getVoteItem() == pindex); | ||||
BOOST_CHECK(abu.getStatus() == s); | BOOST_CHECK(abu.getStatus() == s); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(block_reconcile_twice) { | BOOST_AUTO_TEST_CASE(block_reconcile_twice) { | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const BlockHash blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
CBlockIndex *pindex; | CBlockIndex *pindex; | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(block_register) { | ||||
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_EQUAL(updates.size(), 1); | BOOST_CHECK_EQUAL(updates.size(), 1); | ||||
BOOST_CHECK(updates[0].getBlockIndex() == pindex); | BOOST_CHECK(updates[0].getVoteItem() == pindex); | ||||
BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | ||||
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); | ||||
// Now let's undo this and finalize rejection. | // Now let's undo this and finalize rejection. | ||||
Show All 9 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].getVoteItem() == pindex); | ||||
BOOST_CHECK(updates[0].getStatus() == VoteStatus::Rejected); | BOOST_CHECK(updates[0].getStatus() == VoteStatus::Rejected); | ||||
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].getVoteItem() == pindex); | ||||
BOOST_CHECK(updates[0].getStatus() == VoteStatus::Invalid); | BOOST_CHECK(updates[0].getStatus() == VoteStatus::Invalid); | ||||
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); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(multi_block_register) { | ||||
NodeId secondNodeid = getSuitableNodeToQuery(); | NodeId secondNodeid = getSuitableNodeToQuery(); | ||||
runEventLoop(); | runEventLoop(); | ||||
BOOST_CHECK(firstNodeid != secondNodeid); | BOOST_CHECK(firstNodeid != secondNodeid); | ||||
// Next vote will finalize block A. | // Next vote will finalize block A. | ||||
BOOST_CHECK(registerVotes(firstNodeid, next(resp), updates)); | BOOST_CHECK(registerVotes(firstNodeid, next(resp), updates)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 1); | BOOST_CHECK_EQUAL(updates.size(), 1); | ||||
BOOST_CHECK(updates[0].getBlockIndex() == pindexA); | BOOST_CHECK(updates[0].getVoteItem() == pindexA); | ||||
BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | ||||
updates = {}; | updates = {}; | ||||
// We do not vote on A anymore. | // We do not vote on A anymore. | ||||
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 == blockHashB); | BOOST_CHECK(invs[0].hash == blockHashB); | ||||
// Next vote will finalize block B. | // Next vote will finalize block B. | ||||
BOOST_CHECK(registerVotes(secondNodeid, resp, updates)); | BOOST_CHECK(registerVotes(secondNodeid, resp, updates)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 1); | BOOST_CHECK_EQUAL(updates.size(), 1); | ||||
BOOST_CHECK(updates[0].getBlockIndex() == pindexB); | BOOST_CHECK(updates[0].getVoteItem() == pindexB); | ||||
BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | BOOST_CHECK(updates[0].getStatus() == VoteStatus::Finalized); | ||||
updates = {}; | updates = {}; | ||||
// There is nothing left to vote on. | // There is nothing left to vote on. | ||||
invs = getInvsForNextPoll(); | invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 0); | BOOST_CHECK_EQUAL(invs.size(), 0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 491 Lines • Show Last 20 Lines |