mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
refactor: Duplicate ledger_index pattern for RPC handlers (#2755)
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user