mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
[tests] Connect peer in outbound_slow_chain_eviction by sending p2p messages
Prior to this commit, the peer was connected, and then the services and connectivity fields in the CNode object were manually set. Instead, send p2p `version` and `verack` messages, and have net_processing's internal logic set the state of the node. This ensures that the node's internal state is consistent with how it would be set in the live code. Prior to this commit, `dummyNode1.nServices` was set to `NODE_NONE` which was not a problem since `CNode::fClient` and `CNode::m_limited_node` are default initialised to false. Now that we are doing the actual version handshake, the values of `fClient` and `m_limited_node` are set during the handshake and cause the test to fail if we do not set `dummyNode1.nServices` to a reasonable value (NODE_NETWORK | NODE_WITNESS).
This commit is contained in:
parent
1f52c47d5c
commit
fc5eb528f7
1 changed files with 16 additions and 11 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <serialize.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <timedata.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/time.h>
|
||||
|
@ -44,11 +45,10 @@ BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup)
|
|||
// work.
|
||||
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
||||
{
|
||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
||||
ConnmanTestMsg& connman = static_cast<ConnmanTestMsg&>(*m_node.connman);
|
||||
// Disable inactivity checks for this test to avoid interference
|
||||
static_cast<ConnmanTestMsg*>(connman.get())->SetPeerConnectTimeout(99999s);
|
||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr,
|
||||
*m_node.chainman, *m_node.mempool, false);
|
||||
connman.SetPeerConnectTimeout(99999s);
|
||||
PeerManager& peerman = *m_node.peerman;
|
||||
|
||||
// Mock an outbound peer
|
||||
CAddress addr1(ip(0xa0b0c001), NODE_NONE);
|
||||
|
@ -63,10 +63,15 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
|||
/*addrNameIn=*/"",
|
||||
ConnectionType::OUTBOUND_FULL_RELAY,
|
||||
/*inbound_onion=*/false};
|
||||
dummyNode1.SetCommonVersion(PROTOCOL_VERSION);
|
||||
|
||||
peerLogic->InitializeNode(dummyNode1, dummyNode1.GetLocalServices());
|
||||
dummyNode1.fSuccessfullyConnected = true;
|
||||
connman.Handshake(
|
||||
/*node=*/dummyNode1,
|
||||
/*successfully_connected=*/true,
|
||||
/*remote_services=*/ServiceFlags(NODE_NETWORK | NODE_WITNESS),
|
||||
/*permission_flags=*/NetPermissionFlags::None,
|
||||
/*version=*/PROTOCOL_VERSION,
|
||||
/*relay_txs=*/true);
|
||||
TestOnlyResetTimeData();
|
||||
|
||||
// This test requires that we have a chain with non-zero work.
|
||||
{
|
||||
|
@ -78,7 +83,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
|||
// Test starts here
|
||||
{
|
||||
LOCK(dummyNode1.cs_sendProcessing);
|
||||
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
|
||||
BOOST_CHECK(peerman.SendMessages(&dummyNode1)); // should result in getheaders
|
||||
}
|
||||
{
|
||||
LOCK(dummyNode1.cs_vSend);
|
||||
|
@ -91,7 +96,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
|||
SetMockTime(nStartTime+21*60);
|
||||
{
|
||||
LOCK(dummyNode1.cs_sendProcessing);
|
||||
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
|
||||
BOOST_CHECK(peerman.SendMessages(&dummyNode1)); // should result in getheaders
|
||||
}
|
||||
{
|
||||
LOCK(dummyNode1.cs_vSend);
|
||||
|
@ -101,11 +106,11 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
|
|||
SetMockTime(nStartTime+24*60);
|
||||
{
|
||||
LOCK(dummyNode1.cs_sendProcessing);
|
||||
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
|
||||
BOOST_CHECK(peerman.SendMessages(&dummyNode1)); // should result in disconnect
|
||||
}
|
||||
BOOST_CHECK(dummyNode1.fDisconnect == true);
|
||||
|
||||
peerLogic->FinalizeNode(dummyNode1);
|
||||
peerman.FinalizeNode(dummyNode1);
|
||||
}
|
||||
|
||||
static void AddRandomOutboundPeer(NodeId& id, std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman, ConnectionType connType)
|
||||
|
|
Loading…
Add table
Reference in a new issue