aboutsummaryrefslogtreecommitdiff
path: root/src/test/net_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/net_tests.cpp')
-rw-r--r--src/test/net_tests.cpp96
1 files changed, 52 insertions, 44 deletions
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index 5976aa3713..81b1283663 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -718,47 +718,55 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
BOOST_AUTO_TEST_CASE(LimitedAndReachable_Network)
{
- BOOST_CHECK(IsReachable(NET_IPV4));
- BOOST_CHECK(IsReachable(NET_IPV6));
- BOOST_CHECK(IsReachable(NET_ONION));
- BOOST_CHECK(IsReachable(NET_I2P));
- BOOST_CHECK(IsReachable(NET_CJDNS));
-
- SetReachable(NET_IPV4, false);
- SetReachable(NET_IPV6, false);
- SetReachable(NET_ONION, false);
- SetReachable(NET_I2P, false);
- SetReachable(NET_CJDNS, false);
-
- BOOST_CHECK(!IsReachable(NET_IPV4));
- BOOST_CHECK(!IsReachable(NET_IPV6));
- BOOST_CHECK(!IsReachable(NET_ONION));
- BOOST_CHECK(!IsReachable(NET_I2P));
- BOOST_CHECK(!IsReachable(NET_CJDNS));
-
- SetReachable(NET_IPV4, true);
- SetReachable(NET_IPV6, true);
- SetReachable(NET_ONION, true);
- SetReachable(NET_I2P, true);
- SetReachable(NET_CJDNS, true);
-
- BOOST_CHECK(IsReachable(NET_IPV4));
- BOOST_CHECK(IsReachable(NET_IPV6));
- BOOST_CHECK(IsReachable(NET_ONION));
- BOOST_CHECK(IsReachable(NET_I2P));
- BOOST_CHECK(IsReachable(NET_CJDNS));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_IPV4));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_IPV6));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_ONION));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_I2P));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_CJDNS));
+
+ g_reachable_nets.Remove(NET_IPV4);
+ g_reachable_nets.Remove(NET_IPV6);
+ g_reachable_nets.Remove(NET_ONION);
+ g_reachable_nets.Remove(NET_I2P);
+ g_reachable_nets.Remove(NET_CJDNS);
+
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_IPV4));
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_IPV6));
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_ONION));
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_I2P));
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_CJDNS));
+
+ g_reachable_nets.Add(NET_IPV4);
+ g_reachable_nets.Add(NET_IPV6);
+ g_reachable_nets.Add(NET_ONION);
+ g_reachable_nets.Add(NET_I2P);
+ g_reachable_nets.Add(NET_CJDNS);
+
+ BOOST_CHECK(g_reachable_nets.Contains(NET_IPV4));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_IPV6));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_ONION));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_I2P));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_CJDNS));
}
BOOST_AUTO_TEST_CASE(LimitedAndReachable_NetworkCaseUnroutableAndInternal)
{
- BOOST_CHECK(IsReachable(NET_UNROUTABLE));
- BOOST_CHECK(IsReachable(NET_INTERNAL));
-
- SetReachable(NET_UNROUTABLE, false);
- SetReachable(NET_INTERNAL, false);
-
- BOOST_CHECK(IsReachable(NET_UNROUTABLE)); // Ignored for both networks
- BOOST_CHECK(IsReachable(NET_INTERNAL));
+ // Should be reachable by default.
+ BOOST_CHECK(g_reachable_nets.Contains(NET_UNROUTABLE));
+ BOOST_CHECK(g_reachable_nets.Contains(NET_INTERNAL));
+
+ g_reachable_nets.RemoveAll();
+
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_UNROUTABLE));
+ BOOST_CHECK(!g_reachable_nets.Contains(NET_INTERNAL));
+
+ g_reachable_nets.Add(NET_IPV4);
+ g_reachable_nets.Add(NET_IPV6);
+ g_reachable_nets.Add(NET_ONION);
+ g_reachable_nets.Add(NET_I2P);
+ g_reachable_nets.Add(NET_CJDNS);
+ g_reachable_nets.Add(NET_UNROUTABLE);
+ g_reachable_nets.Add(NET_INTERNAL);
}
CNetAddr UtilBuildAddress(unsigned char p1, unsigned char p2, unsigned char p3, unsigned char p4)
@@ -776,13 +784,13 @@ BOOST_AUTO_TEST_CASE(LimitedAndReachable_CNetAddr)
{
CNetAddr addr = UtilBuildAddress(0x001, 0x001, 0x001, 0x001); // 1.1.1.1
- SetReachable(NET_IPV4, true);
- BOOST_CHECK(IsReachable(addr));
+ g_reachable_nets.Add(NET_IPV4);
+ BOOST_CHECK(g_reachable_nets.Contains(addr));
- SetReachable(NET_IPV4, false);
- BOOST_CHECK(!IsReachable(addr));
+ g_reachable_nets.Remove(NET_IPV4);
+ BOOST_CHECK(!g_reachable_nets.Contains(addr));
- SetReachable(NET_IPV4, true); // have to reset this, because this is stateful.
+ g_reachable_nets.Add(NET_IPV4); // have to reset this, because this is stateful.
}
@@ -790,7 +798,7 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
{
CService addr = CService(UtilBuildAddress(0x002, 0x001, 0x001, 0x001), 1000); // 2.1.1.1:1000
- SetReachable(NET_IPV4, true);
+ g_reachable_nets.Add(NET_IPV4);
BOOST_CHECK(!IsLocal(addr));
BOOST_CHECK(AddLocal(addr, 1000));
@@ -915,7 +923,7 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
ConnectionType::OUTBOUND_FULL_RELAY,
/*inbound_onion=*/false);
};
- SetReachable(NET_CJDNS, true);
+ g_reachable_nets.Add(NET_CJDNS);
CAddress addr_ipv4{Lookup("1.2.3.4", 8333, false).value(), NODE_NONE};
BOOST_REQUIRE(addr_ipv4.IsValid());