fix: LedgerEntryNotExist unittest failure (#1564)

This commit is contained in:
cyan317
2024-07-29 16:41:10 +01:00
committed by GitHub
parent 3a3d8d46dd
commit 8d0e904ecb
2 changed files with 32 additions and 0 deletions

View File

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