/tmp/bitcoin/src/wallet/test/wallet_rpc_tests.cpp
Line | Count | Source |
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 | 9 | { |
18 | 9 | JSONRPCRequest req; |
19 | 9 | req.URI = endpoint; |
20 | 9 | return EnsureUniqueWalletName(req, parameter); |
21 | 9 | } |
22 | | |
23 | | BOOST_FIXTURE_TEST_SUITE(wallet_rpc_tests, BasicTestingSetup) |
24 | | |
25 | | BOOST_AUTO_TEST_CASE(ensure_unique_wallet_name) |
26 | 1 | { |
27 | | // EnsureUniqueWalletName should only return if exactly one unique wallet name is provided |
28 | 1 | BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo"), "foo"); |
29 | 1 | BOOST_CHECK_EQUAL(TestWalletName("/wallet/foo", "foo"), "foo"); |
30 | 1 | BOOST_CHECK_EQUAL(TestWalletName("/", "foo"), "foo"); |
31 | 1 | BOOST_CHECK_EQUAL(TestWalletName("/bar", "foo"), "foo"); |
32 | | |
33 | 1 | BOOST_CHECK_THROW(TestWalletName("/"), UniValue); |
34 | 1 | BOOST_CHECK_THROW(TestWalletName("/foo"), UniValue); |
35 | 1 | BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "bar"), UniValue); |
36 | 1 | BOOST_CHECK_THROW(TestWalletName("/wallet/foo", "foobar"), UniValue); |
37 | 1 | BOOST_CHECK_THROW(TestWalletName("/wallet/foobar", "foo"), UniValue); |
38 | 1 | } |
39 | | |
40 | | BOOST_AUTO_TEST_SUITE_END() |
41 | | } // namespace wallet |