mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-19 19:25:53 +00:00
fix: LedgerEntryNotExist unittest failure (#1564)
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "rpc/RPCHelpers.hpp"
|
||||
#include "rpc/common/Types.hpp"
|
||||
#include "util/AccountUtils.hpp"
|
||||
#include "util/Assert.hpp"
|
||||
|
||||
#include <boost/json/conversion.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
@@ -33,6 +34,7 @@
|
||||
#include <xrpl/basics/strHex.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
#include <xrpl/protocol/Issue.h>
|
||||
#include <xrpl/protocol/LedgerFormats.h>
|
||||
@@ -153,6 +155,7 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input input, Context const& ctx)
|
||||
|
||||
// check ledger exists
|
||||
auto const range = sharedPtrBackend_->fetchLedgerRange();
|
||||
ASSERT(range.has_value(), "Ledger range must be available");
|
||||
auto const lgrInfoOrStatus = getLedgerHeaderFromHashOrSeq(
|
||||
*sharedPtrBackend_, ctx.yield, input.ledgerHash, input.ledgerIndex, range->maxSequence
|
||||
);
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "util/NameGenerator.hpp"
|
||||
#include "util/TestObject.hpp"
|
||||
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <boost/json/value_to.hpp>
|
||||
@@ -2726,6 +2729,7 @@ TEST_F(RPCLedgerEntryTest, LedgerEntryDeleted)
|
||||
// Expected Result: return entryNotFound error
|
||||
TEST_F(RPCLedgerEntryTest, LedgerEntryNotExist)
|
||||
{
|
||||
backend->setRange(RANGEMIN, RANGEMAX);
|
||||
auto const ledgerinfo = CreateLedgerHeader(LEDGERHASH, RANGEMAX);
|
||||
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _)).WillRepeatedly(Return(ledgerinfo));
|
||||
EXPECT_CALL(*backend, doFetchLedgerObject(ripple::uint256{INDEX1}, RANGEMAX, _))
|
||||
@@ -2916,6 +2920,7 @@ TEST_F(RPCLedgerEntryTest, ObjectDeletedPreviously)
|
||||
// Expected Result: return entryNotFound error
|
||||
TEST_F(RPCLedgerEntryTest, ObjectSeqNotExist)
|
||||
{
|
||||
backend->setRange(RANGEMIN, RANGEMAX);
|
||||
auto const ledgerinfo = CreateLedgerHeader(LEDGERHASH, RANGEMAX);
|
||||
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _)).WillRepeatedly(Return(ledgerinfo));
|
||||
EXPECT_CALL(*backend, doFetchLedgerObject(ripple::uint256{INDEX1}, RANGEMAX, _))
|
||||
@@ -2938,3 +2943,27 @@ TEST_F(RPCLedgerEntryTest, ObjectSeqNotExist)
|
||||
EXPECT_EQ(myerr, "entryNotFound");
|
||||
});
|
||||
}
|
||||
|
||||
using RPCLedgerEntryDeathTest = RPCLedgerEntryTest;
|
||||
|
||||
TEST_F(RPCLedgerEntryDeathTest, RangeNotAvailable)
|
||||
{
|
||||
boost::asio::io_context ctx;
|
||||
bool checkCalled = false;
|
||||
spawn(ctx, [&, _ = make_work_guard(ctx)](boost::asio::yield_context yield) {
|
||||
auto const handler = AnyHandler{LedgerEntryHandler{backend}};
|
||||
auto const req = json::parse(fmt::format(
|
||||
R"({{
|
||||
"index": "{}"
|
||||
}})",
|
||||
INDEX1
|
||||
));
|
||||
checkCalled = true;
|
||||
EXPECT_DEATH(
|
||||
{ [[maybe_unused]] auto __ = handler.process(req, Context{yield}); }, "Ledger range must be available"
|
||||
);
|
||||
});
|
||||
|
||||
ctx.run();
|
||||
ASSERT_TRUE(checkCalled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user