diff --git a/src/test/rpc/Connect_test.cpp b/src/test/rpc/Connect_test.cpp new file mode 100644 index 00000000000..8f3fe26adbf --- /dev/null +++ b/src/test/rpc/Connect_test.cpp @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2025 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include + +namespace ripple { + +class Connect_test : public beast::unit_test::suite +{ + void + testErrors() + { + testcase("Errors"); + + using namespace test::jtx; + + { + // standalone mode should fail + Env env{*this}; + BEAST_EXPECT(env.app().config().standalone()); + + auto const result = env.rpc("json", "connect", "{}"); + BEAST_EXPECT(result[jss::result][jss::status] == "error"); + BEAST_EXPECT(result[jss::result].isMember(jss::error)); + BEAST_EXPECT(result[jss::result][jss::error] == "notSynced"); + BEAST_EXPECT( + result[jss::result][jss::error_message] == + "Not synced to the network."); + } + } + +public: + void + run() override + { + testErrors(); + } +}; + +BEAST_DEFINE_TESTSUITE(Connect, rpc, ripple); + +} // namespace ripple diff --git a/src/xrpld/rpc/handlers/Connect.cpp b/src/xrpld/rpc/handlers/Connect.cpp index c564319dc8b..eb4f67e76f8 100644 --- a/src/xrpld/rpc/handlers/Connect.cpp +++ b/src/xrpld/rpc/handlers/Connect.cpp @@ -38,7 +38,9 @@ Json::Value doConnect(RPC::JsonContext& context) { if (context.app.config().standalone()) - return "cannot connect in standalone mode"; + { + return RPC::make_error(rpcNOT_SYNCED); + } if (!context.params.isMember(jss::ip)) return RPC::missing_field_error(jss::ip);