diff options
author | josibake <josibake@protonmail.com> | 2021-12-14 11:26:55 +0100 |
---|---|---|
committer | josibake <josibake@protonmail.com> | 2021-12-15 13:15:22 +0100 |
commit | 8bdd9240d4310aafa1332159355f106a8fcfc5c9 (patch) | |
tree | 642fabaa1a43817fbf2fbdf334660389466f347b /src/test/addrman_tests.cpp | |
parent | 2d0bdb2089644f5904629413423cdc897911b081 (diff) | |
download | bitcoin-8bdd9240d4310aafa1332159355f106a8fcfc5c9.tar.xz |
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.
Diffstat (limited to 'src/test/addrman_tests.cpp')
-rw-r--r-- | src/test/addrman_tests.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index b700c3ae22..133345001f 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -816,19 +816,21 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision) for (unsigned int i = 1; i < 23; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source)); - addrman.Good(addr); - // No collisions yet. - BOOST_CHECK(addrman.size() == i); + // No collisions in tried. + BOOST_CHECK(addrman.Good(addr)); BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0"); } // Ensure Good handles duplicates well. + // If an address is a duplicate, Good will return false but will not count it as a collision. for (unsigned int i = 1; i < 23; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); - addrman.Good(addr); - BOOST_CHECK(addrman.size() == 22); + // Unable to add duplicate address to tried table. + BOOST_CHECK(!addrman.Good(addr)); + + // Verify duplicate address not marked as a collision. BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0"); } } |