Skip to content

Commit 83df257

Browse files
promagsdaftuar
authored andcommitted
Add CConnmanTest to mutate g_connman in tests
1 parent ac7b37c commit 83df257

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ class CConnman
431431
* in excess of nMaxOutbound
432432
* This takes the place of a feeler connection */
433433
std::atomic_bool m_try_another_outbound_peer;
434+
435+
friend struct CConnmanTest;
434436
};
435437
extern std::unique_ptr<CConnman> g_connman;
436438
void Discover(boost::thread_group& threadGroup);

src/test/test_bitcoin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525

2626
#include <memory>
2727

28+
void CConnmanTest::AddNode(CNode& node)
29+
{
30+
LOCK(g_connman->cs_vNodes);
31+
g_connman->vNodes.push_back(&node);
32+
}
33+
34+
void CConnmanTest::ClearNodes()
35+
{
36+
LOCK(g_connman->cs_vNodes);
37+
g_connman->vNodes.clear();
38+
}
39+
2840
uint256 insecure_rand_seed = GetRandHash();
2941
FastRandomContext insecure_rand_ctx(insecure_rand_seed);
3042

src/test/test_bitcoin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ struct BasicTestingSetup {
4949
* Included are data directory, coins database, script check threads setup.
5050
*/
5151
class CConnman;
52+
class CNode;
53+
struct CConnmanTest {
54+
static void AddNode(CNode& node);
55+
static void ClearNodes();
56+
};
57+
5258
class PeerLogicValidation;
5359
struct TestingSetup: public BasicTestingSetup {
5460
CCoinsViewDB *pcoinsdbview;

0 commit comments

Comments
 (0)