Changeset View
Changeset View
Standalone View
Standalone View
src/test/avalanche_tests.cpp
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | |||||
std::array<CNode *, 8> ConnectNodes(const Config &config, AvalancheProcessor &p, | std::array<CNode *, 8> ConnectNodes(const Config &config, AvalancheProcessor &p, | ||||
ServiceFlags nServices, | ServiceFlags nServices, | ||||
PeerLogicValidation &peerLogic, | PeerLogicValidation &peerLogic, | ||||
CConnmanTest *connman) { | CConnmanTest *connman) { | ||||
std::array<CNode *, 8> nodes; | std::array<CNode *, 8> nodes; | ||||
for (CNode *&n : nodes) { | for (CNode *&n : nodes) { | ||||
n = ConnectNode(config, nServices, peerLogic, connman); | n = ConnectNode(config, nServices, peerLogic, connman); | ||||
BOOST_CHECK(p.addPeer(n->GetId(), 0)); | BOOST_CHECK(p.addPeer(n->GetId(), 0, CPubKey())); | ||||
} | } | ||||
return nodes; | return nodes; | ||||
} | } | ||||
static AvalancheResponse next(AvalancheResponse &r) { | static AvalancheResponse next(AvalancheResponse &r) { | ||||
auto copy = r; | auto copy = r; | ||||
r = {r.getRound() + 1, r.getCooldown(), r.GetVotes()}; | r = {r.getRound() + 1, r.getCooldown(), r.GetVotes()}; | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_and_response) { | ||||
// 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 = | ||||
ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
NodeId avanodeid = avanode->GetId(); | NodeId avanodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(avanodeid, 0)); | BOOST_CHECK(p.addPeer(avanodeid, 0, CPubKey())); | ||||
// It returns the avalanche peer. | // It returns the avalanche peer. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | ||||
// Register a block and check it is added to the list of elements to poll. | // Register a block and check it is added to the list of elements to poll. | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
auto invs = AvalancheTest::getInvsForNextPoll(p); | auto invs = AvalancheTest::getInvsForNextPoll(p); | ||||
BOOST_CHECK_EQUAL(invs.size(), 1); | BOOST_CHECK_EQUAL(invs.size(), 1); | ||||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | #endif | ||||
// 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()); | ||||
NodeId avanodeid = avanode->GetId(); | NodeId avanodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(avanodeid, 0)); | BOOST_CHECK(p.addPeer(avanodeid, 0, CPubKey())); | ||||
// Expire requests after some time. | // Expire requests after some time. | ||||
auto queryTimeDuration = std::chrono::milliseconds(10); | auto queryTimeDuration = std::chrono::milliseconds(10); | ||||
p.setQueryTimeoutDuration(queryTimeDuration); | p.setQueryTimeoutDuration(queryTimeDuration); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
#if BOOST_VERSION < 105900 | #if BOOST_VERSION < 105900 | ||||
// TODO: Cleanup this statement when boost 1.58 is no longer supported. | // TODO: Cleanup this statement when boost 1.58 is no longer supported. | ||||
BOOST_REQUIRE(timeStart + 60 * 1000 > GetTimeMillis()); | BOOST_REQUIRE(timeStart + 60 * 1000 > GetTimeMillis()); | ||||
Show All 38 Lines | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, scheduler, false); | connman.get(), nullptr, scheduler, false); | ||||
AvalancheProcessor p(connman.get()); | AvalancheProcessor p(connman.get()); | ||||
// Create enough nodes so that we run into the inflight request limit. | // Create enough nodes so that we run into the inflight request limit. | ||||
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, CPubKey())); | ||||
} | } | ||||
// Add a block to poll | // Add a block to poll | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const BlockHash blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex; | const CBlockIndex *pindex; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(event_loop) { | ||||
// Start the scheduler thread. | // Start the scheduler thread. | ||||
std::thread schedulerThread(std::bind(&CScheduler::serviceQueue, &s)); | std::thread schedulerThread(std::bind(&CScheduler::serviceQueue, &s)); | ||||
// 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()); | ||||
NodeId nodeid = avanode->GetId(); | NodeId nodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(nodeid, 0)); | BOOST_CHECK(p.addPeer(nodeid, 0, CPubKey())); | ||||
// There is no query in flight at the moment. | // There is no query in flight at the moment. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), nodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), nodeid); | ||||
// Add a new block. Check it is added to the polls. | // Add a new block. Check it is added to the polls. | ||||
uint64_t queryRound = AvalancheTest::getRound(p); | uint64_t queryRound = AvalancheTest::getRound(p); | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |