Fix failing assert in connect RPC (#5235)

This commit is contained in:
Mayukha Vadari
2025-01-14 14:52:38 -05:00
committed by GitHub
parent ccc0889803
commit ff8b9aa439
2 changed files with 62 additions and 1 deletions

View File

@@ -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 <test/jtx.h>
#include <xrpl/protocol/jss.h>
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

View File

@@ -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);