mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#23492: tidy up addrman unit tests
This commit is contained in:
parent
aba0ebd400
commit
5b5dd39f45
@ -68,7 +68,7 @@ public:
|
|||||||
Good(addr, nLastSuccess);
|
Good(addr, nLastSuccess);
|
||||||
|
|
||||||
bool count_failure = false;
|
bool count_failure = false;
|
||||||
int64_t nLastTry = GetAdjustedTime()-61;
|
int64_t nLastTry = GetAdjustedTime() - 61;
|
||||||
Attempt(addr, count_failure, nLastTry);
|
Attempt(addr, count_failure, nLastTry);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -88,7 +88,8 @@ static CService ResolveService(const std::string& ip, uint16_t port = 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::vector<bool> FromBytes(const unsigned char* source, int vector_size) {
|
static std::vector<bool> FromBytes(const unsigned char* source, int vector_size)
|
||||||
|
{
|
||||||
std::vector<bool> result(vector_size);
|
std::vector<bool> result(vector_size);
|
||||||
for (int byte_i = 0; byte_i < vector_size / 8; ++byte_i) {
|
for (int byte_i = 0; byte_i < vector_size / 8; ++byte_i) {
|
||||||
unsigned char cur_byte = source[byte_i];
|
unsigned char cur_byte = source[byte_i];
|
||||||
@ -247,11 +248,11 @@ BOOST_AUTO_TEST_CASE(addrman_new_collisions)
|
|||||||
CService addr = ResolveService("250.1.1." + ToString(++num_addrs));
|
CService addr = ResolveService("250.1.1." + ToString(++num_addrs));
|
||||||
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
||||||
|
|
||||||
//Test: No collision in new table yet.
|
// Test: No collision in new table yet.
|
||||||
BOOST_CHECK_EQUAL(addrman.size(), num_addrs);
|
BOOST_CHECK_EQUAL(addrman.size(), num_addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Test: new table collision!
|
// Test: new table collision!
|
||||||
CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs));
|
CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs));
|
||||||
uint32_t collisions{1};
|
uint32_t collisions{1};
|
||||||
BOOST_CHECK(addrman.Add({CAddress(addr1, NODE_NONE)}, source));
|
BOOST_CHECK(addrman.Add({CAddress(addr1, NODE_NONE)}, source));
|
||||||
@ -277,11 +278,11 @@ BOOST_AUTO_TEST_CASE(addrman_tried_collisions)
|
|||||||
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
|
||||||
addrman.Good(CAddress(addr, NODE_NONE));
|
addrman.Good(CAddress(addr, NODE_NONE));
|
||||||
|
|
||||||
//Test: No collision in tried table yet.
|
// Test: No collision in tried table yet.
|
||||||
BOOST_CHECK_EQUAL(addrman.size(), num_addrs);
|
BOOST_CHECK_EQUAL(addrman.size(), num_addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Test: tried table collision!
|
// Test: tried table collision!
|
||||||
CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs));
|
CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs));
|
||||||
uint32_t collisions{1};
|
uint32_t collisions{1};
|
||||||
BOOST_CHECK(!addrman.Add({CAddress(addr1, NODE_NONE)}, source));
|
BOOST_CHECK(!addrman.Add({CAddress(addr1, NODE_NONE)}, source));
|
||||||
@ -690,7 +691,6 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
|
|||||||
// Test: IP addresses in the different source /16 prefixes sometimes map to NO MORE
|
// Test: IP addresses in the different source /16 prefixes sometimes map to NO MORE
|
||||||
// than 1 bucket.
|
// than 1 bucket.
|
||||||
BOOST_CHECK(buckets.size() == 1);
|
BOOST_CHECK(buckets.size() == 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(addrman_serialization)
|
BOOST_AUTO_TEST_CASE(addrman_serialization)
|
||||||
@ -811,7 +811,7 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
|||||||
// Add twenty two addresses.
|
// Add twenty two addresses.
|
||||||
CNetAddr source = ResolveIP("252.2.2.2");
|
CNetAddr source = ResolveIP("252.2.2.2");
|
||||||
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);
|
addrman.Good(addr);
|
||||||
|
|
||||||
@ -822,13 +822,12 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
|||||||
|
|
||||||
// Ensure Good handles duplicates well.
|
// Ensure Good handles duplicates well.
|
||||||
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);
|
addrman.Good(addr);
|
||||||
|
|
||||||
BOOST_CHECK(addrman.size() == 22);
|
BOOST_CHECK(addrman.size() == 22);
|
||||||
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
|
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(addrman_noevict)
|
BOOST_AUTO_TEST_CASE(addrman_noevict)
|
||||||
@ -838,7 +837,7 @@ BOOST_AUTO_TEST_CASE(addrman_noevict)
|
|||||||
// Add 35 addresses.
|
// Add 35 addresses.
|
||||||
CNetAddr source = ResolveIP("252.2.2.2");
|
CNetAddr source = ResolveIP("252.2.2.2");
|
||||||
for (unsigned int i = 1; i < 36; i++) {
|
for (unsigned int i = 1; i < 36; 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);
|
addrman.Good(addr);
|
||||||
|
|
||||||
@ -861,7 +860,7 @@ BOOST_AUTO_TEST_CASE(addrman_noevict)
|
|||||||
|
|
||||||
// Lets create two collisions.
|
// Lets create two collisions.
|
||||||
for (unsigned int i = 37; i < 59; i++) {
|
for (unsigned int i = 37; i < 59; 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);
|
addrman.Good(addr);
|
||||||
|
|
||||||
@ -899,7 +898,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
|||||||
// Add 35 addresses
|
// Add 35 addresses
|
||||||
CNetAddr source = ResolveIP("252.2.2.2");
|
CNetAddr source = ResolveIP("252.2.2.2");
|
||||||
for (unsigned int i = 1; i < 36; i++) {
|
for (unsigned int i = 1; i < 36; 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);
|
addrman.Good(addr);
|
||||||
|
|
||||||
@ -946,9 +945,7 @@ static CDataStream AddrmanToStream(const AddrMan& addrman)
|
|||||||
CDataStream ssPeersIn(SER_DISK, CLIENT_VERSION);
|
CDataStream ssPeersIn(SER_DISK, CLIENT_VERSION);
|
||||||
ssPeersIn << Params().MessageStart();
|
ssPeersIn << Params().MessageStart();
|
||||||
ssPeersIn << addrman;
|
ssPeersIn << addrman;
|
||||||
std::string str = ssPeersIn.str();
|
return ssPeersIn;
|
||||||
std::vector<unsigned char> vchData(str.begin(), str.end());
|
|
||||||
return CDataStream(vchData, SER_DISK, CLIENT_VERSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(load_addrman)
|
BOOST_AUTO_TEST_CASE(load_addrman)
|
||||||
@ -1020,9 +1017,7 @@ static CDataStream MakeCorruptPeersDat()
|
|||||||
AddrInfo info = AddrInfo(addr, resolved);
|
AddrInfo info = AddrInfo(addr, resolved);
|
||||||
s << info;
|
s << info;
|
||||||
|
|
||||||
std::string str = s.str();
|
return s;
|
||||||
std::vector<unsigned char> vchData(str.begin(), str.end());
|
|
||||||
return CDataStream(vchData, SER_DISK, CLIENT_VERSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(load_addrman_corrupted)
|
BOOST_AUTO_TEST_CASE(load_addrman_corrupted)
|
||||||
|
Loading…
Reference in New Issue
Block a user