diff options
author | Jon Atack <jon@atack.com> | 2021-04-22 16:46:21 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2021-06-14 14:01:44 +0200 |
commit | 7c2284eda22a08dbf2a560894e496e245d026ee0 (patch) | |
tree | b1b5cb245617bbb1866e96271d279b7a93965769 | |
parent | ce02dd1ef1f7f54f33780b32f195d31c1cc87318 (diff) |
test: add tests for inbound eviction protection of I2P peers
-rw-r--r-- | src/test/net_peer_eviction_tests.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/net_peer_eviction_tests.cpp b/src/test/net_peer_eviction_tests.cpp index bf56e1bea7..35dfe6c4af 100644 --- a/src/test/net_peer_eviction_tests.cpp +++ b/src/test/net_peer_eviction_tests.cpp @@ -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 |