feat: Nodes communication via DB (#1976)

Fixes #1966.
This commit is contained in:
Sergey Kuznetsov
2025-04-07 14:18:49 +01:00
committed by GitHub
parent 2385bf547b
commit 2c1a90a20d
22 changed files with 1064 additions and 4 deletions

View File

@@ -24,6 +24,7 @@
#include <chrono>
#include <ctime>
#include <string>
TEST(TimeUtilTests, SystemTpFromUTCStrSuccess)
{
@@ -46,6 +47,47 @@ TEST(TimeUtilTests, SystemTpFromUTCStrFail)
ASSERT_FALSE(tp.has_value());
}
TEST(TimeUtilTests, SystemTpToUtcStr)
{
std::tm timeStruct{};
timeStruct.tm_year = 123; // 2023 (years since 1900)
timeStruct.tm_mon = 9; // October (0-based)
timeStruct.tm_mday = 15;
timeStruct.tm_hour = 14;
timeStruct.tm_min = 30;
timeStruct.tm_sec = 45;
auto timePoint = std::chrono::system_clock::from_time_t(timegm(&timeStruct));
std::string const isoFormat = "%Y-%m-%dT%H:%M:%SZ";
std::string isoStr = util::systemTpToUtcStr(timePoint, isoFormat);
EXPECT_EQ(isoStr, "2023-10-15T14:30:45Z");
std::string const customFormat = "%d/%m/%Y %H:%M:%S";
std::string customStr = util::systemTpToUtcStr(timePoint, customFormat);
EXPECT_EQ(customStr, "15/10/2023 14:30:45");
}
TEST(TimeUtilTests, StringToTimePointToString)
{
std::string const isoFormat = "%Y-%m-%dT%H:%M:%SZ";
std::string const originalStr = "2023-10-15T14:30:45Z";
auto timePoint = util::systemTpFromUtcStr(originalStr, isoFormat);
ASSERT_TRUE(timePoint.has_value());
std::string convertedStr = util::systemTpToUtcStr(*timePoint, isoFormat);
EXPECT_EQ(originalStr, convertedStr);
std::string const customFormat = "%d/%m/%Y %H:%M:%S";
std::string const originalCustomStr = "15/10/2023 14:30:45";
auto timePoint2 = util::systemTpFromUtcStr(originalCustomStr, customFormat);
ASSERT_TRUE(timePoint2.has_value());
std::string convertedCustomStr = util::systemTpToUtcStr(*timePoint2, customFormat);
EXPECT_EQ(originalCustomStr, convertedCustomStr);
EXPECT_EQ(*timePoint, *timePoint2);
}
TEST(TimeUtilTests, SystemTpFromLedgerCloseTime)
{
using namespace std::chrono;