diff options
author | josibake <josibake@protonmail.com> | 2021-12-14 12:51:06 +0100 |
---|---|---|
committer | josibake <josibake@protonmail.com> | 2021-12-15 13:18:07 +0100 |
commit | 5a64dc018c04ce16202a8e58ce92d2657c0b1806 (patch) | |
tree | 5bfcb199385c98858163ac71c84f2fa9753f77cb /src/test/addrman_tests.cpp | |
parent | e281fccd8a80d7cd48c3b17d58fd4a8915e1e965 (diff) | |
download | bitcoin-5a64dc018c04ce16202a8e58ce92d2657c0b1806.tar.xz |
refactor: addrman_evictionworks test
Test for collisions and duplicates directly with `Good()`.
If an entry to tried is a duplicate, `Good()` will return false
but `SelectTriedCollision()` will be empty (assuming there were no prior
collisions). If there is a collision, `Good()` will retun false
and `SelectTriedCollision()` will return a value.
Diffstat (limited to 'src/test/addrman_tests.cpp')
-rw-r--r-- | src/test/addrman_tests.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index c93b13168e..226c4d6eec 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -901,19 +901,16 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks) for (unsigned int i = 1; i < 36; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source)); - addrman.Good(addr); // No collision yet. - BOOST_CHECK(addrman.size() == i); - BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0"); + BOOST_CHECK(addrman.Good(addr)); } // Collision between 36 and 19. CService addr = ResolveService("250.1.1.36"); BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source)); - addrman.Good(addr); + BOOST_CHECK(!addrman.Good(addr)); - BOOST_CHECK_EQUAL(addrman.size(), 36); auto info = addrman.SelectTriedCollision().first; BOOST_CHECK_EQUAL(info.ToString(), "250.1.1.19:0"); @@ -924,17 +921,17 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks) addrman.ResolveCollisions(); BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0"); - // If 36 was swapped for 19, then this should cause no collisions. - BOOST_CHECK(!addrman.Add({CAddress(addr, NODE_NONE)}, source)); - addrman.Good(addr); - + // If 36 was swapped for 19, then adding 36 to tried should fail because we + // are attempting to add a duplicate. + // We check this by verifying Good() returns false and also verifying that + // we have no collisions. + BOOST_CHECK(!addrman.Good(addr)); BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0"); - // If we insert 19 it should collide with 36 + // 19 should fail as a collision (not a duplicate) if we now attempt to move + // it to the tried table. CService addr19 = ResolveService("250.1.1.19"); - BOOST_CHECK(!addrman.Add({CAddress(addr19, NODE_NONE)}, source)); - addrman.Good(addr19); - + BOOST_CHECK(!addrman.Good(addr19)); BOOST_CHECK_EQUAL(addrman.SelectTriedCollision().first.ToString(), "250.1.1.36:0"); addrman.ResolveCollisions(); |