mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 18:51:47 +02:00
rpc, test: Add EnsureUniqueWalletName tests
Co-authored-by: stickies-v <stickies-v@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
41
src/wallet/test/wallet_rpc_tests.cpp
Normal file
41
src/wallet/test/wallet_rpc_tests.cpp
Normal file
@@ -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