5f96d7d22drpc: gettxoutsetinfo rejects hash_serialized_2 for specific height (Fabian Jahr)23fe50436btest: Add test for coinstatsindex behavior in reorgs (Fabian Jahr)90c966b0f3rpc: Allow gettxoutsetinfo and getblockstats for stale blocks (Fabian Jahr)b9362392aeindex, rpc: Add use_index option for gettxoutsetinfo (Fabian Jahr)bb7788b121test: Test coinstatsindex robustness across restarts (Fabian Jahr)e0938c2909test: Add tests for block_info in gettxoutsetinfo (Fabian Jahr)2501576eccrpc, index: Add verbose amounts tracking to Coinstats index (Fabian Jahr)655d929836test: add coinstatsindex getindexinfo coverage, improve current tests (Jon Atack)ca01bb8d68rpc: Add Coinstats index to getindexinfo (Fabian Jahr)57a026c30ftest: Add unit test for Coinstats index (Fabian Jahr)6a4c0c09abtest: Add functional test for Coinstats index (Fabian Jahr)3f166ecc12rpc: gettxoutsetinfo can be requested for specific blockheights (Fabian Jahr)3c914d58ffindex: Coinstats index can be activated with command line flag (Fabian Jahr)dd58a4de21index: Add Coinstats index (Fabian Jahr)a8a46c4b3crefactor: Simplify ApplyStats and ApplyHash (Fabian Jahr)9c8a265fd2refactor: Pass hash_type to CoinsStats in stats object (Fabian Jahr)2e2648a902crypto: Make MuHash Remove method efficient (Fabian Jahr) Pull request description: This is part of the coinstats index project tracked in #18000 While the review of the new UTXO set hash algorithm (MuHash) takes longer recently #19328 was merged which added the possibility to run `gettxoutsetinfo` with a specific hash type. As the first type it added `hash_type=none` which skips the hashing of the UTXO set altogether. This alone did not make `gettxoutsetinfo` much faster but it allows the use of an index for the remaining coin statistics even before a new hashing algorithm has been added. Credit to Sjors for the idea to take this intermediate step. Features summary: - Users can start their node with the option `-coinstatsindex` which syncs the index in the background - After the index is synced the user can use `gettxoutsetinfo` with `hash_type=none` or `hash_type=muhash` and will get the response instantly out of the index - The user can specify a height or block hash when calling `gettxoutsetinfo` to see coin statistics at a specific block height ACKs for top commit: Sjors: re-tACK5f96d7d22djonatack: Code review re-ACK5f96d7d22dper `git range-diff13d27b407201d3 5f96d7d` promag: Tested ACK5f96d7d22d. Light code review ACK5f96d7d22d. Tree-SHA512: cbca78bee8e9605c19da4fbcd184625fb280200718396c694a56c7daab6f44ad23ca9fb5456d09f245d8b8d9659fdc2b3f3ce5e953c1c6cf4003dbc74c0463c2
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