Skip to content

Commit 1fc3a8e

Browse files
rpc, test: Add EnsureUniqueWalletName tests
Co-authored-by: stickies-v <[email protected]>
1 parent b635bc0 commit 1fc3a8e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/wallet/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ target_sources(test_bitcoin
1919
scriptpubkeyman_tests.cpp
2020
spend_tests.cpp
2121
wallet_crypto_tests.cpp
22+
wallet_rpc_tests.cpp
2223
wallet_tests.cpp
2324
wallet_transaction_tests.cpp
2425
walletdb_tests.cpp

src/wallet/test/wallet_rpc_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2025-present The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <rpc/request.h>
6+
#include <test/util/setup_common.h>
7+
#include <univalue.h>
8+
#include <wallet/rpc/util.h>
9+
10+
#include <boost/test/unit_test.hpp>
11+
12+
#include <optional>
13+
#include <string>
14+
15+
namespace wallet {
16+
static std::string TestWalletName(const std::string& endpoint, std::optional<std::string> parameter = std::nullopt)
17+
{
18+
JSONRPCRequest req;
19+
req.URI = endpoint;
20+
return EnsureUniqueWalletName(req, parameter ? &*parameter : nullptr);
21+
}
22+
23+
BOOST_FIXTURE_TEST_SUITE(wallet_rpc_tests, BasicTestingSetup)
24+
25+
BOOST_AUTO_TEST_CASE(ensure_unique_wallet_name)
26+
{
27+
// EnsureUniqueWalletName should only return if exactly one unique wallet name is provided
28+
BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo"), "foo");
29+
BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo", "foo"), "foo");
30+
BOOST_CHECK_EQUAL(TestWalletName("/", "foo"), "foo");
31+
BOOST_CHECK_EQUAL(TestWalletName("/bar", "foo"), "foo");
32+
33+
BOOST_CHECK_THROW(TestWalletName("/"), UniValue);
34+
BOOST_CHECK_THROW(TestWalletName("/foo"), UniValue);
35+
BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "bar"), UniValue);
36+
BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "foobar"), UniValue);
37+
BOOST_CHECK_THROW(TestWalletName("/wallet/foobar", "foo"), UniValue);
38+
}
39+
40+
BOOST_AUTO_TEST_SUITE_END()
41+
} // namespace wallet

0 commit comments

Comments
 (0)