Unify ledger_index type (#1019)

Fix #1014
This commit is contained in:
cyan317
2023-12-08 14:20:40 +00:00
committed by GitHub
parent a57abb15a3
commit b886586de3
7 changed files with 119 additions and 19 deletions

View File

@@ -262,9 +262,7 @@ TEST_F(RPCLedgerDataHandlerTest, NoMarker)
mockBackendPtr->updateRange(RANGEMIN); // min
mockBackendPtr->updateRange(RANGEMAX); // max
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
ON_CALL(*rawBackendPtr, fetchLedgerBySequence(RANGEMAX, _))
.WillByDefault(Return(CreateLedgerInfo(LEDGERHASH, RANGEMAX)));
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).WillOnce(Return(CreateLedgerInfo(LEDGERHASH, RANGEMAX)));
// when 'type' not specified, default to all the types
auto limitLine = 5;
@@ -284,8 +282,7 @@ TEST_F(RPCLedgerDataHandlerTest, NoMarker)
bbs.push_back(ticket.getSerializer().peekData());
}
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).WillOnce(Return(bbs));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{LedgerDataHandler{mockBackendPtr}};
@@ -293,7 +290,9 @@ TEST_F(RPCLedgerDataHandlerTest, NoMarker)
auto output = handler.process(req, Context{yield});
ASSERT_TRUE(output);
EXPECT_TRUE(output->as_object().contains("ledger"));
//"close_time_human" 's format depends on platform, might be sightly different
// Note: the format of "close_time_human" depends on the platform and might differ per platform. It is however
// guaranteed to be consistent on the same platform.
EXPECT_EQ(output->as_object().at("ledger").as_object().erase("close_time_human"), 1);
EXPECT_EQ(output->as_object().at("ledger"), json::parse(ledgerExpected));
EXPECT_EQ(output->as_object().at("marker").as_string(), INDEX2);
@@ -303,6 +302,64 @@ TEST_F(RPCLedgerDataHandlerTest, NoMarker)
});
}
TEST_F(RPCLedgerDataHandlerTest, Version2)
{
static auto const ledgerExpected = R"({
"account_hash": "0000000000000000000000000000000000000000000000000000000000000000",
"close_flags": 0,
"close_time": 0,
"close_time_resolution": 0,
"close_time_iso": "2000-01-01T00:00:00Z",
"ledger_hash": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652",
"ledger_index": 30,
"parent_close_time": 0,
"parent_hash": "0000000000000000000000000000000000000000000000000000000000000000",
"total_coins": "0",
"transaction_hash": "0000000000000000000000000000000000000000000000000000000000000000",
"closed": true
})";
auto const rawBackendPtr = dynamic_cast<MockBackend*>(mockBackendPtr.get());
ASSERT_NE(rawBackendPtr, nullptr);
mockBackendPtr->updateRange(RANGEMIN); // min
mockBackendPtr->updateRange(RANGEMAX); // max
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).WillOnce(Return(CreateLedgerInfo(LEDGERHASH, RANGEMAX)));
// When 'type' not specified, default to all the types
auto limitLine = 5;
auto limitTicket = 5;
std::vector<Blob> bbs;
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(limitLine + limitTicket);
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(_, RANGEMAX, _)).WillByDefault(Return(ripple::uint256{INDEX2}));
while ((limitLine--) != 0) {
auto const line = CreateRippleStateLedgerObject("USD", ACCOUNT2, 10, ACCOUNT, 100, ACCOUNT2, 200, TXNID, 123);
bbs.push_back(line.getSerializer().peekData());
}
while ((limitTicket--) != 0) {
auto const ticket = CreateTicketLedgerObject(ACCOUNT, limitTicket);
bbs.push_back(ticket.getSerializer().peekData());
}
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).WillOnce(Return(bbs));
runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{LedgerDataHandler{mockBackendPtr}};
auto const req = json::parse(R"({"limit":10})");
auto output = handler.process(req, Context{.yield = yield, .apiVersion = 2});
ASSERT_TRUE(output);
EXPECT_TRUE(output->as_object().contains("ledger"));
// Note: the format of "close_time_human" depends on the platform and might differ per platform. It is however
// guaranteed to be consistent on the same platform.
EXPECT_EQ(output->as_object().at("ledger").as_object().erase("close_time_human"), 1);
EXPECT_EQ(output->as_object().at("ledger"), json::parse(ledgerExpected));
});
}
TEST_F(RPCLedgerDataHandlerTest, TypeFilter)
{
static auto const ledgerExpected = R"({
@@ -359,7 +416,9 @@ TEST_F(RPCLedgerDataHandlerTest, TypeFilter)
auto output = handler.process(req, Context{yield});
ASSERT_TRUE(output);
EXPECT_TRUE(output->as_object().contains("ledger"));
//"close_time_human" 's format depends on platform, might be sightly different
// Note: the format of "close_time_human" depends on the platform and might differ per platform. It is however
// guaranteed to be consistent on the same platform.
EXPECT_EQ(output->as_object().at("ledger").as_object().erase("close_time_human"), 1);
EXPECT_EQ(output->as_object().at("ledger"), json::parse(ledgerExpected));
EXPECT_EQ(output->as_object().at("marker").as_string(), INDEX2);
@@ -422,7 +481,9 @@ TEST_F(RPCLedgerDataHandlerTest, TypeFilterAMM)
auto output = handler.process(req, Context{yield});
ASSERT_TRUE(output);
EXPECT_TRUE(output->as_object().contains("ledger"));
//"close_time_human" 's format depends on platform, might be sightly different
// Note: the format of "close_time_human" depends on the platform and might differ per platform. It is however
// guaranteed to be consistent on the same platform.
EXPECT_EQ(output->as_object().at("ledger").as_object().erase("close_time_human"), 1);
EXPECT_EQ(output->as_object().at("ledger"), json::parse(ledgerExpected));
EXPECT_EQ(output->as_object().at("marker").as_string(), INDEX2);