e8ae1db864style-only: Make AcceptToMemoryPool signature readable (Carl Dong)8f5c100064style-only: Make CheckSequenceLock signature readable (Carl Dong)8c824819c8validation: Use *this in CChainState::LoadMempool (Carl Dong)0a9a24d8c7validation: Pass in chainstate to UpdateMempoolForReorg (Carl Dong)7142018812validation: Pass in chainstate to CTxMemPool::removeForReorg (Carl Dong)71734c65dcvalidation: Pass in chain to ::TestLockPointValidity (Carl Dong)120aaba9actree-wide: Fix erroneous AcceptToMemoryPool replacements (Carl Dong)417dafc1eevalidation: Remove old AcceptToMemoryPool w/o chainstate param (Carl Dong)3704433c4fscripted-diff: Invoke ::AcceptToMemoryPool with chainstate (Carl Dong)229bc37b5fvalidation: Pass in chainstate to ::AcceptToMemoryPool (Carl Dong)d0da7ea57avalidation: Pass in chainstate to ::LoadMempool (Carl Dong)3a205c43dcvalidation: Pass in chainstate to AcceptToMemoryPoolWithTime (Carl Dong)d8a816329cvalidation: Add chainstate member to MemPoolAccept (Carl Dong)4c15942b79validation: Pass in chainstate to ::CheckSequenceLocks (Carl Dong)577b774d0cvalidation: Remove old CheckFinalTx w/o chain tip param (Carl Dong)7031cf89dbscripted-diff: Invoke ::CheckFinalTx with chain tip (Carl Dong)d015eaa550validation: Pass in chain tip to ::CheckFinalTx (Carl Dong)252b489c9fvalidation: Pass in coins tip to CheckInputsFromMempoolAndCache (Carl Dong)73a6d2b7bevalidation: Pass in chainstate to IsCurrentForFeeEstimation (Carl Dong)d1f932b0b0validation: Pass in coins cache to ::LimitMempoolSize (Carl Dong) Pull request description: Overall PR: #20158 (tree-wide: De-globalize ChainstateManager) Note to reviewers: 1. This bundle may _apparently_ introduce usage of `g_chainman` or `::Chain(state|)Active()` globals, but these are resolved later on in the overall PR. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits) 2. There may be seemingly obvious local references to `ChainstateManager` or other validation objects which are not being used in callers of the current function in question, this is done intentionally to **_keep each commit centered around one function/method_** to ease review and to make the overall change systematic. We don't assume anything about our callers. Rest assured that once we are considering that particular caller in later commits, we will use the obvious local references. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits) 3. When changing a function/method that has many callers (e.g. `LookupBlockIndex` with 55 callers), it is sometimes easier (and less error-prone) to use a scripted-diff. When doing so, there will be 3 commits in sequence so that every commit compiles like so: 1. Add `new_function`, make `old_function` a wrapper of `new_function`, divert all calls to `old_function` to `new_function` **in the local module only** 2. Scripted-diff to divert all calls to `old_function` to `new_function` **in the rest of the codebase** 3. Remove `old_function` ACKs for top commit: glozow: reACKe8ae1db864via `git range-diff 15f0042...e8ae1db`, only change is fixing ATMP call from conflict MarcoFalke: ACKe8ae1db864📣 Tree-SHA512: 6af50f04940a69c5c3d3796a24f32f963fa02503cdc1155cc11fff832a99172b407cd163a19793080a5af98580f051b48195b62ec4a797ba2763b4883174153d
Unit tests
The sources in this directory are unit test cases. Boost includes a unit testing framework, and since Bitcoin Core already uses Boost, it makes sense to simply use this framework rather than require developers to configure some other framework (we want as few impediments to creating unit tests as possible).
The build system is set up to compile an executable called test_bitcoin
that runs all of the unit tests. The main source file for the test library is found in
util/setup_common.cpp.
Compiling/running unit tests
Unit tests will be automatically compiled if dependencies were met in ./configure
and tests weren't explicitly disabled.
After configuring, they can be run with make check.
To run the unit tests manually, launch src/test/test_bitcoin. To recompile
after a test file was modified, run make and then run the test again. If you
modify a non-test file, use make -C src/test to recompile only what's needed
to run the unit tests.
To add more unit tests, add BOOST_AUTO_TEST_CASE functions to the existing
.cpp files in the test/ directory or add new .cpp files that
implement new BOOST_AUTO_TEST_SUITE sections.
To run the GUI unit tests manually, launch src/qt/test/test_bitcoin-qt
To add more GUI unit tests, add them to the src/qt/test/ directory and
the src/qt/test/test_main.cpp file.
Running individual tests
test_bitcoin has some built-in command-line arguments; for
example, to run just the getarg_tests verbosely:
test_bitcoin --log_level=all --run_test=getarg_tests -- DEBUG_LOG_OUT
log_level controls the verbosity of the test framework, which logs when a
test case is entered, for example. The DEBUG_LOG_OUT after the two dashes
redirects the debug log, which would normally go to a file in the test datadir
(BasicTestingSetup::m_path_root), to the standard terminal output.
... or to run just the doubledash test:
test_bitcoin --run_test=getarg_tests/doubledash
Run test_bitcoin --help for the full list.
Adding test cases
To add a new unit test file to our test suite you need
to add the file to src/Makefile.test.include. The pattern is to create
one test file for each class or source file for which you want to create
unit tests. The file naming convention is <source_filename>_tests.cpp
and such files should wrap their tests in a test suite
called <source_filename>_tests. For an example of this pattern,
see uint256_tests.cpp.
Logging and debugging in unit tests
make check will write to a log file foo_tests.cpp.log and display this file
on failure. For running individual tests verbosely, refer to the section
above.
To write to logs from unit tests you need to use specific message methods
provided by Boost. The simplest is BOOST_TEST_MESSAGE.
For debugging you can launch the test_bitcoin executable with gdbor lldb and
start debugging, just like you would with any other program:
gdb src/test/test_bitcoin