mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-07-25 15:49:13 +02:00
test: cover -externalip bypassing -onlynet
Add unit coverage for the -onlynet/-externalip interaction. Check that an unreachable address still fails with normal AddLocal() arguments, while the same address succeeds when the unreachable-net override is set for explicit local-address configuration.
This commit is contained in:
@@ -1590,4 +1590,47 @@ BOOST_AUTO_TEST_CASE(private_broadcast_version_does_not_update_addrman_services)
|
||||
m_node.peerman->FinalizeNode(node);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addlocal_onlynet_externalip)
|
||||
{
|
||||
// Test that `-externalip` addresses bypass `-onlynet`, but score alone does
|
||||
// not.
|
||||
|
||||
CAddress addr_onion;
|
||||
BOOST_REQUIRE(addr_onion.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
|
||||
BOOST_REQUIRE(addr_onion.IsValid());
|
||||
BOOST_REQUIRE(addr_onion.IsTor());
|
||||
|
||||
const auto reachable_nets_at_start{g_reachable_nets.All()};
|
||||
const bool discover_orig{fDiscover};
|
||||
|
||||
// Simulate using -onlynet=ipv4 -externalip=<onion>
|
||||
g_reachable_nets.RemoveAll();
|
||||
g_reachable_nets.Add(NET_IPV4);
|
||||
fDiscover = false;
|
||||
|
||||
// Now AddLocal with a non-manual score should fail for an unreachable network.
|
||||
BOOST_CHECK(!AddLocal(addr_onion, LOCAL_BIND));
|
||||
BOOST_CHECK(!IsLocal(addr_onion));
|
||||
|
||||
BOOST_CHECK(!AddLocal(addr_onion, LOCAL_MANUAL));
|
||||
BOOST_CHECK(!IsLocal(addr_onion));
|
||||
|
||||
// Whereas AddLocal for -externalip should succeed.
|
||||
BOOST_CHECK(AddLocal(addr_onion, LOCAL_MANUAL, /*add_even_if_unreachable=*/true));
|
||||
BOOST_CHECK(IsLocal(addr_onion));
|
||||
|
||||
// Normal AddLocal on a reachable network still works.
|
||||
const CNetAddr addr_ipv4{LookupHost("1.2.3.4", false).value()};
|
||||
BOOST_CHECK(AddLocal(addr_ipv4, LOCAL_MANUAL));
|
||||
BOOST_CHECK(IsLocal(CService{addr_ipv4, GetListenPort()}));
|
||||
|
||||
RemoveLocal(CService{addr_ipv4, GetListenPort()});
|
||||
RemoveLocal(addr_onion);
|
||||
g_reachable_nets.RemoveAll();
|
||||
for (const auto& net : reachable_nets_at_start) {
|
||||
g_reachable_nets.Add(net);
|
||||
}
|
||||
fDiscover = discover_orig;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user