Skip to content

Commit

Permalink
Tests: address placement should be deterministic by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneNyffenegger authored and furszy committed Jul 28, 2021
1 parent 8d01cbd commit fd51941
Showing 1 changed file with 10 additions and 38 deletions.
48 changes: 10 additions & 38 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ class CAddrManTest : public CAddrMan
uint64_t state;

public:
CAddrManTest()
CAddrManTest(bool makeDeterministic = true)
{
state = 1;

if (makeDeterministic) {
// Set addrman addr placement to be deterministic.
MakeDeterministic();
}
}

//! Ensure that bucket placement is always the same for testing purposes.
Expand Down Expand Up @@ -90,9 +95,6 @@ BOOST_AUTO_TEST_CASE(addrman_simple)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CNetAddr source = ResolveIP("252.2.2.2");

// Test 1: Does Addrman respond correctly when empty.
Expand Down Expand Up @@ -131,9 +133,6 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CNetAddr source = ResolveIP("252.2.2.2");

BOOST_CHECK(addrman.size() == 0);
Expand Down Expand Up @@ -163,9 +162,6 @@ BOOST_AUTO_TEST_CASE(addrman_select)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CNetAddr source = ResolveIP("252.2.2.2");

// Test 9: Select from new with 1 addr in new.
Expand Down Expand Up @@ -225,9 +221,6 @@ BOOST_AUTO_TEST_CASE(addrman_new_collisions)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CNetAddr source = ResolveIP("252.2.2.2");

BOOST_CHECK(addrman.size() == 0);
Expand All @@ -254,9 +247,6 @@ BOOST_AUTO_TEST_CASE(addrman_tried_collisions)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CNetAddr source = ResolveIP("252.2.2.2");

BOOST_CHECK(addrman.size() == 0);
Expand Down Expand Up @@ -285,10 +275,7 @@ BOOST_AUTO_TEST_CASE(addrman_find)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

BOOST_CHECK(addrman.size() == 0);
BOOST_CHECK_EQUAL(addrman.size(), 0);

CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE);
CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE);
Expand Down Expand Up @@ -324,10 +311,7 @@ BOOST_AUTO_TEST_CASE(addrman_create)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

BOOST_CHECK(addrman.size() == 0);
BOOST_CHECK_EQUAL(addrman.size(), 0);

CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE);
CNetAddr source1 = ResolveIP("250.1.2.1");
Expand All @@ -347,10 +331,7 @@ BOOST_AUTO_TEST_CASE(addrman_delete)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

BOOST_CHECK(addrman.size() == 0);
BOOST_CHECK_EQUAL(addrman.size(), 0);

CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE);
CNetAddr source1 = ResolveIP("250.1.2.1");
Expand All @@ -370,10 +351,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

// Test 22: Sanity check, GetAddr should never return anything if addrman
// Test: Sanity check, GetAddr should never return anything if addrman
// is empty.
BOOST_CHECK(addrman.size() == 0);
std::vector<CAddress> vAddr1 = addrman.GetAddr();
Expand Down Expand Up @@ -435,9 +413,6 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CAddress addr1 = CAddress(ResolveService("250.1.1.1", 8333), NODE_NONE);
CAddress addr2 = CAddress(ResolveService("250.1.1.1", 9999), NODE_NONE);

Expand Down Expand Up @@ -492,9 +467,6 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
{
CAddrManTest addrman;

// Set addrman addr placement to be deterministic.
addrman.MakeDeterministic();

CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE);
CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE);

Expand Down

0 comments on commit fd51941

Please sign in to comment.