mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-30 00:25:52 +00:00
Reformat codebase with 120 char limit (#583)
This commit is contained in:
@@ -28,17 +28,13 @@ using namespace RPCng;
|
||||
namespace json = boost::json;
|
||||
using namespace testing;
|
||||
|
||||
constexpr static auto LEDGERHASH =
|
||||
"4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652";
|
||||
constexpr static auto LEDGERHASH = "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A652";
|
||||
constexpr static auto ACCOUNT = "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn";
|
||||
constexpr static auto ACCOUNT2 = "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun";
|
||||
constexpr static auto ACCOUNT3 = "rB9BMzh27F3Q6a5FtGPDayQoCCEdiRdqcK";
|
||||
constexpr static auto INDEX1 =
|
||||
"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321";
|
||||
constexpr static auto INDEX2 =
|
||||
"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322";
|
||||
constexpr static auto TXNID =
|
||||
"05FB0EB4B899F056FA095537C5817163801F544BAFCEA39C995D76DB4D16F9DD";
|
||||
constexpr static auto INDEX1 = "E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321";
|
||||
constexpr static auto INDEX2 = "E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322";
|
||||
constexpr static auto TXNID = "05FB0EB4B899F056FA095537C5817163801F544BAFCEA39C995D76DB4D16F9DD";
|
||||
|
||||
class RPCAccountHandlerTest : public HandlerBaseTest
|
||||
{
|
||||
@@ -228,8 +224,7 @@ TEST_F(RPCAccountHandlerTest, AccountNotString)
|
||||
// error case ledger non exist via hash
|
||||
TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerHash)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
// mock fetchLedgerByHash return empty
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _))
|
||||
.WillByDefault(Return(std::optional<ripple::LedgerInfo>{}));
|
||||
@@ -256,13 +251,11 @@ TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerHash)
|
||||
// error case ledger non exist via index
|
||||
TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerStringIndex)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
// mock fetchLedgerBySequence return empty
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(std::optional<ripple::LedgerInfo>{}));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(std::optional<ripple::LedgerInfo>{}));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
auto const input = json::parse(fmt::format(
|
||||
R"({{
|
||||
@@ -282,13 +275,11 @@ TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerStringIndex)
|
||||
|
||||
TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerIntIndex)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
// mock fetchLedgerBySequence return empty
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(std::optional<ripple::LedgerInfo>{}));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(std::optional<ripple::LedgerInfo>{}));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
auto const input = json::parse(fmt::format(
|
||||
R"({{
|
||||
@@ -310,14 +301,12 @@ TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerIntIndex)
|
||||
// idk why this case will happen in reality
|
||||
TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerHash2)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
// mock fetchLedgerByHash return ledger but seq is 31 > 30
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 31);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _))
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _)).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerByHash).Times(1);
|
||||
auto const input = json::parse(fmt::format(
|
||||
R"({{
|
||||
@@ -339,8 +328,7 @@ TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerHash2)
|
||||
// error case ledger > max seq via index
|
||||
TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerIndex2)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
// no need to check from db,call fetchLedgerBySequence 0 time
|
||||
@@ -365,17 +353,14 @@ TEST_F(RPCAccountHandlerTest, NonExistLedgerViaLedgerIndex2)
|
||||
// error case account not exist
|
||||
TEST_F(RPCAccountHandlerTest, NonExistAccount)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _))
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerByHash(ripple::uint256{LEDGERHASH}, _)).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerByHash).Times(1);
|
||||
// fetch account object return emtpy
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject)
|
||||
.WillByDefault(Return(std::optional<Blob>{}));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject).WillByDefault(Return(std::optional<Blob>{}));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(1);
|
||||
auto const input = json::parse(fmt::format(
|
||||
R"({{
|
||||
@@ -426,13 +411,11 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
|
||||
}
|
||||
]
|
||||
})";
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -440,23 +423,18 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
|
||||
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
// return a non empty account
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
|
||||
// return owner index containing 2 indexes
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(
|
||||
{ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||
|
||||
// return two payment channel objects
|
||||
std::vector<Blob> bbs;
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
bbs.push_back(channel1.getSerializer().peekData());
|
||||
bbs.push_back(channel1.getSerializer().peekData());
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||
@@ -478,13 +456,11 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
|
||||
// normal case : limit is used
|
||||
TEST_F(RPCAccountHandlerTest, UseLimit)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -492,9 +468,7 @@ TEST_F(RPCAccountHandlerTest, UseLimit)
|
||||
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
// return a non empty account
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
|
||||
// return owner index
|
||||
std::vector<ripple::uint256> indexes;
|
||||
@@ -504,15 +478,13 @@ TEST_F(RPCAccountHandlerTest, UseLimit)
|
||||
while (repetitions--)
|
||||
{
|
||||
indexes.push_back(ripple::uint256{INDEX1});
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
bbs.push_back(channel.getSerializer().peekData());
|
||||
}
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(indexes, INDEX1);
|
||||
// it should not appear in return marker,marker is the current page
|
||||
ownerDir.setFieldU64(ripple::sfIndexNext, 99);
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||
|
||||
@@ -530,22 +502,18 @@ TEST_F(RPCAccountHandlerTest, UseLimit)
|
||||
ASSERT_TRUE(output);
|
||||
|
||||
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), 20);
|
||||
EXPECT_THAT(
|
||||
(*output).as_object().at("marker").as_string().c_str(),
|
||||
EndsWith(",0"));
|
||||
EXPECT_THAT((*output).as_object().at("marker").as_string().c_str(), EndsWith(",0"));
|
||||
});
|
||||
}
|
||||
|
||||
// normal case : destination is used
|
||||
TEST_F(RPCAccountHandlerTest, UseDestination)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -553,9 +521,7 @@ TEST_F(RPCAccountHandlerTest, UseDestination)
|
||||
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
// return a non empty account
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
|
||||
// return owner index
|
||||
std::vector<ripple::uint256> indexes;
|
||||
@@ -566,8 +532,7 @@ TEST_F(RPCAccountHandlerTest, UseDestination)
|
||||
while (repetitions--)
|
||||
{
|
||||
indexes.push_back(ripple::uint256{INDEX1});
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
bbs.push_back(channel.getSerializer().peekData());
|
||||
}
|
||||
|
||||
@@ -576,14 +541,12 @@ TEST_F(RPCAccountHandlerTest, UseDestination)
|
||||
while (repetitions--)
|
||||
{
|
||||
indexes.push_back(ripple::uint256{INDEX1});
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT3, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT3, 100, 10, 32, TXNID, 28);
|
||||
bbs.push_back(channel.getSerializer().peekData());
|
||||
}
|
||||
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(indexes, INDEX1);
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||
|
||||
@@ -609,13 +572,11 @@ TEST_F(RPCAccountHandlerTest, UseDestination)
|
||||
// normal case : but the lines is emtpy
|
||||
TEST_F(RPCAccountHandlerTest, EmptyChannel)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -623,15 +584,12 @@ TEST_F(RPCAccountHandlerTest, EmptyChannel)
|
||||
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
// return a non empty account
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
|
||||
// return owner index
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({}, INDEX1);
|
||||
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||
auto const input = json::parse(fmt::format(
|
||||
@@ -687,13 +645,11 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
|
||||
}
|
||||
]
|
||||
})";
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -701,23 +657,18 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
|
||||
auto owneDirKk = ripple::keylet::ownerDir(account).key;
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
// return a non empty account
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
|
||||
// return owner index
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(
|
||||
{ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX1}, ripple::uint256{INDEX2}}, INDEX1);
|
||||
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(owneDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
|
||||
|
||||
// return two payment channel objects
|
||||
std::vector<Blob> bbs;
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
channel1.setFieldU32(ripple::sfExpiration, 100);
|
||||
channel1.setFieldU32(ripple::sfCancelAfter, 200);
|
||||
channel1.setFieldU32(ripple::sfSourceTag, 300);
|
||||
@@ -742,8 +693,7 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
|
||||
// normal case : test marker output correct
|
||||
TEST_F(RPCAccountHandlerTest, MarkerOutput)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
@@ -751,22 +701,17 @@ TEST_F(RPCAccountHandlerTest, MarkerOutput)
|
||||
auto ownerDirKk = ripple::keylet::ownerDir(account).key;
|
||||
constexpr static auto nextPage = 99;
|
||||
constexpr static auto limit = 15;
|
||||
auto ownerDir2Kk =
|
||||
ripple::keylet::page(ripple::keylet::ownerDir(account), nextPage).key;
|
||||
auto ownerDir2Kk = ripple::keylet::page(ripple::keylet::ownerDir(account), nextPage).key;
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
|
||||
|
||||
std::vector<Blob> bbs;
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
// owner dir contains 10 indexes
|
||||
int objectsCount = 10;
|
||||
std::vector<ripple::uint256> indexes;
|
||||
@@ -787,15 +732,12 @@ TEST_F(RPCAccountHandlerTest, MarkerOutput)
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(indexes, INDEX1);
|
||||
ownerDir.setFieldU64(ripple::sfIndexNext, nextPage);
|
||||
// first page 's next page is 99
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(ownerDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
ripple::STObject ownerDir2 = CreateOwnerDirLedgerObject(indexes, INDEX1);
|
||||
// second page's next page is 0
|
||||
ownerDir2.setFieldU64(ripple::sfIndexNext, 0);
|
||||
ON_CALL(
|
||||
*rawBackendPtr,
|
||||
doFetchLedgerObject(ownerDir2Kk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDir2Kk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir2.getSerializer().peekData()));
|
||||
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||
@@ -812,9 +754,7 @@ TEST_F(RPCAccountHandlerTest, MarkerOutput)
|
||||
auto handler = AnyHandler{AccountChannelsHandler{this->mockBackendPtr}};
|
||||
auto const output = handler.process(input, Context{std::ref(yield)});
|
||||
ASSERT_TRUE(output);
|
||||
EXPECT_EQ(
|
||||
(*output).as_object().at("marker").as_string().c_str(),
|
||||
fmt::format("{},{}", INDEX1, nextPage));
|
||||
EXPECT_EQ((*output).as_object().at("marker").as_string().c_str(), fmt::format("{},{}", INDEX1, nextPage));
|
||||
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), 15);
|
||||
});
|
||||
}
|
||||
@@ -822,30 +762,24 @@ TEST_F(RPCAccountHandlerTest, MarkerOutput)
|
||||
// normal case : handler marker correctly
|
||||
TEST_F(RPCAccountHandlerTest, MarkerInput)
|
||||
{
|
||||
MockBackend* rawBackendPtr =
|
||||
static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
MockBackend* rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
|
||||
mockBackendPtr->updateRange(10); // min
|
||||
mockBackendPtr->updateRange(30); // max
|
||||
auto account = GetAccountIDWithString(ACCOUNT);
|
||||
auto accountKk = ripple::keylet::account(account).key;
|
||||
constexpr static auto nextPage = 99;
|
||||
constexpr static auto limit = 15;
|
||||
auto ownerDirKk =
|
||||
ripple::keylet::page(ripple::keylet::ownerDir(account), nextPage).key;
|
||||
auto ownerDirKk = ripple::keylet::page(ripple::keylet::ownerDir(account), nextPage).key;
|
||||
auto ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence)
|
||||
.WillByDefault(Return(ledgerinfo));
|
||||
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
|
||||
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
|
||||
// fetch account object return something
|
||||
auto fake = Blob{'f', 'a', 'k', 'e'};
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(fake));
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, testing::_, testing::_)).WillByDefault(Return(fake));
|
||||
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
|
||||
|
||||
std::vector<Blob> bbs;
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(
|
||||
ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
ripple::STObject channel1 = CreatePaymentChannelLedgerObject(ACCOUNT, ACCOUNT2, 100, 10, 32, TXNID, 28);
|
||||
int objectsCount = limit;
|
||||
std::vector<ripple::uint256> indexes;
|
||||
while (objectsCount != 0)
|
||||
@@ -858,8 +792,7 @@ TEST_F(RPCAccountHandlerTest, MarkerInput)
|
||||
|
||||
ripple::STObject ownerDir = CreateOwnerDirLedgerObject(indexes, INDEX1);
|
||||
ownerDir.setFieldU64(ripple::sfIndexNext, 0);
|
||||
ON_CALL(
|
||||
*rawBackendPtr, doFetchLedgerObject(ownerDirKk, testing::_, testing::_))
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ownerDirKk, testing::_, testing::_))
|
||||
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
|
||||
|
||||
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
|
||||
@@ -882,7 +815,6 @@ TEST_F(RPCAccountHandlerTest, MarkerInput)
|
||||
EXPECT_TRUE((*output).as_object().if_contains("marker") == nullptr);
|
||||
// the first item is the marker itself, so the result will have limit-1
|
||||
// items
|
||||
EXPECT_EQ(
|
||||
(*output).as_object().at("channels").as_array().size(), limit - 1);
|
||||
EXPECT_EQ((*output).as_object().at("channels").as_array().size(), limit - 1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user