mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
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.
This commit is contained in:
parent
2d0bdb2089
commit
8bdd9240d4
1 changed files with 7 additions and 5 deletions
|
@ -816,19 +816,21 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
||||||
for (unsigned int i = 1; i < 23; i++) {
|
for (unsigned int i = 1; i < 23; i++) {
|
||||||
CService addr = ResolveService("250.1.1." + ToString(i));
|
CService addr = ResolveService("250.1.1." + ToString(i));
|
||||||
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
||||||
addrman.Good(addr);
|
|
||||||
|
|
||||||
// No collisions yet.
|
// No collisions in tried.
|
||||||
BOOST_CHECK(addrman.size() == i);
|
BOOST_CHECK(addrman.Good(addr));
|
||||||
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
|
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure Good handles duplicates well.
|
// 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++) {
|
for (unsigned int i = 1; i < 23; i++) {
|
||||||
CService addr = ResolveService("250.1.1." + ToString(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");
|
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue