You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile.test.include 5.1KB

[Tests] Adding unit tests for GetDifficulty in blockchain.cpp. blockchain.cpp has low unit test coverage. This commit is intended to start improving its code coverage to reasonable levels. One or more follow up commits will complete the task that this commit is starting (though the usefulness of this commit is not dependent upon later commits). Note that these tests were not written based upon a specification of how GetDifficulty *should* work, but rather how it actually *does* work. As a result, if there are any bugs in the current GetDifficulty implementation, these unit tests serve to lock them in rather than expose them. -- Why has blockchain.cpp been modified if this is a unit testing change? Since the existing GetDifficulty function relies on a global variable, chainActive, it was not suitable for unit testing purposes. Both the existing GetDifficulty function and the unit tests now call through to a new, more modular version of GetDifficulty that can work on any chain, not just chainActive. -- Why does blockchain_tests.cpp directly include blockchain.cpp instead of blockchain.h? While the new GetDifficulty function's signature is arguably better than the old one's, it still isn't great, and doesn't seem to warrant inclusion as part of the blockchain.h API, especially since only test code is directly using it. If a better way of exposing the new GetDifficulty function to unit tests exists, please mention it and the commit will be updated accordingly. -- Why is the test fixture named blockchain_difficulty_tests rather than blockchain_tests? The Bitcoin Core policy for naming unit test files is to match the the file under test ("blockchain" becomes "blockchain_tests"). While this commit complies with that, blockchain.cpp is a massive file, such that having all of the unit tests in one file will tend towards disorder. Since there will be a lot more tests added to this file, the intention is to divide up different types of tests into different test fixtures within the same file.
3 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # Copyright (c) 2013-2016 The Bitcoin Core developers
  2. # Distributed under the MIT software license, see the accompanying
  3. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. TESTS += test/test_bitcoin
  5. bin_PROGRAMS += test/test_bitcoin
  6. noinst_PROGRAMS += test/test_bitcoin_fuzzy
  7. TEST_SRCDIR = test
  8. TEST_BINARY=test/test_bitcoin$(EXEEXT)
  9. JSON_TEST_FILES = \
  10. test/data/script_tests.json \
  11. test/data/base58_keys_valid.json \
  12. test/data/base58_encode_decode.json \
  13. test/data/base58_keys_invalid.json \
  14. test/data/tx_invalid.json \
  15. test/data/tx_valid.json \
  16. test/data/sighash.json
  17. RAW_TEST_FILES =
  18. GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
  19. # test_bitcoin binary #
  20. BITCOIN_TESTS =\
  21. test/arith_uint256_tests.cpp \
  22. test/scriptnum10.h \
  23. test/addrman_tests.cpp \
  24. test/amount_tests.cpp \
  25. test/allocator_tests.cpp \
  26. test/base32_tests.cpp \
  27. test/base58_tests.cpp \
  28. test/base64_tests.cpp \
  29. test/bech32_tests.cpp \
  30. test/bip32_tests.cpp \
  31. test/blockchain_tests.cpp \
  32. test/blockencodings_tests.cpp \
  33. test/bloom_tests.cpp \
  34. test/bswap_tests.cpp \
  35. test/checkqueue_tests.cpp \
  36. test/coins_tests.cpp \
  37. test/compress_tests.cpp \
  38. test/crypto_tests.cpp \
  39. test/cuckoocache_tests.cpp \
  40. test/DoS_tests.cpp \
  41. test/getarg_tests.cpp \
  42. test/hash_tests.cpp \
  43. test/key_tests.cpp \
  44. test/limitedmap_tests.cpp \
  45. test/dbwrapper_tests.cpp \
  46. test/main_tests.cpp \
  47. test/mempool_tests.cpp \
  48. test/merkle_tests.cpp \
  49. test/merkleblock_tests.cpp \
  50. test/miner_tests.cpp \
  51. test/multisig_tests.cpp \
  52. test/net_tests.cpp \
  53. test/netbase_tests.cpp \
  54. test/pmt_tests.cpp \
  55. test/policyestimator_tests.cpp \
  56. test/pow_tests.cpp \
  57. test/prevector_tests.cpp \
  58. test/raii_event_tests.cpp \
  59. test/random_tests.cpp \
  60. test/reverselock_tests.cpp \
  61. test/rpc_tests.cpp \
  62. test/sanity_tests.cpp \
  63. test/scheduler_tests.cpp \
  64. test/script_P2SH_tests.cpp \
  65. test/script_tests.cpp \
  66. test/script_standard_tests.cpp \
  67. test/scriptnum_tests.cpp \
  68. test/serialize_tests.cpp \
  69. test/sighash_tests.cpp \
  70. test/sigopcount_tests.cpp \
  71. test/skiplist_tests.cpp \
  72. test/streams_tests.cpp \
  73. test/test_bitcoin.cpp \
  74. test/test_bitcoin.h \
  75. test/test_bitcoin_main.cpp \
  76. test/timedata_tests.cpp \
  77. test/torcontrol_tests.cpp \
  78. test/transaction_tests.cpp \
  79. test/txvalidation_tests.cpp \
  80. test/txvalidationcache_tests.cpp \
  81. test/uint256_tests.cpp \
  82. test/util_tests.cpp \
  83. test/validation_block_tests.cpp \
  84. test/versionbits_tests.cpp
  85. if ENABLE_WALLET
  86. BITCOIN_TESTS += \
  87. wallet/test/wallet_test_fixture.cpp \
  88. wallet/test/wallet_test_fixture.h \
  89. wallet/test/accounting_tests.cpp \
  90. wallet/test/wallet_tests.cpp \
  91. wallet/test/crypto_tests.cpp
  92. endif
  93. test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
  94. test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS)
  95. test_test_bitcoin_LDADD =
  96. if ENABLE_WALLET
  97. test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
  98. endif
  99. test_test_bitcoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \
  100. $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
  101. test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
  102. test_test_bitcoin_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS)
  103. test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
  104. if ENABLE_ZMQ
  105. test_test_bitcoin_LDADD += $(ZMQ_LIBS)
  106. endif
  107. #
  108. # test_bitcoin_fuzzy binary #
  109. test_test_bitcoin_fuzzy_SOURCES = test/test_bitcoin_fuzzy.cpp
  110. test_test_bitcoin_fuzzy_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
  111. test_test_bitcoin_fuzzy_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
  112. test_test_bitcoin_fuzzy_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
  113. test_test_bitcoin_fuzzy_LDADD = \
  114. $(LIBUNIVALUE) \
  115. $(LIBBITCOIN_SERVER) \
  116. $(LIBBITCOIN_COMMON) \
  117. $(LIBBITCOIN_UTIL) \
  118. $(LIBBITCOIN_CONSENSUS) \
  119. $(LIBBITCOIN_CRYPTO) \
  120. $(LIBSECP256K1)
  121. test_test_bitcoin_fuzzy_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
  122. #
  123. nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
  124. $(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
  125. CLEAN_BITCOIN_TEST = test/*.gcda test/*.gcno $(GENERATED_TEST_FILES)
  126. CLEANFILES += $(CLEAN_BITCOIN_TEST)
  127. bitcoin_test: $(TEST_BINARY)
  128. bitcoin_test_check: $(TEST_BINARY) FORCE
  129. $(MAKE) check-TESTS TESTS=$^
  130. bitcoin_test_clean : FORCE
  131. rm -f $(CLEAN_BITCOIN_TEST) $(test_test_bitcoin_OBJECTS) $(TEST_BINARY)
  132. check-local:
  133. @echo "Running test/util/bitcoin-util-test.py..."
  134. $(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py
  135. $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
  136. if EMBEDDED_UNIVALUE
  137. $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check
  138. endif
  139. %.json.h: %.json
  140. @$(MKDIR_P) $(@D)
  141. @{ \
  142. echo "namespace json_tests{" && \
  143. echo "static unsigned const char $(*F)[] = {" && \
  144. $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \
  145. echo "};};"; \
  146. } > "$@.new" && mv -f "$@.new" "$@"
  147. @echo "Generated $@"