From 8d32d2011d3f4e1d9e587d6f80dfa4a3e9f9393d Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Tue, 7 Jul 2020 11:56:54 +0200 Subject: [PATCH 1/3] test: consider generate covered in _get_uncovered_rpc_commands() --- test/functional/test_runner.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 2fa48006f4..86e9ab3fe2 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -708,14 +708,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") From 92d94ffb8d07cc0d2665c901de5903a3a90d5fd0 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 9 Jul 2020 17:13:51 +0200 Subject: [PATCH 2/3] rpc: print useful help and error message for generate --- src/rpc/mining.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index fee6a893eb..ea961a1514 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -236,6 +236,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", @@ -1198,6 +1209,7 @@ static const CRPCCommand commands[] = { "util", "estimatesmartfee", &estimatesmartfee, {"conf_target", "estimate_mode"} }, { "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} }, + { "hidden", "generate", &generate, {} }, }; // clang-format on From f0aa8aeea5a183ea44a877255d12db7732f2e0a8 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Mon, 6 Jul 2020 05:39:40 +0200 Subject: [PATCH 3/3] test: add rpc_generate functional test --- test/functional/rpc_generate.py | 35 +++++++++++++++++++++++++++++++++ test/functional/test_runner.py | 1 + 2 files changed, 36 insertions(+) create mode 100755 test/functional/rpc_generate.py diff --git a/test/functional/rpc_generate.py b/test/functional/rpc_generate.py new file mode 100755 index 0000000000..9404f1e25e --- /dev/null +++ b/test/functional/rpc_generate.py @@ -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() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 86e9ab3fe2..97c30b2b83 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -193,6 +193,7 @@ BASE_SCRIPTS = [ 'p2p_eviction.py', 'rpc_signmessage.py', 'rpc_generateblock.py', + 'rpc_generate.py', 'wallet_balance.py', 'feature_nulldummy.py', 'mempool_accept.py',