test: add tests for inbound eviction protection of I2P peers

This commit is contained in:
Jon Atack 2021-04-22 16:46:21 +02:00
parent ce02dd1ef1
commit 7c2284eda2
No known key found for this signature in database
GPG Key ID: 4F5721B3D0E3921D

View File

@ -157,6 +157,29 @@ BOOST_AUTO_TEST_CASE(peer_protection_test)
/* unprotected_peer_ids */ {3, 4, 5, 6, 10, 11},
random_context));
// Expect 1/4 I2P peers to be protected from eviction,
// if no onion or localhost peers.
BOOST_CHECK(IsProtected(
num_peers, [](NodeEvictionCandidate& c) {
c.m_is_local = false;
c.m_network = (c.id == 2 || c.id == 7 || c.id == 10) ? NET_I2P : NET_IPV4;
},
/* protected_peer_ids */ {2, 7, 10},
/* unprotected_peer_ids */ {},
random_context));
// Expect 1/4 I2P peers and 1/4 of the other peers to be protected,
// sorted by longest uptime (lowest nTimeConnected), if no onion or localhost peers.
BOOST_CHECK(IsProtected(
num_peers, [](NodeEvictionCandidate& c) {
c.nTimeConnected = c.id;
c.m_is_local = false;
c.m_network = (c.id == 4 || c.id > 8) ? NET_I2P : NET_IPV6;
},
/* protected_peer_ids */ {0, 1, 2, 4, 9, 10},
/* unprotected_peer_ids */ {3, 5, 6, 7, 8, 11},
random_context));
// Tests with 2 networks...
// Combined test: expect having 1 localhost and 1 onion peer out of 4 to