Skip to content

Commit 28d7e55

Browse files
committed
test: Add tests for unfiltered GetAddr usage
1 parent b8843d3 commit 28d7e55

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/addrman_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,24 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
429429
BOOST_CHECK_EQUAL(addrman->Size(), 2006U);
430430
}
431431

432+
BOOST_AUTO_TEST_CASE(getaddr_unfiltered)
433+
{
434+
auto addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));
435+
436+
// Set time on this addr so isTerrible = false
437+
CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE);
438+
addr1.nTime = Now<NodeSeconds>();
439+
// Not setting time so this addr should be isTerrible = true
440+
CAddress addr2 = CAddress(ResolveService("250.251.2.2", 9999), NODE_NONE);
441+
442+
CNetAddr source = ResolveIP("250.1.2.1");
443+
BOOST_CHECK(addrman->Add({addr1, addr2}, source));
444+
445+
// Filtered GetAddr should only return addr1
446+
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 1U);
447+
// Unfiltered GetAddr should return addr1 and addr2
448+
BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 2U);
449+
}
432450

433451
BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy)
434452
{

0 commit comments

Comments
 (0)