Skip to content

Commit

Permalink
Remove ledger_header in API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek authored and Bronek Kozicki committed Oct 13, 2023
1 parent 5abfe09 commit 8402ffb
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ if (tests)
src/test/rpc/KeyGeneration_test.cpp
src/test/rpc/LedgerClosed_test.cpp
src/test/rpc/LedgerData_test.cpp
src/test/rpc/LedgerHeader_test.cpp
src/test/rpc/LedgerRPC_test.cpp
src/test/rpc/LedgerRequestRPC_test.cpp
src/test/rpc/ManifestRPC_test.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Handler const handlerArray[]{
NEEDS_CURRENT_LEDGER},
{"ledger_data", byRef(&doLedgerData), Role::USER, NO_CONDITION},
{"ledger_entry", byRef(&doLedgerEntry), Role::USER, NO_CONDITION},
{"ledger_header", byRef(&doLedgerHeader), Role::USER, NO_CONDITION},
{"ledger_header", byRef(&doLedgerHeader), Role::USER, NO_CONDITION, 1, 1},
{"ledger_request", byRef(&doLedgerRequest), Role::ADMIN, NO_CONDITION},
{"log_level", byRef(&doLogLevel), Role::ADMIN, NO_CONDITION},
{"logrotate", byRef(&doLogRotate), Role::ADMIN, NO_CONDITION},
Expand Down
92 changes: 92 additions & 0 deletions src/test/rpc/LedgerHeader_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 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 <ripple/protocol/jss.h>
#include <test/jtx.h>
#include <test/jtx/Env.h>
#include <test/jtx/envconfig.h>

namespace ripple {

class LedgerHeader_test : public beast::unit_test::suite
{
void
testSimpleCurrent()
{
testcase("Current ledger");
using namespace test::jtx;
Env env{*this, envconfig(no_admin)};

Json::Value params{Json::objectValue};
params[jss::api_version] = 1;
params[jss::ledger_index] = "current";
auto const result =
env.client().invoke("ledger_header", params)[jss::result];
BEAST_EXPECT(result[jss::status] == "success");
BEAST_EXPECT(result.isMember("ledger"));
BEAST_EXPECT(result[jss::ledger][jss::closed] == false);
BEAST_EXPECT(result[jss::validated] == false);
}

void
testSimpleValidated()
{
testcase("Validated ledger");
using namespace test::jtx;
Env env{*this, envconfig(no_admin)};

Json::Value params{Json::objectValue};
params[jss::api_version] = 1;
params[jss::ledger_index] = "validated";
auto const result =
env.client().invoke("ledger_header", params)[jss::result];
BEAST_EXPECT(result[jss::status] == "success");
BEAST_EXPECT(result.isMember("ledger"));
BEAST_EXPECT(result[jss::ledger][jss::closed] == true);
BEAST_EXPECT(result[jss::validated] == true);
}

void
testCommandRetired()
{
testcase("Command retired from API v2");
using namespace test::jtx;
Env env{*this, envconfig(no_admin)};

Json::Value params{Json::objectValue};
params[jss::api_version] = 2;
auto const result =
env.client().invoke("ledger_header", params)[jss::result];
BEAST_EXPECT(result[jss::error] == "unknownCmd");
BEAST_EXPECT(result[jss::status] == "error");
}

public:
void
run() override
{
testSimpleCurrent();
testSimpleValidated();
testCommandRetired();
}
};

BEAST_DEFINE_TESTSUITE(LedgerHeader, rpc, ripple);

} // namespace ripple

0 comments on commit 8402ffb

Please sign in to comment.