From 83df25736ebaa23777e965d265ed677a8d79f23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Tue, 24 Oct 2017 09:26:05 +0100 Subject: [PATCH] Add CConnmanTest to mutate g_connman in tests --- src/net.h | 2 ++ src/test/test_bitcoin.cpp | 12 ++++++++++++ src/test/test_bitcoin.h | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/net.h b/src/net.h index c90df6499..edca1171a 100644 --- a/src/net.h +++ b/src/net.h @@ -431,6 +431,8 @@ private: * in excess of nMaxOutbound * This takes the place of a feeler connection */ std::atomic_bool m_try_another_outbound_peer; + + friend struct CConnmanTest; }; extern std::unique_ptr g_connman; void Discover(boost::thread_group& threadGroup); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index c768446d3..85476b6da 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -25,6 +25,18 @@ #include +void CConnmanTest::AddNode(CNode& node) +{ + LOCK(g_connman->cs_vNodes); + g_connman->vNodes.push_back(&node); +} + +void CConnmanTest::ClearNodes() +{ + LOCK(g_connman->cs_vNodes); + g_connman->vNodes.clear(); +} + uint256 insecure_rand_seed = GetRandHash(); FastRandomContext insecure_rand_ctx(insecure_rand_seed); diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h index 2390aca34..62ded2aaf 100644 --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -49,6 +49,12 @@ struct BasicTestingSetup { * Included are data directory, coins database, script check threads setup. */ class CConnman; +class CNode; +struct CConnmanTest { + static void AddNode(CNode& node); + static void ClearNodes(); +}; + class PeerLogicValidation; struct TestingSetup: public BasicTestingSetup { CCoinsViewDB *pcoinsdbview;