refactor: Duplicate ledger_index pattern for RPC handlers (#2755)

Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
This commit is contained in:
emrearıyürek
2025-11-10 18:11:12 +01:00
committed by GitHub
parent 224e835e7c
commit 093606106c
30 changed files with 114 additions and 198 deletions

View File

@@ -88,3 +88,29 @@ TEST(JsonUtils, integralValueAs)
auto const stringJson = boost::json::value("not a number");
EXPECT_THROW(util::integralValueAs<int>(stringJson), std::logic_error);
}
TEST(JsonUtils, getLedgerIndex)
{
auto const emptyJson = boost::json::value();
EXPECT_THROW(std::ignore = util::getLedgerIndex(emptyJson), std::logic_error);
auto const boolJson = boost::json::value(true);
EXPECT_THROW(std::ignore = util::getLedgerIndex(emptyJson), std::logic_error);
auto const numberJson = boost::json::value(12345);
auto ledgerIndex = util::getLedgerIndex(numberJson);
EXPECT_TRUE(ledgerIndex.has_value());
EXPECT_EQ(ledgerIndex.value(), 12345u);
auto const validStringJson = boost::json::value("12345");
ledgerIndex = util::getLedgerIndex(validStringJson);
EXPECT_TRUE(ledgerIndex.has_value());
EXPECT_EQ(ledgerIndex.value(), 12345u);
auto const invalidStringJson = boost::json::value("invalid123");
EXPECT_THROW(std::ignore = util::getLedgerIndex(invalidStringJson), std::invalid_argument);
auto const validatedJson = boost::json::value("validated");
ledgerIndex = util::getLedgerIndex(validatedJson);
EXPECT_FALSE(ledgerIndex.has_value());
}