mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 19:23:26 -03:00
test: Add tests for CNode::ConnectedThroughNetwork
This commit is contained in:
parent
49fba9c1aa
commit
3984b78cd7
2 changed files with 44 additions and 3 deletions
|
@ -46,7 +46,8 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||||
*address_bind,
|
*address_bind,
|
||||||
fuzzed_data_provider.ConsumeRandomLengthString(32),
|
fuzzed_data_provider.ConsumeRandomLengthString(32),
|
||||||
fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH})};
|
fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH}),
|
||||||
|
fuzzed_data_provider.ConsumeBool()};
|
||||||
while (fuzzed_data_provider.ConsumeBool()) {
|
while (fuzzed_data_provider.ConsumeBool()) {
|
||||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 11)) {
|
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 11)) {
|
||||||
case 0: {
|
case 0: {
|
||||||
|
@ -148,4 +149,5 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) :
|
fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) :
|
||||||
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
||||||
(void)node.HasPermission(net_permission_flags);
|
(void)node.HasPermission(net_permission_flags);
|
||||||
|
(void)node.ConnectedThroughNetwork();
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,21 +185,60 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
||||||
CAddress addr = CAddress(CService(ipv4Addr, 7777), NODE_NETWORK);
|
CAddress addr = CAddress(CService(ipv4Addr, 7777), NODE_NETWORK);
|
||||||
std::string pszDest;
|
std::string pszDest;
|
||||||
|
|
||||||
std::unique_ptr<CNode> pnode1 = MakeUnique<CNode>(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, ConnectionType::OUTBOUND_FULL_RELAY);
|
std::unique_ptr<CNode> pnode1 = MakeUnique<CNode>(
|
||||||
|
id++, NODE_NETWORK, height, hSocket, addr,
|
||||||
|
/* nKeyedNetGroupIn = */ 0,
|
||||||
|
/* nLocalHostNonceIn = */ 0,
|
||||||
|
CAddress(), pszDest, ConnectionType::OUTBOUND_FULL_RELAY);
|
||||||
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
|
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
|
||||||
BOOST_CHECK(pnode1->IsManualConn() == false);
|
BOOST_CHECK(pnode1->IsManualConn() == false);
|
||||||
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
|
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
|
||||||
BOOST_CHECK(pnode1->IsFeelerConn() == false);
|
BOOST_CHECK(pnode1->IsFeelerConn() == false);
|
||||||
BOOST_CHECK(pnode1->IsAddrFetchConn() == false);
|
BOOST_CHECK(pnode1->IsAddrFetchConn() == false);
|
||||||
BOOST_CHECK(pnode1->IsInboundConn() == false);
|
BOOST_CHECK(pnode1->IsInboundConn() == false);
|
||||||
|
BOOST_CHECK_EQUAL(pnode1->ConnectedThroughNetwork(), Network::NET_IPV4);
|
||||||
|
|
||||||
std::unique_ptr<CNode> pnode2 = MakeUnique<CNode>(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, ConnectionType::INBOUND);
|
std::unique_ptr<CNode> pnode2 = MakeUnique<CNode>(
|
||||||
|
id++, NODE_NETWORK, height, hSocket, addr,
|
||||||
|
/* nKeyedNetGroupIn = */ 1,
|
||||||
|
/* nLocalHostNonceIn = */ 1,
|
||||||
|
CAddress(), pszDest, ConnectionType::INBOUND,
|
||||||
|
/* inbound_onion = */ false);
|
||||||
BOOST_CHECK(pnode2->IsFullOutboundConn() == false);
|
BOOST_CHECK(pnode2->IsFullOutboundConn() == false);
|
||||||
BOOST_CHECK(pnode2->IsManualConn() == false);
|
BOOST_CHECK(pnode2->IsManualConn() == false);
|
||||||
BOOST_CHECK(pnode2->IsBlockOnlyConn() == false);
|
BOOST_CHECK(pnode2->IsBlockOnlyConn() == false);
|
||||||
BOOST_CHECK(pnode2->IsFeelerConn() == false);
|
BOOST_CHECK(pnode2->IsFeelerConn() == false);
|
||||||
BOOST_CHECK(pnode2->IsAddrFetchConn() == false);
|
BOOST_CHECK(pnode2->IsAddrFetchConn() == false);
|
||||||
BOOST_CHECK(pnode2->IsInboundConn() == true);
|
BOOST_CHECK(pnode2->IsInboundConn() == true);
|
||||||
|
BOOST_CHECK_EQUAL(pnode2->ConnectedThroughNetwork(), Network::NET_IPV4);
|
||||||
|
|
||||||
|
std::unique_ptr<CNode> pnode3 = MakeUnique<CNode>(
|
||||||
|
id++, NODE_NETWORK, height, hSocket, addr,
|
||||||
|
/* nKeyedNetGroupIn = */ 0,
|
||||||
|
/* nLocalHostNonceIn = */ 0,
|
||||||
|
CAddress(), pszDest, ConnectionType::OUTBOUND_FULL_RELAY,
|
||||||
|
/* inbound_onion = */ true);
|
||||||
|
BOOST_CHECK(pnode3->IsFullOutboundConn() == true);
|
||||||
|
BOOST_CHECK(pnode3->IsManualConn() == false);
|
||||||
|
BOOST_CHECK(pnode3->IsBlockOnlyConn() == false);
|
||||||
|
BOOST_CHECK(pnode3->IsFeelerConn() == false);
|
||||||
|
BOOST_CHECK(pnode3->IsAddrFetchConn() == false);
|
||||||
|
BOOST_CHECK(pnode3->IsInboundConn() == false);
|
||||||
|
BOOST_CHECK_EQUAL(pnode3->ConnectedThroughNetwork(), Network::NET_IPV4);
|
||||||
|
|
||||||
|
std::unique_ptr<CNode> pnode4 = MakeUnique<CNode>(
|
||||||
|
id++, NODE_NETWORK, height, hSocket, addr,
|
||||||
|
/* nKeyedNetGroupIn = */ 1,
|
||||||
|
/* nLocalHostNonceIn = */ 1,
|
||||||
|
CAddress(), pszDest, ConnectionType::INBOUND,
|
||||||
|
/* inbound_onion = */ true);
|
||||||
|
BOOST_CHECK(pnode4->IsFullOutboundConn() == false);
|
||||||
|
BOOST_CHECK(pnode4->IsManualConn() == false);
|
||||||
|
BOOST_CHECK(pnode4->IsBlockOnlyConn() == false);
|
||||||
|
BOOST_CHECK(pnode4->IsFeelerConn() == false);
|
||||||
|
BOOST_CHECK(pnode4->IsAddrFetchConn() == false);
|
||||||
|
BOOST_CHECK(pnode4->IsInboundConn() == true);
|
||||||
|
BOOST_CHECK_EQUAL(pnode4->ConnectedThroughNetwork(), Network::NET_ONION);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cnetaddr_basic)
|
BOOST_AUTO_TEST_CASE(cnetaddr_basic)
|
||||||
|
|
Loading…
Add table
Reference in a new issue