Changeset View
Changeset View
Standalone View
Standalone View
src/test/avalanche_tests.cpp
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(block_register) { | ||||
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<AvalancheBlockUpdate> updates; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
// Create nodes that supports avalanche. | // Create nodes that supports avalanche. | ||||
auto avanodes = | auto avanodes = | ||||
ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
// Querying for random block returns false. | // Querying for random block returns false. | ||||
BOOST_CHECK(!p.isAccepted(pindex)); | BOOST_CHECK(!p.isAccepted(pindex)); | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(multi_block_register) { | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<AvalancheBlockUpdate> updates; | ||||
// Create several nodes that support avalanche. | // Create several nodes that support avalanche. | ||||
auto avanodes = | auto avanodes = | ||||
ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
// Make sure the block has a hash. | // Make sure the block has a hash. | ||||
CBlock blockA = CreateAndProcessBlock({}, CScript()); | CBlock blockA = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHashA = blockA.GetHash(); | const BlockHash blockHashA = blockA.GetHash(); | ||||
const CBlockIndex *pindexA = mapBlockIndex[blockHashA]; | const CBlockIndex *pindexA = mapBlockIndex[blockHashA]; | ||||
CBlock blockB = CreateAndProcessBlock({}, CScript()); | CBlock blockB = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHashB = blockB.GetHash(); | const BlockHash blockHashB = blockB.GetHash(); | ||||
const CBlockIndex *pindexB = mapBlockIndex[blockHashB]; | const CBlockIndex *pindexB = mapBlockIndex[blockHashB]; | ||||
// Querying for random block returns false. | // Querying for random block returns false. | ||||
BOOST_CHECK(!p.isAccepted(pindexA)); | BOOST_CHECK(!p.isAccepted(pindexA)); | ||||
BOOST_CHECK(!p.isAccepted(pindexB)); | BOOST_CHECK(!p.isAccepted(pindexB)); | ||||
// Start voting on block A. | // Start voting on block A. | ||||
BOOST_CHECK(p.addBlockToReconcile(pindexA)); | BOOST_CHECK(p.addBlockToReconcile(pindexA)); | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_and_response) { | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<AvalancheBlockUpdate> updates; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
// There is no node to query. | // There is no node to query. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), NO_NODE); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), NO_NODE); | ||||
// Create a node that supports avalanche and one that doesn't. | // Create a node that supports avalanche and one that doesn't. | ||||
ConnectNode(config, NODE_NONE, *peerLogic, connman.get()); | ConnectNode(config, NODE_NONE, *peerLogic, connman.get()); | ||||
auto avanode = | auto avanode = | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_and_response) { | ||||
// Proper response gets processed and avanode is available again. | // Proper response gets processed and avanode is available again. | ||||
resp = {queryRound, 0, {AvalancheVote(0, blockHash)}}; | resp = {queryRound, 0, {AvalancheVote(0, blockHash)}}; | ||||
BOOST_CHECK(p.registerVotes(avanodeid, resp, updates)); | BOOST_CHECK(p.registerVotes(avanodeid, resp, updates)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 0); | BOOST_CHECK_EQUAL(updates.size(), 0); | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | ||||
// Out of order response are rejected. | // Out of order response are rejected. | ||||
CBlock block2 = CreateAndProcessBlock({}, CScript()); | CBlock block2 = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash2 = block2.GetHash(); | const BlockHash blockHash2 = block2.GetHash(); | ||||
CBlockIndex *pindex2 = mapBlockIndex[blockHash2]; | CBlockIndex *pindex2 = mapBlockIndex[blockHash2]; | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex2)); | BOOST_CHECK(p.addBlockToReconcile(pindex2)); | ||||
resp = {AvalancheTest::getRound(p), | resp = {AvalancheTest::getRound(p), | ||||
0, | 0, | ||||
{AvalancheVote(0, blockHash), AvalancheVote(0, blockHash2)}}; | {AvalancheVote(0, blockHash), AvalancheVote(0, blockHash2)}}; | ||||
AvalancheTest::runEventLoop(p); | AvalancheTest::runEventLoop(p); | ||||
BOOST_CHECK(!p.registerVotes(avanodeid, resp, updates)); | BOOST_CHECK(!p.registerVotes(avanodeid, resp, updates)); | ||||
Show All 33 Lines | #endif | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<AvalancheBlockUpdate> updates; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
// Add the block | // Add the block | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
// Create a node that supports avalanche. | // Create a node that supports avalanche. | ||||
auto avanode = | auto avanode = | ||||
ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_inflight_count) { | ||||
std::array<CNode *, AVALANCHE_MAX_INFLIGHT_POLL + 1> nodes; | std::array<CNode *, AVALANCHE_MAX_INFLIGHT_POLL + 1> nodes; | ||||
for (auto &n : nodes) { | for (auto &n : nodes) { | ||||
n = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | n = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
BOOST_CHECK(p.addPeer(n->GetId(), 0)); | BOOST_CHECK(p.addPeer(n->GetId(), 0)); | ||||
} | } | ||||
// Add a block to poll | // Add a block to poll | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
// Ensure there are enough requests in flight. | // Ensure there are enough requests in flight. | ||||
std::map<NodeId, uint64_t> node_round_map; | std::map<NodeId, uint64_t> node_round_map; | ||||
for (int i = 0; i < AVALANCHE_MAX_INFLIGHT_POLL; i++) { | for (int i = 0; i < AVALANCHE_MAX_INFLIGHT_POLL; i++) { | ||||
NodeId nodeid = AvalancheTest::getSuitableNodeToQuery(p); | NodeId nodeid = AvalancheTest::getSuitableNodeToQuery(p); | ||||
BOOST_CHECK(node_round_map.find(nodeid) == node_round_map.end()); | BOOST_CHECK(node_round_map.find(nodeid) == node_round_map.end()); | ||||
Show All 35 Lines | BOOST_AUTO_TEST_CASE(quorum_diversity) { | ||||
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<AvalancheBlockUpdate> updates; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
// Create nodes that supports avalanche. | // Create nodes that supports avalanche. | ||||
auto avanodes = | auto avanodes = | ||||
ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNodes(config, p, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
// Querying for random block returns false. | // Querying for random block returns false. | ||||
BOOST_CHECK(!p.isAccepted(pindex)); | BOOST_CHECK(!p.isAccepted(pindex)); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(event_loop) { | ||||
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
CScheduler s; | CScheduler s; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const uint256 blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | const CBlockIndex *pindex = mapBlockIndex[blockHash]; | ||||
// Starting the event loop. | // Starting the event loop. | ||||
BOOST_CHECK(p.startEventLoop(s)); | BOOST_CHECK(p.startEventLoop(s)); | ||||
// There is one task planned in the next hour (our event loop). | // There is one task planned in the next hour (our event loop). | ||||
boost::chrono::system_clock::time_point start, stop; | boost::chrono::system_clock::time_point start, stop; | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 1); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 1); | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |