Skip to content

Commit 8bdd924

Browse files
committed
refactor: addrman_selecttriedcollisions test
Check `Good()` directly when adding addresses. Previously, test would check `size()`, which is incorrect. Check that duplicates are also handled by checking the output from `SelectTriedCollision()` when `Good()` returns false.
1 parent 2d0bdb2 commit 8bdd924

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/test/addrman_tests.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,19 +816,21 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
816816
for (unsigned int i = 1; i < 23; i++) {
817817
CService addr = ResolveService("250.1.1." + ToString(i));
818818
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
819-
addrman.Good(addr);
820819

821-
// No collisions yet.
822-
BOOST_CHECK(addrman.size() == i);
820+
// No collisions in tried.
821+
BOOST_CHECK(addrman.Good(addr));
823822
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
824823
}
825824

826825
// Ensure Good handles duplicates well.
826+
// If an address is a duplicate, Good will return false but will not count it as a collision.
827827
for (unsigned int i = 1; i < 23; i++) {
828828
CService addr = ResolveService("250.1.1." + ToString(i));
829-
addrman.Good(addr);
830829

831-
BOOST_CHECK(addrman.size() == 22);
830+
// Unable to add duplicate address to tried table.
831+
BOOST_CHECK(!addrman.Good(addr));
832+
833+
// Verify duplicate address not marked as a collision.
832834
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
833835
}
834836
}

0 commit comments

Comments
 (0)