Merge dabab06a1a into merged_master (Bitcoin PR #19455)

This commit is contained in:
Andrew Poelstra 2020-11-27 19:01:46 +00:00
commit a67921c2c8
3 changed files with 52 additions and 2 deletions

View file

@ -256,6 +256,17 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
return generateBlocks(chainman, mempool, coinbase_script, num_blocks, max_tries);
}
static UniValue generate(const JSONRPCRequest& request)
{
const std::string help_str{"generate ( nblocks maxtries ) has been replaced by the -generate cli option. Refer to -help for more information."};
if (request.fHelp) {
throw std::runtime_error(help_str);
} else {
throw JSONRPCError(RPC_METHOD_NOT_FOUND, help_str);
}
}
static UniValue generatetoaddress(const JSONRPCRequest& request)
{
RPCHelpMan{"generatetoaddress",
@ -1710,6 +1721,7 @@ static const CRPCCommand commands[] =
{ "util", "estimatesmartfee", &estimatesmartfee, {"conf_target", "estimate_mode"} },
{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },
{ "hidden", "generate", &generate, {} },
};
// clang-format on
for (const auto& c : commands) {

35
test/functional/rpc_generate.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python3
# Copyright (c) 2020 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 generate RPC."""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
)
class RPCGenerateTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
def run_test(self):
message = (
"generate ( nblocks maxtries ) has been replaced by the -generate "
"cli option. Refer to -help for more information."
)
self.log.info("Test rpc generate raises with message to use cli option")
assert_raises_rpc_error(-32601, message, self.nodes[0].rpc.generate)
self.log.info("Test rpc generate help prints message to use cli option")
assert_equal(message, self.nodes[0].help("generate"))
self.log.info("Test rpc generate is a hidden command not discoverable in general help")
assert message not in self.nodes[0].help()
if __name__ == "__main__":
RPCGenerateTest().main()

View file

@ -219,6 +219,7 @@ BASE_SCRIPTS = [
'p2p_eviction.py',
'rpc_signmessage.py',
'rpc_generateblock.py',
'rpc_generate.py',
'wallet_balance.py',
'feature_nulldummy.py',
'mempool_accept.py',
@ -740,14 +741,16 @@ class RPCCoverage():
Return a set of currently untested RPC commands.
"""
# This is shared from `test/functional/test-framework/coverage.py`
# This is shared from `test/functional/test_framework/coverage.py`
reference_filename = 'rpc_interface.txt'
coverage_file_prefix = 'coverage.'
coverage_ref_filename = os.path.join(self.dir, reference_filename)
coverage_filenames = set()
all_cmds = set()
covered_cmds = set()
# Consider RPC generate covered, because it is overloaded in
# test_framework/test_node.py and not seen by the coverage check.
covered_cmds = set({'generate'})
if not os.path.isfile(coverage_ref_filename):
raise RuntimeError("No coverage reference found")