- Adds unittests for several methods in CAddrMan which are not currently tested.
- Creates unittests for CAddrinfo which had no test coverage. These tests validate security critical features.
- Refactors addrman so that tests can overrides the random number generator to allow for deterministic tests of CAddrman.select that involve tests of more than one addr in tried or new. See justification below.
- We move the MakeDeterministic method from addrman into a test class to reduce lines of code in addrman and to prevent non-test calls.
Details on GetRandInt Wrapper
To allow for deterministic tests of the select method in CAddrMan we wrap the GetRandInt function with a method RandomInt which can be overridden in a test class CAddrManTest. The RandomInt wrapper name was used so that it would not be a prefix substring of GetRandInt to avoid find and replace mistakes. Changes to random number generators as always a concern, this approach presents no risks because only subclasses of addrman can redirect calls to GetRandInt.
IPv4 IPv6 confusion
Bitcoin addr constructors assume any IP string that contains a semicolon is a IPv6 address. Thus
CService(“250.1.2.1:9999”) will create an IPv6 address with a default port number 8333. I have discovered this behavior only applies to CNetAddr constructors since CNetAddr does not take a port number.