diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 9f1d9ea52..45b483b66 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,173 +1,185 @@ # Copyright (c) 2018 The Bitcoin developers project(bitcoin-test) +option(TEST_WITH_UPGRADE_ACTIVATED "Run unit tests with the next upgrade activated in addition to regular tests" OFF) + # Process json files. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data") function(gen_json_header NAME) set(HEADERS "") foreach(f ${ARGN}) set(h "${CMAKE_CURRENT_BINARY_DIR}/${f}.h") # Get the proper name for the test variable. get_filename_component(TEST_NAME ${f} NAME_WE) add_custom_command(OUTPUT ${h} COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/data/generate_header.py" "${TEST_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/${f}" > ${h} MAIN_DEPENDENCY ${f} DEPENDS "data/generate_header.py" VERBATIM ) list(APPEND HEADERS ${h}) endforeach(f) set(${NAME} "${HEADERS}" PARENT_SCOPE) endfunction() gen_json_header(JSON_HEADERS data/base58_encode_decode.json data/blockfilters.json data/key_io_valid.json data/key_io_invalid.json data/script_tests.json data/sighash.json data/tx_invalid.json data/tx_valid.json ) include(TestSuite) create_test_suite(bitcoin) add_dependencies(check check-bitcoin) add_boost_unit_tests_to_suite(bitcoin test_bitcoin activation_tests.cpp addrman_tests.cpp allocator_tests.cpp amount_tests.cpp arith_uint256_tests.cpp avalanche_tests.cpp base32_tests.cpp base58_tests.cpp base64_tests.cpp bip32_tests.cpp bitmanip_tests.cpp blockchain_tests.cpp blockcheck_tests.cpp blockencodings_tests.cpp blockfilter_tests.cpp blockindex_tests.cpp blockstatus_tests.cpp bloom_tests.cpp bswap_tests.cpp cashaddr_tests.cpp cashaddrenc_tests.cpp checkdatasig_tests.cpp checkpoints_tests.cpp checkqueue_tests.cpp coins_tests.cpp compress_tests.cpp config_tests.cpp core_io_tests.cpp crypto_tests.cpp cuckoocache_tests.cpp dbwrapper_tests.cpp denialofservice_tests.cpp descriptor_tests.cpp dstencode_tests.cpp excessiveblock_tests.cpp feerate_tests.cpp finalization_tests.cpp flatfile_tests.cpp getarg_tests.cpp hash_tests.cpp inv_tests.cpp jsonutil.cpp key_io_tests.cpp key_tests.cpp lcg_tests.cpp limitedmap_tests.cpp main_tests.cpp mempool_tests.cpp merkle_tests.cpp miner_tests.cpp monolith_opcodes_tests.cpp multisig_tests.cpp net_tests.cpp netbase_tests.cpp pmt_tests.cpp policyestimator_tests.cpp pow_tests.cpp prevector_tests.cpp radix_tests.cpp raii_event_tests.cpp random_tests.cpp rcu_tests.cpp reverselock_tests.cpp rpc_tests.cpp rpc_server_tests.cpp rwcollection_tests.cpp sanity_tests.cpp scheduler_tests.cpp schnorr_tests.cpp script_bitfield_tests.cpp script_commitment_tests.cpp script_p2sh_tests.cpp script_standard_tests.cpp script_tests.cpp scriptflags.cpp scriptnum_tests.cpp serialize_tests.cpp sigcache_tests.cpp sigencoding_tests.cpp sighash_tests.cpp sighashtype_tests.cpp sigopcount_tests.cpp sigutil.cpp skiplist_tests.cpp streams_tests.cpp sync_tests.cpp test_bitcoin.cpp test_bitcoin_main.cpp timedata_tests.cpp torcontrol_tests.cpp transaction_tests.cpp txindex_tests.cpp txvalidation_tests.cpp txvalidationcache_tests.cpp uint256_tests.cpp undo_tests.cpp util_tests.cpp validation_block_tests.cpp validation_tests.cpp work_comparator_tests.cpp # RPC Tests ../rpc/test/server_tests.cpp # Tests generated from JSON ${JSON_HEADERS} ) +if (TEST_WITH_UPGRADE_ACTIVATED) + add_test( + NAME + "bitcoin-upgrade-activated" + COMMAND + "test_bitcoin" + "-gravitonactivationtime=1573819200" + ) +endif() + target_link_libraries(test_bitcoin rpcclient server) if(TARGET bitcoinconsensus-shared) target_link_libraries(test_bitcoin bitcoinconsensus-shared) else() target_link_libraries(test_bitcoin bitcoinconsensus) endif() if(BUILD_BITCOIN_WALLET) target_sources(test_bitcoin PRIVATE ../wallet/test/accounting_tests.cpp ../wallet/test/coinselector_tests.cpp ../wallet/test/psbt_wallet_tests.cpp ../wallet/test/wallet_test_fixture.cpp ../wallet/test/wallet_tests.cpp ../wallet/test/walletdb_tests.cpp ../wallet/test/wallet_crypto_tests.cpp ) endif() diff --git a/src/test/activation_tests.cpp b/src/test/activation_tests.cpp index d5e91d77f..18565dc02 100644 --- a/src/test/activation_tests.cpp +++ b/src/test/activation_tests.cpp @@ -1,48 +1,50 @@ // Copyright (c) 2019 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include +#include #include #include BOOST_FIXTURE_TEST_SUITE(activation_tests, BasicTestingSetup) static void SetMTP(std::array &blocks, int64_t mtp) { size_t len = blocks.size(); for (size_t i = 0; i < len; ++i) { blocks[i].nTime = mtp + (i - (len / 2)); } assert(blocks.back().GetMedianTimePast() == mtp); } BOOST_AUTO_TEST_CASE(isgravitonenabled) { CBlockIndex prev; const Consensus::Params ¶ms = Params().GetConsensus(); - const auto activation = params.gravitonActivationTime; - - BOOST_CHECK(!IsGravitonEnabled(params, nullptr)); + const auto activation = + gArgs.GetArg("-gravitonactivationtime", params.gravitonActivationTime); + SetMockTime(activation - 1000000); std::array blocks; for (size_t i = 1; i < blocks.size(); ++i) { blocks[i].pprev = &blocks[i - 1]; } + BOOST_CHECK(!IsGravitonEnabled(params, &blocks.back())); SetMTP(blocks, activation - 1); BOOST_CHECK(!IsGravitonEnabled(params, &blocks.back())); SetMTP(blocks, activation); BOOST_CHECK(IsGravitonEnabled(params, &blocks.back())); SetMTP(blocks, activation + 1); BOOST_CHECK(IsGravitonEnabled(params, &blocks.back())); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/test_bitcoin_main.cpp b/src/test/test_bitcoin_main.cpp index ff6ece017..67fbc85b0 100644 --- a/src/test/test_bitcoin_main.cpp +++ b/src/test/test_bitcoin_main.cpp @@ -1,25 +1,45 @@ // Copyright (c) 2011-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #define BOOST_TEST_MODULE Bitcoin Test Suite +#define BOOST_TEST_NO_MAIN #include #include +#include #include std::unique_ptr g_connman; std::unique_ptr g_banman; [[noreturn]] void Shutdown(void *parg) { std::exit(EXIT_SUCCESS); } [[noreturn]] void StartShutdown() { std::exit(EXIT_SUCCESS); } bool ShutdownRequested() { return false; } + +std::set testArgs = {"-gravitonactivationtime"}; + +int main(int argc, char *argv[]) { + // Additional CLI params supported by test_bitcoin: + // Note: gArgs.ParseParameters() cannot be called here or it will fail to + // parse BOOST runtime params. + for (int i = 1; i < argc; i++) { + std::string key(argv[i]); + std::string value; + if (ParseKeyValue(key, value)) { + if (testArgs.count(key) > 0) { + gArgs.ForceSetArg(key, value); + } + } + } + return boost::unit_test::unit_test_main(&init_unit_test, argc, argv); +}