dash/src/test
pasta bd27f65601
Merge #6284: backport: bitcoin#21713, #21856, #22061, #22122, #22172, #22261, #22381, #22445, #22447
8f06ac9dfa Merge bitcoin/bitcoin#22172: doc: update tor.md, release notes with removal of tor v2 support (W. J. van der Laan)
9b22501a4d Merge bitcoin/bitcoin#22122: ci: Bump macOS image to big-sur-xcode-12.5 (MarcoFalke)
3b05a99b50 Merge bitcoin/bitcoin#22106: refactor: address ProcessNewBlock comments from #21713 (fanquake)
c8725560c9 Merge bitcoin/bitcoin#21856: doc: add OSS-Fuzz section to fuzzing.md doc (MarcoFalke)
facf685285 Merge bitcoin/bitcoin#22261: [p2p/mempool] Two small fixes to node broadcast logic (fanquake)
1430897fc4 Merge bitcoin/bitcoin#22445: fuzz: Move implementations of non-template fuzz helpers from util.h to util.cpp (MarcoFalke)
f0c62d50a5 Merge bitcoin/bitcoin#22447: test: whitelist rpc_rawtransaction peers to speed up tests (fanquake)
b609514142 Merge #22381: guix: Test security-check sanity before performing them (Carl Dong)
9ef68d1905 Merge bitcoin/bitcoin#22061: ci: Bump multiprocess memory (fanquake)

Pull request description:

  ## Issue being fixed or feature implemented
  Regular backports from bitcoin v22

  ## What was done?
  See commits

  ## How Has This Been Tested?
  Run unit and functional tests

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  UdjinM6:
    utACK 8f06ac9dfa
  PastaPastaPasta:
    utACK 8f06ac9dfa

Tree-SHA512: f800b7ca8d357f2d02ce5cb1fc4951c2765242676c5494efd5e22e8f6d41d889e1fa2f888930f72aded75813413c6488d8a7d96baa2cf4820e3461464708658e
2024-09-27 10:47:26 -05:00
..
data Merge #19698: test: apply strict verification flags for transaction tests and assert backwards compatibility 2024-06-20 12:23:13 +07:00
fuzz Merge #6284: backport: bitcoin#21713, #21856, #22061, #22122, #22172, #22261, #22381, #22445, #22447 2024-09-27 10:47:26 -05:00
util feat: removed 2 checkpoints: TestChainDIP3Setup and TestChainV19Setup from unit tests 2024-09-26 14:16:38 +07:00
addrman_tests.cpp merge bitcoin#27015: bitcoin#26847 fixups (AddrMan totals) 2024-09-13 16:57:54 +00:00
allocator_tests.cpp
amount_tests.cpp Merge #20305: wallet: introduce fee_rate sat/vB param/option 2024-09-23 02:13:14 +07:00
arith_uint256_tests.cpp
banman_tests.cpp merge bitcoin#22362: Drop only invalid entries when reading banlist.json 2024-09-08 16:24:36 +00:00
base32_tests.cpp
base58_tests.cpp Merge bitcoin/bitcoin#21902: refactor: Remove useless extern keyword 2024-04-23 09:15:19 -05:00
base64_tests.cpp
bech32_tests.cpp
bip32_tests.cpp
bip324_tests.cpp merge bitcoin#28196: BIP324 connection support 2024-09-20 12:24:22 +00:00
block_reward_reallocation_tests.cpp style: apply clang format for new changes 2024-09-26 14:17:06 +07:00
blockchain_tests.cpp
blockencodings_tests.cpp merge bitcoin#25147: follow ups to #20799 (removing support for v1 compact blocks) 2024-06-10 17:31:24 +00:00
blockfilter_index_tests.cpp refactor: remove unused includes from unit tests 2024-07-13 00:13:10 +07:00
blockfilter_tests.cpp Merge #20813: scripted-diff: Bump copyright headers 2024-04-10 03:19:34 +07:00
bloom_tests.cpp
bls_tests.cpp
bswap_tests.cpp Merge #21531: test: remove qt byteswap compattests 2024-04-10 03:19:40 +07:00
cachemap_tests.cpp
cachemultimap_tests.cpp
checkdatasig_tests.cpp
checkqueue_tests.cpp
coins_tests.cpp merge bitcoin#25325: Add pool based memory resource 2024-09-04 16:29:30 +00:00
coinstatsindex_tests.cpp merge bitcoin#21866: Farewell, global Chainstate! 2024-06-26 13:50:50 +00:00
compilerbug_tests.cpp
compress_tests.cpp
crypto_tests.cpp
cuckoocache_tests.cpp
dbwrapper_tests.cpp Merge bitcoin/bitcoin#24338: util: Work around libstdc++ create_directories issue 2024-08-14 12:47:45 +07:00
denialofservice_tests.cpp Merge #6264: backport: Merge bitcoin#23142, (partial) bitcoin-core/gui#409, 23333, 23755, (partial) 22981 2024-09-24 08:59:35 -05:00
descriptor_tests.cpp merge bitcoin#20867: Support up to 20 keys for multisig under Segwit context 2024-06-27 19:27:37 +00:00
dip0020opcodes_tests.cpp
dynamic_activation_thresholds_tests.cpp refactor: remove unused includes from unit tests 2024-07-13 00:13:10 +07:00
evo_assetlocks_tests.cpp merge bitcoin#21866: Farewell, global Chainstate! 2024-06-26 13:50:50 +00:00
evo_deterministicmns_tests.cpp style: apply clang format for new changes 2024-09-26 14:17:06 +07:00
evo_mnhf_tests.cpp feat: actually test something EHF unit tests 2024-08-26 14:19:44 +07:00
evo_simplifiedmns_tests.cpp merge bitcoin#26261: cleanup LookupIntern, Lookup and LookupHost 2024-09-11 18:34:06 +00:00
evo_trivialvalidation.cpp
evo_utils_tests.cpp
flatfile_tests.cpp merge bitcoin#21850: Remove GetDataDir(net_specific) function 2024-07-23 17:45:24 +00:00
fs_tests.cpp merge bitcoin#24331: Revert back MoveFileExW call for MinGW-w64 2024-09-08 16:29:03 +00:00
getarg_tests.cpp Merge #21244: Move GetDataDir to ArgsManager 2024-04-16 09:20:32 -05:00
governance_validators_tests.cpp
hash_tests.cpp
i2p_tests.cpp merge bitcoin#21850: Remove GetDataDir(net_specific) function 2024-07-23 17:45:24 +00:00
interfaces_tests.cpp merge bitcoin#22932: Add CBlockIndex lock annotations, guard nStatus/nFile/nDataPos/nUndoPos by cs_main 2024-07-19 17:17:48 +00:00
key_io_tests.cpp Merge bitcoin/bitcoin#21902: refactor: Remove useless extern keyword 2024-04-23 09:15:19 -05:00
key_tests.cpp Merge bitcoin/bitcoin#24213: refactor: use Span in random.* 2024-06-06 22:58:30 -05:00
lcg.h
limitedmap_tests.cpp
llmq_dkg_tests.cpp
logging_tests.cpp Merge bitcoin/bitcoin#22904: sync, log: inline lock contention logging macro to fix duration, improve BCLog::LogMsg() 2024-06-04 12:51:04 -05:00
main.cpp merge bitcoin#23373: Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change 2024-09-03 14:57:50 +00:00
Makefile
mempool_tests.cpp Merge #21676: test: Use mocktime to avoid intermittent failure in rpc_tests 2024-04-11 02:26:04 +07:00
merkle_tests.cpp Merge #20813: scripted-diff: Bump copyright headers 2024-04-10 03:19:34 +07:00
merkleblock_tests.cpp
miner_tests.cpp Merge bitcoin/bitcoin#22277: test: Properly set BIP34 height in CreateNewBlock_validity unit test 2024-07-25 10:44:24 -05:00
multisig_tests.cpp
net_peer_eviction_tests.cpp merge bitcoin#23758: Use type-safe mockable time for peer connection time 2024-06-12 16:37:11 +00:00
net_tests.cpp merge bitcoin#28525: Drop v2 garbage authentication packet 2024-09-20 12:24:23 +00:00
netbase_tests.cpp merge bitcoin#26261: cleanup LookupIntern, Lookup and LookupHost 2024-09-11 18:34:06 +00:00
pmt_tests.cpp
policyestimator_tests.cpp
pool_tests.cpp merge bitcoin#25325: Add pool based memory resource 2024-09-04 16:29:30 +00:00
pow_tests.cpp test: simplify pow_test's get_next_work block index construction 2024-09-18 07:38:48 +00:00
prevector_tests.cpp
raii_event_tests.cpp Merge #20813: scripted-diff: Bump copyright headers 2024-04-10 03:19:34 +07:00
random_tests.cpp Merge bitcoin/bitcoin#26827: doc: use "std lib clock" over "C++11 clock" 2024-08-12 11:52:41 +07:00
ratecheck_tests.cpp
README.md merge bitcoin#23373: Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change 2024-09-03 14:57:50 +00:00
reverselock_tests.cpp
rpc_tests.cpp Merge #21574: Drop JSONRPCRequest constructors after #21366 2024-07-16 00:25:06 +07:00
sanity_tests.cpp Merge #20813: scripted-diff: Bump copyright headers 2024-04-10 03:19:34 +07:00
scheduler_tests.cpp
script_p2pk_tests.cpp
script_p2pkh_tests.cpp
script_p2sh_tests.cpp
script_standard_tests.cpp Merge bitcoin/bitcoin#21840: test: Misc refactor to get rid of &foo[0] raw pointers 2024-07-26 23:40:04 +07:00
script_tests.cpp merge bitcoin#20744: Use std::filesystem. Remove Boost Filesystem & System 2024-08-06 18:00:39 +00:00
scriptnum10.h
scriptnum_tests.cpp
serfloat_tests.cpp merge bitcoin#22633: Replace remaining binascii method calls 2024-07-23 17:45:24 +00:00
serialize_tests.cpp merge bitcoin#24406: Fix Wambiguous-reversed-operator compiler warnings 2024-04-23 15:34:50 +00:00
settings_tests.cpp merge bitcoin#20744: Use std::filesystem. Remove Boost Filesystem & System 2024-08-06 18:00:39 +00:00
sighash_tests.cpp Merge bitcoin/bitcoin#21902: refactor: Remove useless extern keyword 2024-04-23 09:15:19 -05:00
sigopcount_tests.cpp
skiplist_tests.cpp
sock_tests.cpp
streams_tests.cpp merge bitcoin#20744: Use std::filesystem. Remove Boost Filesystem & System 2024-08-06 18:00:39 +00:00
subsidy_tests.cpp
sync_tests.cpp
system_tests.cpp Merge #20813: scripted-diff: Bump copyright headers 2024-04-10 03:19:34 +07:00
timedata_tests.cpp partial bitcoin#20196: fix GetListenPort() to derive the proper port 2024-04-26 20:25:31 +00:00
torcontrol_tests.cpp
transaction_tests.cpp Merge bitcoin/bitcoin#22860: test: Always clear reject reason in IsStandard tx test 2024-08-22 10:00:01 -05:00
txindex_tests.cpp merge bitcoin#21866: Farewell, global Chainstate! 2024-06-26 13:50:50 +00:00
txvalidation_tests.cpp feat: enforce DIP0001 from first block on regtest and drop fDIP0001ActiveAtTip 2024-08-16 10:57:48 +07:00
txvalidationcache_tests.cpp Merge bitcoin/bitcoin#22818: test: Activate all regtest softforks at height 1, unless overridden 2024-08-14 16:58:46 +07:00
uint256_tests.cpp
util_tests.cpp Merge bitcoin/bitcoin#21786: wallet: ensure sat/vB feerates are in range (mantissa of 3) 2024-09-23 02:13:14 +07:00
util_threadnames_tests.cpp
validation_block_tests.cpp (partial) Merge bitcoin/bitcoin#22981: doc: Fix incorrect C++ named args 2024-09-12 18:57:30 +05:30
validation_chainstate_tests.cpp merge bitcoin#22564: Move mutable globals cleared in ::UnloadBlockIndex to BlockManager 2024-08-23 06:57:37 +00:00
validation_chainstatemanager_tests.cpp merge bitcoin#22564: Move mutable globals cleared in ::UnloadBlockIndex to BlockManager 2024-08-23 06:57:37 +00:00
validation_flush_tests.cpp merge bitcoin#25325: Add pool based memory resource 2024-09-04 16:29:30 +00:00
validation_tests.cpp merge bitcoin#21953: fuzz: Add utxo_snapshot target 2024-07-23 17:45:24 +00:00
validationinterface_tests.cpp
versionbits_tests.cpp Merge bitcoin/bitcoin#24032: Add defaults to vDeployments to avoid uninitialized variables 2024-07-24 14:04:29 -05:00
xoroshiro128plusplus_tests.cpp

Unit tests

The sources in this directory are unit test cases. Boost includes a unit testing framework, and since Dash 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_dash 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_dash. 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_dash-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_dash accepts the command line arguments from the boost framework. For example, to run just the getarg_tests suite of tests:

test_dash --log_level=all --run_test=getarg_tests

log_level controls the verbosity of the test framework, which logs when a test case is entered, for example. test_dash also accepts the command line arguments accepted by dashd. Use -- to separate both types of arguments:

test_dash --log_level=all --run_test=getarg_tests -- -printtoconsole=1

The -printtoconsole=1 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_dash --run_test=getarg_tests/doubledash

Run test_dash --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_dash executable with gdb or lldb and start debugging, just like you would with any other program:

gdb src/test/test_dash

Segmentation faults

If you hit a segmentation fault during a test run, you can diagnose where the fault is happening by running gdb ./src/test/test_dash and then using the bt command within gdb.

Another tool that can be used to resolve segmentation faults is valgrind.

If for whatever reason you want to produce a core dump file for this fault, you can do that as well. By default, the boost test runner will intercept system errors and not produce a core file. To bypass this, add --catch_system_errors=no to the test_dash arguments and ensure that your ulimits are set properly (e.g. ulimit -c unlimited).

Running the tests and hitting a segmentation fault should now produce a file called core (on Linux platforms, the file name will likely depend on the contents of /proc/sys/kernel/core_pattern).

You can then explore the core dump using

gdb src/test/test_dash core

(gbd) bt  # produce a backtrace for where a segfault occurred