diff --git a/doc/release-notes.md b/doc/release-notes.md index 51175bab2..28db81479 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -1,10 +1,12 @@ # Bitcoin ABC 0.23.8 Release Notes Bitcoin ABC version 0.23.8 is now available from: This release includes the following features and fixes: - Add a new option `-networkactive` to enable all P2P network activity (default 1). To start a node offline, you can provide `-networkactive=0` or `-nonetworkactive`. + - The deprecated `setexcessiveblock` RPC has been removed and is no longer + available. The `-excessiveblocksize` option should be used instead. diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp index 0845d9038..d2b3a7d95 100644 --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -1,106 +1,45 @@ // Copyright (c) 2017-2020 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 #include #include #include static UniValue getexcessiveblock(const Config &config, const JSONRPCRequest &request) { RPCHelpMan{ "getexcessiveblock", "Return the excessive block size.", {}, RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"}, RPCExamples{HelpExampleCli("getexcessiveblock", "") + HelpExampleRpc("getexcessiveblock", "")}, } .Check(request); UniValue ret(UniValue::VOBJ); ret.pushKV("excessiveBlockSize", config.GetMaxBlockSize()); return ret; } -static UniValue setexcessiveblock(Config &config, - const JSONRPCRequest &request) { - RPCHelpMan{ - "setexcessiveblock", - "DEPRECATED. Set the excessive block size. Excessive blocks will not " - "be used in the active chain or relayed. This discourages the " - "propagation of blocks that you consider excessively large.", - { - {"blockSize", RPCArg::Type::NUM, RPCArg::Optional::NO, - "Excessive block size in bytes. Must be greater than " + - ToString(LEGACY_MAX_BLOCK_SIZE) + "."}, - }, - RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"}, - RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") + - HelpExampleRpc("setexcessiveblock", "25000000")}, - } - .Check(request); - - if (!IsDeprecatedRPCEnabled(gArgs, "setexcessiveblock")) { - // setexcessiveblock is deprecated in v0.22.12 for removal in v0.23 - throw JSONRPCError( - RPC_METHOD_DEPRECATED, - std::string( - "The setexcessiveblock RPC is deprecated and will be removed " - "in a future version. Use the -deprecatedrpc=setexcessiveblock " - "option to continue using it.")); - } - - if (!request.params[0].isNum()) { - throw JSONRPCError( - RPC_INVALID_PARAMETER, - std::string( - "Invalid parameter, excessiveblock must be an integer")); - } - - int64_t ebs = request.params[0].get_int64(); - - // Do not allow maxBlockSize to be set below historic 1MB limit - if (ebs <= int64_t(LEGACY_MAX_BLOCK_SIZE)) { - throw JSONRPCError( - RPC_INVALID_PARAMETER, - std::string( - "Invalid parameter, excessiveblock must be larger than ") + - ToString(LEGACY_MAX_BLOCK_SIZE)); - } - - // Set the new max block size. - { - LOCK(cs_main); - if (!config.SetMaxBlockSize(ebs)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected error"); - } - } - - // settingsToUserAgentString(); - std::ostringstream ret; - ret << "Excessive Block set to " << ebs << " bytes."; - return UniValue(ret.str()); -} - void RegisterABCRPCCommands(CRPCTable &t) { // clang-format off static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "network", "getexcessiveblock", getexcessiveblock, {}}, - { "network", "setexcessiveblock", setexcessiveblock, {"maxBlockSize"}}, }; // clang-format on for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); } } diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 82936384f..6b4f8d96f 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -1,258 +1,256 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-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. #include #include #include #include class CRPCConvertParam { public: std::string methodName; //!< method whose params want conversion int paramIdx; //!< 0-based idx of param to convert std::string paramName; //!< parameter name }; /** * Specify a (method, idx, name) here if the argument is a non-string RPC * argument and needs to be converted from JSON. * * @note Parameter indexes start from 0. */ static const CRPCConvertParam vRPCConvertParams[] = { {"setmocktime", 0, "timestamp"}, {"mockscheduler", 0, "delta_time"}, {"utxoupdatepsbt", 1, "descriptors"}, {"generatetoaddress", 0, "nblocks"}, {"generatetoaddress", 2, "maxtries"}, {"generatetodescriptor", 0, "num_blocks"}, {"generatetodescriptor", 2, "maxtries"}, {"generateblock", 1, "transactions"}, {"getnetworkhashps", 0, "nblocks"}, {"getnetworkhashps", 1, "height"}, {"sendtoaddress", 1, "amount"}, {"sendtoaddress", 4, "subtractfeefromamount"}, {"sendtoaddress", 5, "avoid_reuse"}, {"settxfee", 0, "amount"}, {"sethdseed", 0, "newkeypool"}, {"getreceivedbyaddress", 1, "minconf"}, {"getreceivedbylabel", 1, "minconf"}, {"listreceivedbyaddress", 0, "minconf"}, {"listreceivedbyaddress", 1, "include_empty"}, {"listreceivedbyaddress", 2, "include_watchonly"}, {"listreceivedbylabel", 0, "minconf"}, {"listreceivedbylabel", 1, "include_empty"}, {"listreceivedbylabel", 2, "include_watchonly"}, {"getbalance", 1, "minconf"}, {"getbalance", 2, "include_watchonly"}, {"getbalance", 3, "avoid_reuse"}, {"getblockhash", 0, "height"}, {"waitforblockheight", 0, "height"}, {"waitforblockheight", 1, "timeout"}, {"waitforblock", 1, "timeout"}, {"waitfornewblock", 0, "timeout"}, {"listtransactions", 1, "count"}, {"listtransactions", 2, "skip"}, {"listtransactions", 3, "include_watchonly"}, {"walletpassphrase", 1, "timeout"}, {"getblocktemplate", 0, "template_request"}, {"listsinceblock", 1, "target_confirmations"}, {"listsinceblock", 2, "include_watchonly"}, {"listsinceblock", 3, "include_removed"}, {"sendmany", 1, "amounts"}, {"sendmany", 2, "minconf"}, {"sendmany", 4, "subtractfeefrom"}, {"deriveaddresses", 1, "range"}, {"scantxoutset", 1, "scanobjects"}, {"addmultisigaddress", 0, "nrequired"}, {"addmultisigaddress", 1, "keys"}, {"createmultisig", 0, "nrequired"}, {"createmultisig", 1, "keys"}, {"listunspent", 0, "minconf"}, {"listunspent", 1, "maxconf"}, {"listunspent", 2, "addresses"}, {"listunspent", 3, "include_unsafe"}, {"listunspent", 4, "query_options"}, {"getblock", 1, "verbosity"}, {"getblock", 1, "verbose"}, {"getblockheader", 1, "verbose"}, {"getchaintxstats", 0, "nblocks"}, {"gettransaction", 1, "include_watchonly"}, {"gettransaction", 2, "verbose"}, {"getrawtransaction", 1, "verbose"}, {"createrawtransaction", 0, "inputs"}, {"createrawtransaction", 1, "outputs"}, {"createrawtransaction", 2, "locktime"}, {"signrawtransactionwithkey", 1, "privkeys"}, {"signrawtransactionwithkey", 2, "prevtxs"}, {"signrawtransactionwithwallet", 1, "prevtxs"}, {"sendrawtransaction", 1, "maxfeerate"}, {"testmempoolaccept", 0, "rawtxs"}, {"testmempoolaccept", 1, "maxfeerate"}, {"combinerawtransaction", 0, "txs"}, {"fundrawtransaction", 1, "options"}, {"walletcreatefundedpsbt", 0, "inputs"}, {"walletcreatefundedpsbt", 1, "outputs"}, {"walletcreatefundedpsbt", 2, "locktime"}, {"walletcreatefundedpsbt", 3, "options"}, {"walletcreatefundedpsbt", 4, "bip32derivs"}, {"walletprocesspsbt", 1, "sign"}, {"walletprocesspsbt", 3, "bip32derivs"}, {"createpsbt", 0, "inputs"}, {"createpsbt", 1, "outputs"}, {"createpsbt", 2, "locktime"}, {"combinepsbt", 0, "txs"}, {"joinpsbts", 0, "txs"}, {"finalizepsbt", 1, "extract"}, {"converttopsbt", 1, "permitsigdata"}, {"gettxout", 1, "n"}, {"gettxout", 2, "include_mempool"}, {"gettxoutproof", 0, "txids"}, {"lockunspent", 0, "unlock"}, {"lockunspent", 1, "transactions"}, {"importprivkey", 2, "rescan"}, {"importaddress", 2, "rescan"}, {"importaddress", 3, "p2sh"}, {"importpubkey", 2, "rescan"}, {"importmulti", 0, "requests"}, {"importmulti", 1, "options"}, {"importdescriptors", 0, "requests"}, {"verifychain", 0, "checklevel"}, {"verifychain", 1, "nblocks"}, {"getblockstats", 0, "hash_or_height"}, {"getblockstats", 1, "stats"}, {"pruneblockchain", 0, "height"}, {"keypoolrefill", 0, "newsize"}, {"getrawmempool", 0, "verbose"}, {"estimatefee", 0, "nblocks"}, {"prioritisetransaction", 1, "dummy"}, {"prioritisetransaction", 2, "fee_delta"}, {"setban", 2, "bantime"}, {"setban", 3, "absolute"}, {"setnetworkactive", 0, "state"}, {"setwalletflag", 1, "value"}, {"getmempoolancestors", 1, "verbose"}, {"getmempooldescendants", 1, "verbose"}, {"disconnectnode", 1, "nodeid"}, {"logging", 0, "include"}, {"logging", 1, "exclude"}, {"upgradewallet", 0, "version"}, // Echo with conversion (For testing only) {"echojson", 0, "arg0"}, {"echojson", 1, "arg1"}, {"echojson", 2, "arg2"}, {"echojson", 3, "arg3"}, {"echojson", 4, "arg4"}, {"echojson", 5, "arg5"}, {"echojson", 6, "arg6"}, {"echojson", 7, "arg7"}, {"echojson", 8, "arg8"}, {"echojson", 9, "arg9"}, {"rescanblockchain", 0, "start_height"}, {"rescanblockchain", 1, "stop_height"}, {"createwallet", 1, "disable_private_keys"}, {"createwallet", 2, "blank"}, {"createwallet", 4, "avoid_reuse"}, {"createwallet", 5, "descriptors"}, {"getnodeaddresses", 0, "count"}, {"stop", 0, "wait"}, // Avalanche {"addavalanchenode", 0, "nodeid"}, {"buildavalancheproof", 0, "sequence"}, {"buildavalancheproof", 1, "expiration"}, {"buildavalancheproof", 3, "stakes"}, - // ABC specific RPC - {"setexcessiveblock", 0, "blockSize"}, }; class CRPCConvertTable { private: std::set> members; std::set> membersByName; public: CRPCConvertTable(); bool convert(const std::string &method, int idx) { return (members.count(std::make_pair(method, idx)) > 0); } bool convert(const std::string &method, const std::string &name) { return (membersByName.count(std::make_pair(method, name)) > 0); } }; CRPCConvertTable::CRPCConvertTable() { const unsigned int n_elem = (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0])); for (unsigned int i = 0; i < n_elem; i++) { members.insert(std::make_pair(vRPCConvertParams[i].methodName, vRPCConvertParams[i].paramIdx)); membersByName.insert(std::make_pair(vRPCConvertParams[i].methodName, vRPCConvertParams[i].paramName)); } } static CRPCConvertTable rpcCvtTable; /** * Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, * false, null) as well as objects and arrays. */ UniValue ParseNonRFCJSONValue(const std::string &strVal) { UniValue jVal; if (!jVal.read(std::string("[") + strVal + std::string("]")) || !jVal.isArray() || jVal.size() != 1) { throw std::runtime_error(std::string("Error parsing JSON:") + strVal); } return jVal[0]; } UniValue RPCConvertValues(const std::string &strMethod, const std::vector &strParams) { UniValue params(UniValue::VARR); for (unsigned int idx = 0; idx < strParams.size(); idx++) { const std::string &strVal = strParams[idx]; if (!rpcCvtTable.convert(strMethod, idx)) { // insert string value directly params.push_back(strVal); } else { // parse string as JSON, insert bool/number/object/etc. value params.push_back(ParseNonRFCJSONValue(strVal)); } } return params; } UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector &strParams) { UniValue params(UniValue::VOBJ); for (const std::string &s : strParams) { size_t pos = s.find('='); if (pos == std::string::npos) { throw(std::runtime_error("No '=' in named argument '" + s + "', this needs to be present for every " "argument (even if it is empty)")); } std::string name = s.substr(0, pos); std::string value = s.substr(pos + 1); if (!rpcCvtTable.convert(strMethod, name)) { // insert string value directly params.pushKV(name, value); } else { // parse string as JSON, insert bool/number/object/etc. value params.pushKV(name, ParseNonRFCJSONValue(value)); } } return params; } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index b4a72a68c..08aecb183 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,286 +1,285 @@ # Copyright (c) 2018 The Bitcoin developers project(bitcoin-test) # 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) # An utility library for bitcoin related test suites. add_library(testutil OBJECT util/blockfilter.cpp util/logging.cpp util/mining.cpp util/net.cpp util/setup_common.cpp util/str.cpp util/transaction_utils.cpp util/wallet.cpp ) target_link_libraries(testutil server) if(BUILD_BITCOIN_WALLET) set(BITCOIN_WALLET_TEST_FIXTURE ../wallet/test/init_test_fixture.cpp ../wallet/test/wallet_test_fixture.cpp ) set(BITCOIN_WALLET_TESTS ../wallet/test/db_tests.cpp ../wallet/test/coinselector_tests.cpp ../wallet/test/init_tests.cpp ../wallet/test/ismine_tests.cpp ../wallet/test/psbt_wallet_tests.cpp ../wallet/test/scriptpubkeyman_tests.cpp ../wallet/test/wallet_tests.cpp ../wallet/test/walletdb_tests.cpp ../wallet/test/wallet_crypto_tests.cpp ) endif() function(gen_asmap_headers HEADERS_VAR) foreach(INPUT_FILE ${ARGN}) set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${INPUT_FILE}.h") add_custom_command( OUTPUT "${OUTPUT_FILE}" COMMENT "Generate ASMAP header from ${INPUT_FILE}" COMMAND "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/data/generate_asmap.py" "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_FILE}" "${OUTPUT_FILE}" MAIN_DEPENDENCY "${INPUT_FILE}" DEPENDS "data/generate_header.py" VERBATIM ) list(APPEND ${HEADERS_VAR} "${OUTPUT_FILE}") endforeach() set(${HEADERS_VAR} ${${HEADERS_VAR}} PARENT_SCOPE) endfunction() gen_asmap_headers(ASMAP_HEADERS data/asmap.raw ) add_boost_unit_tests_to_suite(bitcoin test_bitcoin fixture.cpp jsonutil.cpp scriptflags.cpp sigutil.cpp ${ASMAP_HEADERS} # Tests generated from JSON ${JSON_HEADERS} # Wallet test fixture ${BITCOIN_WALLET_TEST_FIXTURE} TESTS activation_tests.cpp 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 bitmanip_tests.cpp blockchain_tests.cpp blockcheck_tests.cpp blockencodings_tests.cpp blockfilter_tests.cpp blockfilter_index_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 compilerbug_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 dnsseeds_tests.cpp dstencode_tests.cpp - excessiveblock_tests.cpp feerate_tests.cpp finalization_tests.cpp flatfile_tests.cpp fs_tests.cpp getarg_tests.cpp hash_tests.cpp interfaces_tests.cpp inv_tests.cpp key_io_tests.cpp key_tests.cpp lcg_tests.cpp logging_tests.cpp mempool_tests.cpp merkle_tests.cpp merkleblock_tests.cpp miner_tests.cpp monolith_opcodes_tests.cpp multisig_tests.cpp net_tests.cpp netbase_tests.cpp op_reversebytes_tests.cpp pmt_tests.cpp policy_fee_tests.cpp policyestimator_tests.cpp prevector_tests.cpp radix_tests.cpp raii_event_tests.cpp random_tests.cpp rcu_tests.cpp ref_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 scriptnum_tests.cpp serialize_tests.cpp settings_tests.cpp sigcache_tests.cpp sigencoding_tests.cpp sighash_tests.cpp sighashtype_tests.cpp sigcheckcount_tests.cpp skiplist_tests.cpp streams_tests.cpp sync_tests.cpp timedata_tests.cpp torcontrol_tests.cpp transaction_tests.cpp txindex_tests.cpp txrequest_tests.cpp txvalidation_tests.cpp txvalidationcache_tests.cpp uint256_tests.cpp undo_tests.cpp util_tests.cpp util_threadnames_tests.cpp validation_block_tests.cpp validation_chainstate_tests.cpp validation_chainstatemanager_tests.cpp validation_flush_tests.cpp validation_tests.cpp validationinterface_tests.cpp versionbits_tests.cpp work_comparator_tests.cpp # RPC Tests ../rpc/test/server_tests.cpp # Wallet tests ${BITCOIN_WALLET_TESTS} ) function(add_boost_test_runners_with_upgrade_activated SUITE EXECUTABLE) set(SUITE_UPGRADE_ACTIVATED "${SUITE}-upgrade-activated") get_target_from_suite(${SUITE_UPGRADE_ACTIVATED} TARGET_UPGRADE_ACTIVATED) if(NOT TARGET ${TARGET_UPGRADE_ACTIVATED}) create_test_suite_with_parent_targets( ${SUITE_UPGRADE_ACTIVATED} check-upgrade-activated check-upgrade-activated-extended ) add_dependencies(${TARGET_UPGRADE_ACTIVATED} ${EXECUTABLE}) endif() get_target_from_suite(${SUITE} SUITE_TARGET) get_target_property(BOOST_TESTS ${SUITE_TARGET} UNIT_TESTS) get_target_from_suite(${SUITE_UPGRADE_ACTIVATED} SUITE_UPGRADE_ACTIVATED_TARGET) set(HRF_LOGGER "HRF,test_suite") foreach(_test_name ${BOOST_TESTS}) if(ENABLE_JUNIT_REPORT) set(JUNIT_LOGGER ":JUNIT,message,${SUITE_UPGRADE_ACTIVATED}-${_test_name}.xml") endif() add_test_runner( ${SUITE_UPGRADE_ACTIVATED} "${_test_name}" ${EXECUTABLE} JUNIT "--run_test=${_test_name}" "--logger=${HRF_LOGGER}${JUNIT_LOGGER}" "--catch_system_errors=no" # Dec. 1st, 2019 at 00:00:00 -- "-testsuitename=Bitcoin ABC unit tests with next upgrade activated" -axionactivationtime=1575158400 ) endforeach() endfunction() add_boost_test_runners_with_upgrade_activated(bitcoin test_bitcoin) target_link_libraries(test_bitcoin rpcclient testutil) if(TARGET bitcoinconsensus-shared) target_link_libraries(test_bitcoin bitcoinconsensus-shared) else() target_link_libraries(test_bitcoin bitcoinconsensus) endif() add_subdirectory(fuzz) diff --git a/src/test/excessiveblock_tests.cpp b/src/test/excessiveblock_tests.cpp deleted file mode 100644 index 2f68d9ba0..000000000 --- a/src/test/excessiveblock_tests.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2017-2020 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 -#include - -#include -#include - -extern UniValue CallRPC(const std::string &args, const util::Ref &context); - -class ExcessiveBlockTestingSetup : public TestingSetup { -public: - ExcessiveBlockTestingSetup() - : TestingSetup(CBaseChainParams::MAIN, - {"-deprecatedrpc=setexcessiveblock"}){}; - - UniValue CallRPC(const std::string &args) { - const util::Ref context{m_node}; - return ::CallRPC(args, context); - } -}; - -BOOST_FIXTURE_TEST_SUITE(excessiveblock_tests, ExcessiveBlockTestingSetup) - -BOOST_AUTO_TEST_CASE(excessiveblock_rpc) { - BOOST_CHECK_NO_THROW(CallRPC("getexcessiveblock")); - - BOOST_CHECK_THROW(CallRPC("setexcessiveblock"), std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock not_uint"), - std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 not_uint"), - std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 1"), - std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock -1"), std::runtime_error); - - BOOST_CHECK_THROW(CallRPC("setexcessiveblock 0"), std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1"), std::runtime_error); - BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000"), std::runtime_error); - BOOST_CHECK_THROW( - CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE - 1)), - std::runtime_error); - BOOST_CHECK_THROW( - CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE)), - std::runtime_error); - - BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + - ToString(ONE_MEGABYTE + 1))); - BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + - ToString(ONE_MEGABYTE + 10))); - - // Default can be higher than 1MB in future - test it too - BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + - ToString(DEFAULT_MAX_BLOCK_SIZE))); - BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + - ToString(DEFAULT_MAX_BLOCK_SIZE * 8))); - - BOOST_CHECK_NO_THROW( - CallRPC(std::string("setexcessiveblock ") + - ToString(std::numeric_limits::max()))); - - BOOST_CHECK_THROW( - CallRPC(std::string("setexcessiveblock ") + - ToString(uint64_t(std::numeric_limits::max()) + 1)), - std::runtime_error); - - BOOST_CHECK_THROW(CallRPC(std::string("setexcessiveblock ") + - ToString(std::numeric_limits::max())), - std::runtime_error); -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/test/functional/abc_rpc_excessiveblock.py b/test/functional/abc_rpc_excessiveblock.py index 30b14b53b..06cc787b7 100755 --- a/test/functional/abc_rpc_excessiveblock.py +++ b/test/functional/abc_rpc_excessiveblock.py @@ -1,92 +1,86 @@ #!/usr/bin/env python3 # Copyright (c) 2017 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # Exercise the Bitcoin ABC RPC calls. import re from test_framework.cdefs import ( DEFAULT_MAX_BLOCK_SIZE, LEGACY_MAX_BLOCK_SIZE, ONE_MEGABYTE, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error +from test_framework.util import assert_equal -BLOCKSIZE_TOO_LOW = "Invalid parameter, excessiveblock must be larger than {}".format( +BLOCKSIZE_TOO_LOW = "Error: Excessive block size must be > {:,} bytes".format( LEGACY_MAX_BLOCK_SIZE) class ExcessiveBlockSizeRPCTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 self.tip = None self.setup_clean_chain = True - self.extra_args = [["-deprecatedrpc=setexcessiveblock"]] + self.extra_args = [[f"-blockmaxsize={LEGACY_MAX_BLOCK_SIZE}"]] def check_subversion(self, pattern_str): # Check that the subversion is set as expected netinfo = self.nodes[0].getnetworkinfo() subversion = netinfo['subversion'] pattern = re.compile(pattern_str) assert pattern.match(subversion) def test_excessiveblock(self): + node = self.nodes[0] + # Check that we start with DEFAULT_MAX_BLOCK_SIZE - getsize = self.nodes[0].getexcessiveblock() + getsize = node.getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, DEFAULT_MAX_BLOCK_SIZE) - # Check that setting to legacy size is ok - self.nodes[0].setexcessiveblock(LEGACY_MAX_BLOCK_SIZE + 1) - getsize = self.nodes[0].getexcessiveblock() - ebs = getsize['excessiveBlockSize'] - assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) - - # Check that going below legacy size is not accepted - assert_raises_rpc_error(-8, BLOCKSIZE_TOO_LOW, - self.nodes[0].setexcessiveblock, LEGACY_MAX_BLOCK_SIZE) - getsize = self.nodes[0].getexcessiveblock() - ebs = getsize['excessiveBlockSize'] - assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) + def setexcessiveblock(block_size): + self.restart_node( + 0, + self.extra_args[0] + + [f"-excessiveblocksize={block_size}"]) - # Check that a negative size returns an error - assert_raises_rpc_error(-8, BLOCKSIZE_TOO_LOW, - self.nodes[0].setexcessiveblock, -2 * LEGACY_MAX_BLOCK_SIZE) - getsize = self.nodes[0].getexcessiveblock() + # Check that setting to legacy size is ok + setexcessiveblock(LEGACY_MAX_BLOCK_SIZE + 1) + getsize = node.getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) # Check setting to 2MB - self.nodes[0].setexcessiveblock(2 * ONE_MEGABYTE) - getsize = self.nodes[0].getexcessiveblock() + setexcessiveblock(2 * ONE_MEGABYTE) + getsize = node.getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 2 * ONE_MEGABYTE) # Check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB2\.0; .*\)/") # Check setting to 13MB - self.nodes[0].setexcessiveblock(13 * ONE_MEGABYTE) - getsize = self.nodes[0].getexcessiveblock() + setexcessiveblock(13 * ONE_MEGABYTE) + getsize = node.getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 13 * ONE_MEGABYTE) # Check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB13\.0; .*\)/") # Check setting to 13.14MB - self.nodes[0].setexcessiveblock(13140000) - getsize = self.nodes[0].getexcessiveblock() + setexcessiveblock(13140000) + getsize = node.getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 13.14 * ONE_MEGABYTE) # check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB13\.1; .*\)/") def run_test(self): self.test_excessiveblock() if __name__ == '__main__': ExcessiveBlockSizeRPCTest().main() diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py index 4f918ff5c..e62249b72 100755 --- a/test/functional/rpc_deprecated.py +++ b/test/functional/rpc_deprecated.py @@ -1,43 +1,33 @@ #!/usr/bin/env python3 # Copyright (c) 2017-2019 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test deprecation of RPC calls.""" -from test_framework.cdefs import DEFAULT_MAX_BLOCK_SIZE from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_raises_rpc_error class DeprecatedRpcTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 self.setup_clean_chain = True - self.extra_args = [[], ["-deprecatedrpc=banscore", - "-deprecatedrpc=setexcessiveblock"]] + self.extra_args = [[], ["-deprecatedrpc=banscore"]] def run_test(self): # This test should be used to verify correct behaviour of deprecated # RPC methods with and without the -deprecatedrpc flags. For example: # # In set_test_params: # self.extra_args = [[], ["-deprecatedrpc=generate"]] # # In run_test: # self.log.info("Test generate RPC") # assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1) # self.nodes[1].generate(1) self.log.info("Test deprecated banscore") assert 'banscore' not in self.nodes[0].getpeerinfo()[0] assert 'banscore' in self.nodes[1].getpeerinfo()[0] - self.log.info("Test deprecated setexcessiveblock RPC") - assert_raises_rpc_error(-32, - 'The setexcessiveblock RPC is deprecated', - self.nodes[0].setexcessiveblock, - DEFAULT_MAX_BLOCK_SIZE) - self.nodes[1].setexcessiveblock(DEFAULT_MAX_BLOCK_SIZE) - if __name__ == '__main__': DeprecatedRpcTest().main()