Bitcoin Core  31.0.0
P2P Digital Currency
wallet_rpc_tests.cpp
Go to the documentation of this file.
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>
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);
21 }
22 
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 
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 
41 } // namespace wallet
static std::string TestWalletName(const std::string &endpoint, std::optional< std::string > parameter=std::nullopt)
#define BOOST_CHECK_THROW(stmt, excMatch)
Definition: object.cpp:18
Basic testing setup.
Definition: setup_common.h:64
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string EnsureUniqueWalletName(const JSONRPCRequest &request, std::optional< std::string_view > wallet_name)
Ensures that a wallet name is specified across the endpoint and wallet_name.
Definition: util.cpp:33
BOOST_AUTO_TEST_CASE(bnb_test)
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:17
std::string URI
Definition: request.h:59