Merge bitcoin/bitcoin#32845: rpc, test: Fix JSON parsing errors in unloadwallet and getdescriptoractivity RPCs
c5c1960f93doc: Add release notes for changes in RPCs (pablomartin4btc)90fd5acbe5rpc, test: Fix error message in getdescriptoractivity (pablomartin4btc)39fef1d203test: Add missing logging info for each test (pablomartin4btc)53ac704efdrpc, test: Fix error message in unloadwallet (pablomartin4btc)1fc3a8e8e7rpc, test: Add EnsureUniqueWalletName tests (pablomartin4btc)b635bc0896rpc, util: Add EnsureUniqueWalletName (pablomartin4btc) Pull request description: Currently, `unloadwallet` RPC call fails with a JSON parsing error when no `wallet_name` argument is provided. This behavior is misleading because the error originates from a low-level JSON type mismatch, rather than clearly indicating that the wallet name or RPC endpoint (`-rpcwallet=...`) is missing. Also, found out that the [issue](https://github.com/bitcoin/bitcoin/pull/13111#issuecomment-398831543) was noticed during its implementation but never addressed. In addition, I've verified all RPC commands calls finding that `getdescriptoractivity` had the same problem, but related to the array input types (blockhashes & descriptors), so I've corrected that RPC as well. For consistency I've added the missing logging info for each test case in `test/functional/rpc_getdescriptoractivity.py` in preparation for the new test. **_-Before_** ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc unloadwallet error code: -3 error message: JSON value of type number is not of expected type string ``` ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc getdescriptoractivity error code: -3 error message: JSON value of type null is not of expected type array ``` ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc getdescriptoractivity '[]' error code: -3 error message: JSON value of type null is not of expected type array ``` **_-After_** ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc unloadwallet error code: -8 error message: Either the RPC endpoint wallet or the wallet name parameter must be provided ``` ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc getdescriptoractivity error code: -1 error message: getdescriptoractivity ["blockhash",...] [scanobjects,...] ( include_mempool ) Get spend and receive activity associated with a set of descriptors for a set of blocks. This command pairs well with the `relevant_blocks` output of `scanblocks()`. This call may take several minutes. If you encounter timeouts, try specifying no RPC timeout (bitcoin-cli -rpcclienttimeout=0) Arguments: 1. blockhashes (json array, required) The list of blockhashes to examine for activity. Order doesn't matter. Must be along main chain or an error is thrown. [ "blockhash", (string) A valid blockhash ... ] 2. scanobjects (json array, required) Array of scan objects. Every scan object is either a string descriptor or an object: [ "descriptor", (string) An output descriptor { (json object) An object with output descriptor and metadata "desc": "str", (string, required) An output descriptor "range": n or [n,n], (numeric or array, optional, default=1000) The range of HD chain indexes to explore (either end or [begin,end]) }, ... ] 3. include_mempool (boolean, optional, default=true) Whether to include unconfirmed activity ... ``` ``` ./build/bin/bitcoin-cli -regtest -datadir=/tmp/btc getdescriptoractivity '[]' error code: -1 error message: getdescriptoractivity ["blockhash",...] [scanobjects,...] ( include_mempool ) ... ``` ACKs for top commit: achow101: ACKc5c1960f93stickies-v: re-ACKc5c1960f93furszy: ACKc5c1960f93Tree-SHA512: e831ff1acbfd15d2ce3a69bb408cce94664c0b63b2aa2f4627a05c6c052241ae3b5cc238219ef1b30afb489a4a3f4c3030e2168b0c8f08b4d20805d050d810f5
This commit is contained in:
10 files changed
+118
-32
No files matched your search
@@ -19,6 +19,7 @@ target_sources(test_bitcoin
|
||||
scriptpubkeyman_tests.cpp
|
||||
spend_tests.cpp
|
||||
wallet_crypto_tests.cpp
|
||||
wallet_rpc_tests.cpp
|
||||
wallet_tests.cpp
|
||||
wallet_transaction_tests.cpp
|
||||
walletdb_tests.cpp
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025-present 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 <rpc/request.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <univalue.h>
|
||||
#include <wallet/rpc/util.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace wallet {
|
||||
static std::string TestWalletName(const std::string& endpoint, std::optional<std::string> parameter = std::nullopt)
|
||||
{
|
||||
JSONRPCRequest req;
|
||||
req.URI = endpoint;
|
||||
return EnsureUniqueWalletName(req, parameter ? &*parameter : nullptr);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(wallet_rpc_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ensure_unique_wallet_name)
|
||||
{
|
||||
// EnsureUniqueWalletName should only return if exactly one unique wallet name is provided
|
||||
BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo"), "foo");
|
||||
BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo", "foo"), "foo");
|
||||
BOOST_CHECK_EQUAL(TestWalletName("/", "foo"), "foo");
|
||||
BOOST_CHECK_EQUAL(TestWalletName("/bar", "foo"), "foo");
|
||||
|
||||
BOOST_CHECK_THROW(TestWalletName("/"), UniValue);
|
||||
BOOST_CHECK_THROW(TestWalletName("/foo"), UniValue);
|
||||
BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "bar"), UniValue);
|
||||
BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "foobar"), UniValue);
|
||||
BOOST_CHECK_THROW(TestWalletName("/wallet/foobar", "foo"), UniValue);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
} // namespace wallet
|
||||
Reference in new issue
Block a user