wallet_rpc_tests.cpp
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); 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