aboutsummaryrefslogtreecommitdiff
path: root/src/test/addrman_tests.cpp
AgeCommit message (Collapse)Author
2022-07-30addrman: Use system time instead of adjusted network timeMarcoFalke
2022-07-26refactor: Use type-safe std::chrono for addrman timeMarcoFalke
2022-04-20[netgroupman] Add GetMappedAS() and GetGroup()John Newbery
These currently call through to the CNetAddr methods. The logic will be moved in a future commit.
2022-04-20[net] Move asmap into NetGroupManagerJohn Newbery
2022-01-11test: addrman unit tests: override-able check ratioVasil Dimov
In addrman unit tests, make it possible to override the check ratio from the command line, without recompiling: ``` test_bitcoin --run_test="addrman_tests/*" -- -checkaddrman=1 ``` Also, make the arguments of the constructor of `AddrManTest` the same as the arguments of `AddrMan`.
2022-01-04Merge bitcoin/bitcoin#23826: test: Make AddrMan unit tests use public ↵fanquake
interface, extend coverage ea4c9fd4ab9aaa2e8f2c2e38a75c9f05d0bfc866 test: Cover eviction by timeout in addrman_evictionworks (Martin Zumsande) 4f1bb467b556ec93c9b8f758783fda4d050da491 test: Add test for multiplicity in addrman new tables (Martin Zumsande) e880bb7836dab2018049390884220177c6db9b92 test: Add test for updating addrman entries (Martin Zumsande) f02eee8c8784dfc8db80a21ab6508f7c99298255 test: introduce utility function to retrieve an addrman (Martin Zumsande) f0e5efb82493f7a14580335ce719d5be81c8713e test: Remove unused AddrManTest class (Martin Zumsande) b696d7870b29232057600df5ddd8351888253b95 test: Remove tests for internal helper functions (Martin Zumsande) 0538520091bf2982a029a0298835400f5afbdc15 test: use AddrMan instead of AddrManTest where possible (Martin Zumsande) 1c65d427bbf61bb558cf7e18f7aff99b19f68508 test: Inline SimConnFail function (Martin Zumsande) 5b7aac34f2363822c3a1cfafda8ffc9528905058 test: delete unused GetBucketAndEntry function (Amiti Uttarwar) 2ba1e74e59a325ca6cb140757067dd5e0c7c249b test: Update addrman_serialization unit test to use AddrMan's interface (Amiti Uttarwar) dad5f760211df314d650999e0a76edb0151b4fe1 addrman: Introduce a test-only function to lookup addresses (Amiti Uttarwar) Pull request description: This PR (joint work with Amiti Uttarwar) changes the addrman unit tests such that they only use the public `AddrMan` interface: This has the advantage that the tests are less implementation-dependent, i.e. it would be possible to rewrite the internal addrman implementation (as drafted [here](https://github.com/sipa/bitcoin/tree/202106_multiindex_addrman) for using a multiindex) without having to adjust the tests. This includes the following steps: * Adding a test-only function `FindAddressEntry()` to the public addrman interface which returns info about an address in addrman (e.g. bucket, position, whethe the address is in new or tried). Obviously we want to do this sparingly, but I think a single test-only function is ok (which could also be useful elsewhere, e.g. in fuzz tests). * Removal of the `AddrManTest` subclass which would reach into AddrMan's internals, using `AddrMan` instead * Removal of tests for internal helper functions that are not publicly exposed (these are still tested indirectly via the public functions calling them). * Additional tests for previously untested features such as multiplicity in the new tables, that can be tested with the help of `FindAddressEntry()`. All in all, this PR increases the unit test coverage of AddrMan by a bit. ACKs for top commit: jnewbery: ACK ea4c9fd4ab9aaa2e8f2c2e38a75c9f05d0bfc866 josibake: reACK https://github.com/bitcoin/bitcoin/pull/23826/commits/ea4c9fd4ab9aaa2e8f2c2e38a75c9f05d0bfc866 Tree-SHA512: c2d4ec8bdc62ffd6055ddcd37dea85ec08c76889e9e417e8d7c62a96cf68a8bcbe8c67bec3344d91fa7d3c499f6d9f810962da1dddd38e70966186b10b8ab447
2022-01-03test: Cover eviction by timeout in addrman_evictionworksMartin Zumsande
2022-01-03test: Add test for multiplicity in addrman new tablesMartin Zumsande
2021-12-30scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: * 2020: fa0074e2d82928016a43ca408717154a1c70a4db * 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2021-12-28test: Add test for updating addrman entriesMartin Zumsande
This covers Connected() which updates nTime, and SetServices() which updates nServices
2021-12-28test: introduce utility function to retrieve an addrmanMartin Zumsande
2021-12-28test: Remove unused AddrManTest classMartin Zumsande
2021-12-28test: Remove tests for internal helper functionsMartin Zumsande
The logic of these functions is already covered by existing unit tests using publicly exposed functions of the interface. Therefore, removing them does not decrease test coverage.
2021-12-28test: use AddrMan instead of AddrManTest where possibleMartin Zumsande
Switches to AddrMan for tests that use no features of AddrManTest. Also removes unusued AddrManTest variables Co-Authored-By: Amiti Uttarwar <amiti@uttarwar.org>
2021-12-28test: Inline SimConnFail functionMartin Zumsande
No need for a function, since it is only used once. Co-Authored-By: Amiti Uttarwar <amiti@uttarwar.org>
2021-12-28test: delete unused GetBucketAndEntry functionAmiti Uttarwar
2021-12-28test: Update addrman_serialization unit test to use AddrMan's interfaceAmiti Uttarwar
By updating the test to use FindEntry, it no longer needs to reach into AddrMan's internals (via GetBucketAndEntry) to assert expected behaviors.
2021-12-15refactor: addrman_select testjosibake
Check that `Good()` is successful whenever it is called.
2021-12-15refactor: addrman_evictionworks testjosibake
Test for collisions and duplicates directly with `Good()`. If an entry to tried is a duplicate, `Good()` will return false but `SelectTriedCollision()` will be empty (assuming there were no prior collisions). If there is a collision, `Good()` will retun false and `SelectTriedCollision()` will return a value.
2021-12-15refactor: addrman_noevict testjosibake
Check the response from `Good()` wherever it is called. Previously, the test was using `size()` (incorrect for checking tried) and `SelectTriedCollision()` to determine if a collision happened.
2021-12-15refactor: addrman_selecttriedcollisions testjosibake
Check `Good()` directly when adding addresses. Previously, test would check `size()`, which is incorrect. Check that duplicates are also handled by checking the output from `SelectTriedCollision()` when `Good()` returns false.
2021-12-14refactor: remove dependence on AddrManTestjosibake
2021-12-14refactor: check Good() in tried_collisions testjosibake
Rather than try to infer a collision by checking `AddrMan::size`, check whether or not moving to the tried table was successful by checking the output from `AddrMan::Good`
2021-11-19scripted-diff: Use clang-tidy syntax for C++ named argumentsMarcoFalke
-BEGIN VERIFY SCRIPT- perl -0777 -pi -e 's:((\(|\{|,)(\n| )*)\/\* ?([^=* ]+) ?\*\/ ?:\1/*\4=*/:g' $( git ls-files ./src/test ./src/wallet/test ) -END VERIFY SCRIPT-
2021-11-12style: Use 4 spaces for indentation, not 5MarcoFalke
The wrong indentation breaks editor workflows. Can be reviewed with --ignore-all-space
2021-11-12test: Remove unused CDataStream copyMarcoFalke
2021-11-09[addrman] [tests] Remove AddrManUncorrupted subclassJohn Newbery
It doesn't do anything different from the base AddrMan class.
2021-11-09[addrman] [tests] Remove AddrManCorrupted subclassJohn Newbery
It's only used to create a corrupted peers.dat file. We can do that directly in a pure function.
2021-11-09[addrman] [tests] Tidy up unused arguments in addrman test functionsJohn Newbery
2021-11-09[addrman] [tests] Remove deterministic argument and member from AddrManTestJohn Newbery
It's always set to true.
2021-10-28[addrman] Add Add_() inner function, fix Add() return semanticsJohn Newbery
Previously, Add() would return true if the function created a new AddressInfo object, even if that object could not be successfully entered into the new table and was deleted. That would happen if the new table position was already taken and the existing entry could not be removed. Instead, return true if the new AddressInfo object is successfully entered into the new table. This fixes a bug in the "Added %i addresses" log, which would not always accurately log how many addresses had been added. p2p_addrv2_relay.py and p2p_addr_relay.py need to be updated since they were incorrectly asserting on the buggy log (assuming that addresses are added to addrman, when there could in fact be new table position collisions that prevent some of those address records from being added).
2021-10-22Make AddrMan support multiple ports per IPPieter Wuille
2021-09-28[style] Run changed files through clang formatter.Amiti Uttarwar
2021-09-28scripted-diff: Rename CAddrInfo to AddrInfoAmiti Uttarwar
-BEGIN VERIFY SCRIPT- git grep -l CAddrInfo src/ | xargs sed -i 's/CAddrInfo/AddrInfo/g' -END VERIFY SCRIPT-
2021-09-28scripted-diff: Rename CAddrMan to AddrManAmiti Uttarwar
-BEGIN VERIFY SCRIPT- git grep -l CAddrMan src/ test/ | xargs sed -i 's/CAddrMan/AddrMan/g' -END VERIFY SCRIPT-
2021-09-28[net, addrman] Remove external dependencies on CAddrInfo objectsAmiti Uttarwar
CAddrInfo objects are an implementation detail of how AddrMan manages and adds metadata to different records. Encapsulate this logic by updating Select & SelectTriedCollision to return the additional info that the callers need.
2021-09-28[addrman] Introduce CAddrMan::Impl to encapsulate addrman implementation.Amiti Uttarwar
Introduce the pimpl pattern for CAddrMan to separate the implementation details from the externally used object representation. This reduces compile-time dependencies and conceptually clarifies AddrMan's interface from the implementation specifics. Since the unit & fuzz tests currently rely on accessing CAddrMan internals, this commit introduces addrman_impl.h, which is exclusively imported by addrman.cpp and test files. Review hint: git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-09-09Raise InitError when peers.dat is invalid or corruptedMarcoFalke
2021-09-07Remove confusing CAddrDBMarcoFalke
The class only stores the file path, reading it from a global. Globals are confusing and make testing harder. The method reading from a stream does not even use any class members, so putting it in a class is also confusing.
2021-09-07Move addrman includes from .h to .cppMarcoFalke
This is a follow-up to the code move in commit a820e79512b67b1bfda20bdc32b47086d2b0910d
2021-08-27[addrman] Set m_asmap in CAddrMan initializer listJohn Newbery
This allows us to make it const.
2021-08-19[addrman] inline Clear() into CAddrMan ctorJohn Newbery
Clear() is now only called from the ctor, so just inline the code into that function. The LOCK(cs) can be removed, since there can be no data races in the ctor. Also move the function definition out of the header and into the cpp file.
2021-08-19[addrman] Remove all public uses of CAddrMan.Clear() from the testsJohn Newbery
Just use unique_ptr<CAddrMan>s and reset the pointer if a frest addrman is required. Also make CAddrMan::Clear() private to ensure that no call sites are missed.
2021-08-18[tests] Remove CAddrMan.Clear() call from CAddrDB::Read()John Newbery
`bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)` is _only_ called from the tests, and the call to addr.Clear() only exists so that a test that Clear() is called passes. Remove that test and the call.
2021-08-17[MOVEONLY] [tests] Move addrman ser/deser tests to addrman_tests.cppJohn Newbery
Addrman serialization/deserialization tests are currently in net_tests.cpp. Move them to addrman_tests.cpp with the rest of the addrman tests. Reviewer hint: review using `git diff --color-moved=dimmed-zebra`
2021-08-15[addrman] Merge the two Add() functionsAmiti Uttarwar
Merge the two definitions of this overloaded function to reduce code duplication.
2021-08-12[addrman] Make addrman consistency checks a runtime optionJohn Newbery
Currently addrman consistency checks are a compile time option, and are not enabled in our CI. It's unlikely anyone is running these consistency checks. Make them a runtime option instead, where users can enable addrman consistency checks every n operations (similar to mempool tests). Update the addrman unit tests to do internal consistency checks every 100 operations (checking on every operations causes the test runtime to increase by several seconds). Also assert on a failed addrman consistency check to terminate program execution.
2021-08-05[tests] Make deterministic addrman use nKey = 1John Newbery
addrman_tests fail when consistency checks are enabled, since the tests set the deterministic test addrman's nKey value to zero, which is an invalid value. Change this so that deterministic addrman's nKey value is set to 1. This requires updating a few tests that are using magic values derived from nKey being set to 0.
2021-08-05[addrman] Add deterministic argument to CAddrMan ctorJohn Newbery
Removes the need for tests to update nKey and insecure_rand after constructing a CAddrMan.
2021-07-23Add missing GUARDED_BY to CAddrMan::insecure_randMarcoFalke