Skip to content

Commit a98e542

Browse files
test: add addrman test for special case
if an addr matching the network requirements is only on the new table and select is invoked with new_only = false, ensure that the code selects the new table. in order to test this case, we use a non deterministic addrman. this means we cannot have more than one address in any addrman table, or risk sporadic failures when the second address happens to conflict. if the code chose a table at random, the test would fail 50% of the time Co-authored-by: Martin Zumsande <[email protected]>
1 parent 5c8b4ba commit a98e542

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/addrman_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,28 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network)
252252
}
253253
}
254254

255+
BOOST_AUTO_TEST_CASE(addrman_select_special)
256+
{
257+
// use a non-deterministic addrman to ensure a passing test isn't due to setup
258+
auto addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, /*deterministic=*/false, GetCheckRatio(m_node));
259+
260+
// add ipv4 address to the new table
261+
CNetAddr source = ResolveIP("252.2.2.2");
262+
CService addr1 = ResolveService("250.1.1.3", 8333);
263+
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
264+
265+
// add I2P address to the tried table
266+
CAddress i2p_addr;
267+
i2p_addr.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p");
268+
BOOST_CHECK(addrman->Add({i2p_addr}, source));
269+
BOOST_CHECK(addrman->Good(i2p_addr));
270+
271+
// since the only ipv4 address is on the new table, ensure that the new
272+
// table gets selected even if new_only is false. if the table was being
273+
// selected at random, this test will sporadically fail
274+
BOOST_CHECK(addrman->Select(/*new_only=*/false, NET_IPV4).first == addr1);
275+
}
276+
255277
BOOST_AUTO_TEST_CASE(addrman_new_collisions)
256278
{
257279
auto addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));

0 commit comments

Comments
 (0)