diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e929b3a1..14f1a3fa01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,6 @@ set(FIRO_DAEMON_NAME firod) set(FIRO_GUI_NAME firo-qt) set(FIRO_CLI_NAME firo-cli) set(FIRO_TX_NAME firo-tx) -set(FIRO_UTIL_NAME firo-util) set(CLIENT_VERSION_STRING ${PROJECT_VERSION}) if(CLIENT_VERSION_RC GREATER 0) @@ -105,14 +104,13 @@ option(BUILD_DAEMON "Build ${FIRO_DAEMON_NAME} executable." ON) option(BUILD_GUI "Build ${FIRO_GUI_NAME} executable." OFF) option(BUILD_CLI "Build ${FIRO_CLI_NAME} executable." ON) -option(BUILD_TESTS "Build test_firo executable." ON) -option(BUILD_TX "Build ${FIRO_TX_NAME} executable." ${BUILD_TESTS}) -option(BUILD_UTIL "Build ${FIRO_UTIL_NAME} executable and library." ${BUILD_TESTS}) option(BUILD_UTIL_CHAINSTATE "Build experimental firo-chainstate executable." OFF) option(BUILD_KERNEL_LIB "Build experimental firokernel library." ${BUILD_UTIL_CHAINSTATE}) option(ENABLE_WALLET "Enable wallet." OFF) +cmake_dependent_option(BUILD_TESTS "Build tests." OFF "ENABLE_WALLET" OFF) +option(BUILD_TX "Build ${FIRO_TX_NAME} executable." ${BUILD_TESTS}) option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF) cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF) if(WITH_BDB) @@ -129,7 +127,6 @@ if(WITH_BDB) endif() endif() endif() -cmake_dependent_option(BUILD_WALLET_TOOL "Build firo-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF) option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON) option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF) @@ -162,7 +159,7 @@ endif() cmake_dependent_option(WITH_DBUS "Enable DBus support." ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\" AND BUILD_GUI" OFF) -cmake_dependent_option(BUILD_GUI_TESTS "Build test_firo-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF) +cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF) if(BUILD_GUI) set(qt_components Core Gui Widgets LinguistTools) if(ENABLE_WALLET) @@ -232,7 +229,6 @@ if(BUILD_FOR_FUZZING) set(BUILD_UTIL OFF) set(BUILD_UTIL_CHAINSTATE OFF) set(BUILD_KERNEL_LIB OFF) - set(BUILD_WALLET_TOOL OFF) set(BUILD_GUI OFF) set(ENABLE_EXTERNAL_SIGNER OFF) set(WITH_ZMQ OFF) @@ -735,8 +731,6 @@ message(" firod ............................ ${BUILD_DAEMON}") message(" firo-qt (GUI) .................... ${BUILD_GUI}") message(" firo-cli ......................... ${BUILD_CLI}") message(" firo-tx .......................... ${BUILD_TX}") -message(" firo-util ........................ ${BUILD_UTIL}") -message(" firo-wallet ...................... ${BUILD_WALLET_TOOL}") message(" firo-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}") message(" libfirokernel (experimental) ..... ${BUILD_KERNEL_LIB}") message("Optional features:") @@ -750,8 +744,8 @@ message(" USDT tracing ........................ ${WITH_USDT}") message(" QR code (GUI) ....................... ${WITH_QRENCODE}") message(" DBus (GUI, Linux only) .............. ${WITH_DBUS}") message("Tests:") -message(" test_firo ........................ ${BUILD_TESTS}") -message(" test_firo-qt ..................... ${BUILD_GUI_TESTS}") +message(" test_bitcoin ........................ ${BUILD_TESTS}") +message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}") message(" bench_firo ....................... ${BUILD_BENCH}") message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}") message("") diff --git a/cmake/script/GenerateHeaderFromJson.cmake b/cmake/script/GenerateHeaderFromJson.cmake index 4a3bddb323..5d3482f5f1 100644 --- a/cmake/script/GenerateHeaderFromJson.cmake +++ b/cmake/script/GenerateHeaderFromJson.cmake @@ -2,21 +2,33 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://opensource.org/license/mit/. -cmake_path(GET JSON_SOURCE_PATH STEM json_source_basename) +message(STATUS "Generating header ${HEADER_PATH} from ${JSON_SOURCE_PATH}") -file(READ ${JSON_SOURCE_PATH} hex_content HEX) -string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}") -string(REGEX REPLACE "[^\n][^\n]" "0x\\0, " formatted_bytes "${formatted_bytes}") +# Generate a header file from a JSON file containing a hex dump +function(generate_json_header JSON_SOURCE_PATH HEADER_PATH) + # Use get_filename_component instead of cmake_path + get_filename_component(json_source_basename "${JSON_SOURCE_PATH}" NAME_WE) -set(header_content -"#include + # Create directory + get_filename_component(header_dir "${HEADER_PATH}" DIRECTORY) + file(MAKE_DIRECTORY "${header_dir}") + + # Read and convert to hex + file(READ ${JSON_SOURCE_PATH} hex_content HEX) + string(REGEX REPLACE ".." "0x\\0, " formatted_bytes "${hex_content}") -namespace json_tests { -inline constexpr char detail_${json_source_basename}_bytes[] { -${formatted_bytes} -}; + # Generate content + set(header_content + "namespace json_tests{ + static unsigned const char ${json_source_basename}[] = { + ${formatted_bytes} + }; + };" + ) + + # Atomic write using temporary file + file(WRITE "${HEADER_PATH}.new" "${header_content}") + file(RENAME "${HEADER_PATH}.new" "${HEADER_PATH}") +endfunction() -inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)}; -} -") -file(WRITE ${HEADER_PATH} "${header_content}") +generate_json_header(${JSON_SOURCE_PATH} ${HEADER_PATH}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 624c2bba1b..68c640f7d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -249,70 +249,9 @@ target_link_libraries(bitcoin_common $<$:ws2_32> ) -add_library(bitcoin_wallet STATIC EXCLUDE_FROM_ALL - activemasternode.cpp - hdmint/hdmint.cpp - masternode-sync.cpp - hdmint/mintpool.cpp - hdmint/wallet.cpp - sigma.cpp - lelantus.cpp - spark/state.cpp - wallet/crypter.cpp - wallet/bip39.cpp - wallet/mnemoniccontainer.cpp - wallet/db.cpp - wallet/rpcdump.cpp - wallet/rpcwallet.cpp - wallet/sigmaspendbuilder.cpp - wallet/txbuilder.cpp - wallet/lelantusjoinsplitbuilder.cpp - wallet/walletexcept.cpp - wallet/wallet.cpp - spark/sparkwallet.cpp - spark/primitives.cpp - wallet/walletdb.cpp - wallet/authhelper.cpp - hdmint/tracker.cpp - policy/rbf.cpp - bip47/account.cpp - bip47/paymentchannel.cpp - bip47/bip47utils.cpp - bip47/paymentcode.cpp - bip47/secretpoint.cpp - primitives/mint_spend.cpp -) -target_link_libraries(bitcoin_wallet - PUBLIC - core_interface - bitcoin_util - univalue - secp256k1 - Boost::headers - leveldb -) - set(installable_targets) if(ENABLE_WALLET) add_subdirectory(wallet) - - if(BUILD_WALLET_TOOL) - add_executable(firo-wallet - bitcoin-wallet.cpp - init/bitcoin-wallet.cpp - wallet/wallettool.cpp - ) - add_windows_resources(firo-wallet bitcoin-wallet-res.rc) - target_link_libraries(firo-wallet - core_interface - firo_wallet - bitcoin_common - bitcoin_util - bitcoin_wallet - Boost::headers - ) - list(APPEND installable_targets firo-wallet) - endif() endif() @@ -322,7 +261,6 @@ add_library(firo_node STATIC EXCLUDE_FROM_ALL addrman.cpp blockencodings.cpp chain.cpp - consensus/tx_verify.cpp dbwrapper.cpp httprpc.cpp httpserver.cpp @@ -502,7 +440,6 @@ if(BUILD_DAEMON) firo_cli secp256k1 secp256k1pp - bitcoin_wallet $ ) list(APPEND installable_targets firod) @@ -592,17 +529,6 @@ if(BUILD_TX) endif() -if(BUILD_UTIL) - add_executable(bitcoin-util bitcoin-util.cpp) - add_windows_resources(bitcoin-util bitcoin-util-res.rc) - target_link_libraries(bitcoin-util - core_interface - bitcoin_common - bitcoin_util - ) - list(APPEND installable_targets bitcoin-util) -endif() - if(BUILD_GUI) add_subdirectory(qt) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 16819e88d3..99669b8f1c 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -205,7 +205,7 @@ BITCOIN_TESTS += \ wallet/test/wallet_tests.cpp \ wallet/test/crypto_tests.cpp \ wallet/test/lelantus_tests.cpp \ - wallet/test/spark_tests.cpp \ + wallet/test/spark_wallet_tests.cpp \ wallet/test/sigma_tests.cpp \ wallet/test/mnemonic_tests.cpp \ wallet/test/txbuilder_tests.cpp diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 0000000000..79574a5530 --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,187 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +include(GenerateHeaders) +generate_header_from_json(data/base58_encode_decode.json) +generate_header_from_json(data/base58_keys_invalid.json) +generate_header_from_json(data/base58_keys_valid.json) +generate_header_from_json(data/script_tests.json) +generate_header_from_json(data/sighash.json) +generate_header_from_json(data/tx_invalid.json) +generate_header_from_json(data/tx_valid.json) + +# Do not use generator expressions in test sources because the +# SOURCES property is processed to gather test suite macros. +add_executable(test_bitcoin + ${CMAKE_CURRENT_BINARY_DIR}/data/base58_encode_decode.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/base58_keys_invalid.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/base58_keys_valid.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/script_tests.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/sighash.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/tx_invalid.json.h + ${CMAKE_CURRENT_BINARY_DIR}/data/tx_valid.json.h + addrman_tests.cpp + allocator_tests.cpp + amount_tests.cpp + arith_uint256_tests.cpp + base32_tests.cpp + base58_tests.cpp + base64_tests.cpp + bip32_tests.cpp + bip47_test_data.h + bip47_tests.cpp + bip47_serialization_tests.cpp + blockencodings_tests.cpp + bloom_tests.cpp + bswap_tests.cpp + checkqueue_tests.cpp + coins_tests.cpp + compress_tests.cpp + crypto_tests.cpp + cuckoocache_tests.cpp + DoS_tests.cpp + fixtures.cpp + fixtures.h + getarg_tests.cpp + hash_tests.cpp + key_tests.cpp + dbwrapper_tests.cpp + lelantus_tests.cpp + lelantus_mintspend_test.cpp + lelantus_state_tests.cpp + sigma_lelantus_transition.cpp + limitedmap_tests.cpp + main_tests.cpp + mbstring_tests.cpp + mempool_tests.cpp + merkle_tests.cpp + miner_tests.cpp + mtp_halving_tests.cpp + mtp_tests.cpp + mtp_trans_tests.cpp + firopow_tests.cpp + multisig_tests.cpp + netbase_tests.cpp + net_tests.cpp + pmt_tests.cpp + prevector_tests.cpp + raii_event_tests.cpp + random_tests.cpp + reverselock_tests.cpp + rpc_tests.cpp + sanity_tests.cpp + scheduler_tests.cpp + scriptnum10.h + scriptnum_tests.cpp + script_P2SH_tests.cpp + script_tests.cpp + serialize_tests.cpp + sighash_tests.cpp + sigma_manymintspend_test.cpp + sigma_mintspend_numinputs.cpp + sigma_mintspend_test.cpp + sigma_partialspend_mempool_tests.cpp + sigma_state_tests.cpp + sigopcount_tests.cpp + skiplist_tests.cpp + streams_tests.cpp + test_bitcoin.cpp + test_bitcoin.h + test_random.h + testutil.cpp + testutil.h + timedata_tests.cpp + transaction_tests.cpp + txdb_tests.cpp + txvalidationcache_tests.cpp + uint256_tests.cpp + univalue_tests.cpp + util_tests.cpp + multiexponentation_test.cpp + firsthalving_tests.cpp + evospork_tests.cpp + evo_deterministicmns_tests.cpp + evo_simplifiedmns_tests.cpp + progpow_tests.cpp + bls_tests.cpp +) + +target_link_libraries(test_bitcoin + core_interface + firo_cli + firo_node + bitcoin_consensus + secp256k1 + Boost::headers + libevent::extra + secp256k1pp + univalue + leveldb + firo_wallet +) + +target_include_directories(test_bitcoin + PUBLIC + ${CMAKE_CURRENT_BINARY_DIR} +) + +if(ENABLE_WALLET) + add_subdirectory(${PROJECT_SOURCE_DIR}/src/wallet/test wallet) +endif() + +if(WITH_MULTIPROCESS) + target_link_libraries(bitcoin_ipc_test + PRIVATE + core_interface + univalue + ) + + target_sources(test_bitcoin + PRIVATE + ipc_tests.cpp + ) + target_link_libraries(test_bitcoin bitcoin_ipc_test bitcoin_ipc) +endif() + +function(add_boost_test source_file) + if(NOT EXISTS ${source_file}) + return() + endif() + + file(READ "${source_file}" source_file_content) + string(REGEX + MATCH "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)" + test_suite_macro "${source_file_content}" + ) + string(REGEX + REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" "" + test_suite_name "${test_suite_macro}" + ) + if(test_suite_name) + add_test(NAME ${test_suite_name} + COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT + ) + set_property(TEST ${test_suite_name} PROPERTY + SKIP_REGULAR_EXPRESSION "no test cases matching filter" + ) + endif() +endfunction() + +function(add_all_test_targets) + get_target_property(test_source_dir test_bitcoin SOURCE_DIR) + get_target_property(test_sources test_bitcoin SOURCES) + foreach(test_source ${test_sources}) + cmake_path(IS_RELATIVE test_source result) + if(result) + cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source) + endif() + add_boost_test(${test_source}) + endforeach() +endfunction() + +add_all_test_targets() + +install(TARGETS test_bitcoin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 5d9ddbf81a..1db4a0f925 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -4,9 +4,9 @@ #include "base58.h" -#include "data/base58_encode_decode.json.h" -#include "data/base58_keys_invalid.json.h" -#include "data/base58_keys_valid.json.h" +#include +#include +#include #include "key.h" #include "script/script.h" diff --git a/src/univalue/CMakeLists.txt b/src/univalue/CMakeLists.txt index ab460286f5..02e1a38958 100644 --- a/src/univalue/CMakeLists.txt +++ b/src/univalue/CMakeLists.txt @@ -28,13 +28,4 @@ if(BUILD_TESTS) COMMAND unitester ) - add_executable(object test/object.cpp) - target_link_libraries(object - PRIVATE - core_interface - univalue - ) - add_test(NAME univalue_object_test - COMMAND object - ) endif() diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 9bd1706207..c69e7ed2bf 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -3,31 +3,48 @@ # file COPYING or https://opensource.org/license/mit/. # Wallet functionality used by bitcoind and bitcoin-wallet executables. + add_library(firo_wallet STATIC EXCLUDE_FROM_ALL - authhelper.cpp - bip39.cpp - crypter.cpp - db.cpp - lelantusjoinsplitbuilder.cpp - mnemoniccontainer.cpp - rpcdump.cpp - rpcwallet.cpp - sigmaspendbuilder.cpp - txbuilder.cpp - wallet.cpp - walletdb.cpp - walletexcept.cpp + ../activemasternode.cpp + ../masternode-sync.cpp + ../sigma.cpp + ../lelantus.cpp + ../hdmint/hdmint.cpp + ../hdmint/mintpool.cpp + ../hdmint/wallet.cpp + ../hdmint/tracker.cpp + ../spark/state.cpp + ../spark/sparkwallet.cpp + ../spark/primitives.cpp + ../policy/rbf.cpp + ../bip47/account.cpp + ../bip47/paymentchannel.cpp + ../bip47/bip47utils.cpp + ../bip47/paymentcode.cpp + ../bip47/secretpoint.cpp + ../primitives/mint_spend.cpp + crypter.cpp + bip39.cpp + mnemoniccontainer.cpp + db.cpp + rpcdump.cpp + rpcwallet.cpp + sigmaspendbuilder.cpp + txbuilder.cpp + lelantusjoinsplitbuilder.cpp + walletexcept.cpp + wallet.cpp + walletdb.cpp + authhelper.cpp ) - target_link_libraries(firo_wallet - PRIVATE + PUBLIC core_interface - bitcoin_common + bitcoin_util univalue - Boost::headers secp256k1 + Boost::headers leveldb - $ ) # Firo only supports BDB for wallet storage. diff --git a/src/wallet/test/CMakeLists.txt b/src/wallet/test/CMakeLists.txt new file mode 100644 index 0000000000..32c0ba9226 --- /dev/null +++ b/src/wallet/test/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +# Do not use generator expressions in test sources because the +# SOURCES property is processed to gather test suite macros. + +target_sources(test_bitcoin + PRIVATE + accounting_tests.cpp + crypto_tests.cpp + lelantus_tests.cpp + mnemonic_tests.cpp + sigma_tests.cpp + spark_wallet_tests.cpp + txbuilder_tests.cpp + wallet_test_fixture.cpp + wallet_tests.cpp +) +target_link_libraries(test_bitcoin firo_wallet) diff --git a/src/wallet/test/spark_tests.cpp b/src/wallet/test/spark_wallet_tests.cpp similarity index 99% rename from src/wallet/test/spark_tests.cpp rename to src/wallet/test/spark_wallet_tests.cpp index 7ed925fb2d..bd9bd8c297 100644 --- a/src/wallet/test/spark_tests.cpp +++ b/src/wallet/test/spark_wallet_tests.cpp @@ -37,7 +37,7 @@ void ExtractSpend(CTransaction const &tx, } } -BOOST_FIXTURE_TEST_SUITE(spark_tests, SparkTestingSetup) +BOOST_FIXTURE_TEST_SUITE(spark_wallet_tests, SparkTestingSetup) BOOST_AUTO_TEST_CASE(create_mint_recipient) {