Move to clang-format-16 (#908)

Fixes #848
This commit is contained in:
Alex Kremer
2023-10-19 16:55:04 +01:00
committed by GitHub
parent 5de87b9ef8
commit 1aab2b94b1
265 changed files with 3950 additions and 4743 deletions

View File

@@ -42,25 +42,20 @@ using namespace rpc;
namespace json = boost::json;
using namespace testing;
class RPCBookOffersHandlerTest : public HandlerBaseTest
{
};
class RPCBookOffersHandlerTest : public HandlerBaseTest {};
struct ParameterTestBundle
{
struct ParameterTestBundle {
std::string testName;
std::string testJson;
std::string expectedError;
std::string expectedErrorMessage;
};
struct RPCBookOffersParameterTest : public RPCBookOffersHandlerTest, public WithParamInterface<ParameterTestBundle>
{
struct NameGenerator
{
struct RPCBookOffersParameterTest : public RPCBookOffersHandlerTest, public WithParamInterface<ParameterTestBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(const testing::TestParamInfo<ParamType>& info) const
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<ParameterTestBundle>(info.param);
return bundle.testName;
@@ -452,10 +447,10 @@ INSTANTIATE_TEST_SUITE_P(
RPCBookOffersHandler,
RPCBookOffersParameterTest,
testing::ValuesIn(generateParameterBookOffersTestBundles()),
RPCBookOffersParameterTest::NameGenerator());
RPCBookOffersParameterTest::NameGenerator()
);
struct BookOffersNormalTestBundle
{
struct BookOffersNormalTestBundle {
std::string testName;
std::string inputJson;
std::map<ripple::uint256, std::optional<ripple::uint256>> mockedSuccessors;
@@ -466,13 +461,11 @@ struct BookOffersNormalTestBundle
};
struct RPCBookOffersNormalPathTest : public RPCBookOffersHandlerTest,
public WithParamInterface<BookOffersNormalTestBundle>
{
struct NameGenerator
{
public WithParamInterface<BookOffersNormalTestBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(const testing::TestParamInfo<ParamType>& info) const
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<BookOffersNormalTestBundle>(info.param);
return bundle.testName;
@@ -495,23 +488,23 @@ TEST_P(RPCBookOffersNormalPathTest, CheckOutput)
// return valid book dir
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(bundle.mockedSuccessors.size());
for (auto const& [key, value] : bundle.mockedSuccessors)
{
for (auto const& [key, value] : bundle.mockedSuccessors) {
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(key, seq, _)).WillByDefault(Return(value));
}
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(bundle.ledgerObjectCalls);
for (auto const& [key, value] : bundle.mockedLedgerObjects)
{
for (auto const& [key, value] : bundle.mockedLedgerObjects) {
ON_CALL(*rawBackendPtr, doFetchLedgerObject(key, seq, _)).WillByDefault(Return(value));
}
std::vector<Blob> bbs;
std::transform(
bundle.mockedOffers.begin(), bundle.mockedOffers.end(), std::back_inserter(bbs), [](auto const& obj) {
return obj.getSerializer().peekData();
});
bundle.mockedOffers.begin(),
bundle.mockedOffers.end(),
std::back_inserter(bbs),
[](auto const& obj) { return obj.getSerializer().peekData(); }
);
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObjects).Times(1);
@@ -530,7 +523,8 @@ generateNormalPathBookOffersTestBundles()
auto const account2 = GetAccountIDWithString(ACCOUNT2);
auto const frozenTrustLine = CreateRippleStateLedgerObject(
"USD", ACCOUNT, -8, ACCOUNT2, 1000, ACCOUNT, 2000, INDEX1, 2, ripple::lsfLowFreeze);
"USD", ACCOUNT, -8, ACCOUNT2, 1000, ACCOUNT, 2000, INDEX1, 2, ripple::lsfLowFreeze
);
auto const gets10USDPays20XRPOffer = CreateOfferLedgerObject(
ACCOUNT2,
@@ -540,7 +534,8 @@ generateNormalPathBookOffersTestBundles()
ripple::to_string(ripple::xrpCurrency()),
ACCOUNT,
toBase58(ripple::xrpAccount()),
PAYS20XRPGETS10USDBOOKDIR);
PAYS20XRPGETS10USDBOOKDIR
);
auto const gets10USDPays20XRPOwnerOffer = CreateOfferLedgerObject(
ACCOUNT,
@@ -550,7 +545,8 @@ generateNormalPathBookOffersTestBundles()
ripple::to_string(ripple::xrpCurrency()),
ACCOUNT,
toBase58(ripple::xrpAccount()),
PAYS20XRPGETS10USDBOOKDIR);
PAYS20XRPGETS10USDBOOKDIR
);
auto const gets10XRPPays20USDOffer = CreateOfferLedgerObject(
ACCOUNT2,
@@ -560,12 +556,15 @@ generateNormalPathBookOffersTestBundles()
ripple::to_string(ripple::to_currency("USD")),
toBase58(ripple::xrpAccount()),
ACCOUNT,
PAYS20USDGETS10XRPBOOKDIR);
PAYS20USDGETS10XRPBOOKDIR
);
auto const getsXRPPaysUSDBook = getBookBase(std::get<ripple::Book>(
rpc::parseBook(ripple::to_currency("USD"), account, ripple::xrpCurrency(), ripple::xrpAccount())));
rpc::parseBook(ripple::to_currency("USD"), account, ripple::xrpCurrency(), ripple::xrpAccount())
));
auto const getsUSDPaysXRPBook = getBookBase(std::get<ripple::Book>(
rpc::parseBook(ripple::xrpCurrency(), ripple::xrpAccount(), ripple::to_currency("USD"), account)));
rpc::parseBook(ripple::xrpCurrency(), ripple::xrpAccount(), ripple::to_currency("USD"), account)
));
auto const getsXRPPaysUSDInputJson = fmt::format(
R"({{
@@ -579,7 +578,8 @@ generateNormalPathBookOffersTestBundles()
"issuer": "{}"
}}
}})",
ACCOUNT);
ACCOUNT
);
auto const paysXRPGetsUSDInputJson = fmt::format(
R"({{
@@ -593,7 +593,8 @@ generateNormalPathBookOffersTestBundles()
"issuer": "{}"
}}
}})",
ACCOUNT);
ACCOUNT
);
auto const feeLedgerObject = CreateFeeSettingBlob(1, 2, 3, 4, 0);
@@ -657,7 +658,8 @@ generateNormalPathBookOffersTestBundles()
LEDGERHASH,
ACCOUNT2,
193,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysUSDGetsXRPNoFrozenOwnerFundNotEnough",
getsXRPPaysUSDInputJson,
@@ -718,7 +720,8 @@ generateNormalPathBookOffersTestBundles()
LEDGERHASH,
ACCOUNT2,
5,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysUSDGetsXRPFrozen",
getsXRPPaysUSDInputJson,
@@ -774,7 +777,8 @@ generateNormalPathBookOffersTestBundles()
LEDGERHASH,
ACCOUNT2,
0,
2)},
2
)},
BookOffersNormalTestBundle{
"GetsUSDPaysXRPFrozen",
paysXRPGetsUSDInputJson,
@@ -831,7 +835,8 @@ generateNormalPathBookOffersTestBundles()
ACCOUNT2,
PAYS20XRPGETS10USDBOOKDIR,
0,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysXRPGetsUSDWithTransferFee",
paysXRPGetsUSDInputJson,
@@ -890,7 +895,8 @@ generateNormalPathBookOffersTestBundles()
ACCOUNT2,
PAYS20XRPGETS10USDBOOKDIR,
8,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysXRPGetsUSDWithMultipleOffers",
paysXRPGetsUSDInputJson,
@@ -977,7 +983,8 @@ generateNormalPathBookOffersTestBundles()
2,
ACCOUNT2,
PAYS20XRPGETS10USDBOOKDIR,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysXRPGetsUSDSellingOwnCurrency",
paysXRPGetsUSDInputJson,
@@ -1027,7 +1034,8 @@ generateNormalPathBookOffersTestBundles()
ACCOUNT,
PAYS20XRPGETS10USDBOOKDIR,
10,
2)},
2
)},
BookOffersNormalTestBundle{
"PaysXRPGetsUSDTrustLineFrozen",
paysXRPGetsUSDInputJson,
@@ -1086,7 +1094,8 @@ generateNormalPathBookOffersTestBundles()
ACCOUNT2,
PAYS20XRPGETS10USDBOOKDIR,
0,
2)},
2
)},
};
}
@@ -1094,7 +1103,8 @@ INSTANTIATE_TEST_SUITE_P(
RPCBookOffersHandler,
RPCBookOffersNormalPathTest,
testing::ValuesIn(generateNormalPathBookOffersTestBundles()),
RPCBookOffersNormalPathTest::NameGenerator());
RPCBookOffersNormalPathTest::NameGenerator()
);
// ledger not exist
TEST_F(RPCBookOffersHandlerTest, LedgerNonExistViaIntSequence)
@@ -1120,7 +1130,8 @@ TEST_F(RPCBookOffersHandlerTest, LedgerNonExistViaIntSequence)
"issuer": "{}"
}}
}})",
ACCOUNT));
ACCOUNT
));
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
runSpawn([&](boost::asio::yield_context yield) {
auto const output = handler.process(input, Context{yield});
@@ -1154,7 +1165,8 @@ TEST_F(RPCBookOffersHandlerTest, LedgerNonExistViaSequence)
"issuer": "{}"
}}
}})",
ACCOUNT));
ACCOUNT
));
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
runSpawn([&](boost::asio::yield_context yield) {
auto const output = handler.process(input, Context{yield});
@@ -1190,7 +1202,8 @@ TEST_F(RPCBookOffersHandlerTest, LedgerNonExistViaHash)
}}
}})",
LEDGERHASH,
ACCOUNT));
ACCOUNT
));
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
runSpawn([&](boost::asio::yield_context yield) {
auto const output = handler.process(input, Context{yield});
@@ -1218,7 +1231,8 @@ TEST_F(RPCBookOffersHandlerTest, Limit)
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(1);
auto const getsXRPPaysUSDBook = getBookBase(std::get<ripple::Book>(
rpc::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())));
rpc::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())
));
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(getsXRPPaysUSDBook, seq, _))
.WillByDefault(Return(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}));
@@ -1234,8 +1248,9 @@ TEST_F(RPCBookOffersHandlerTest, Limit)
.WillByDefault(Return(CreateFeeSettingBlob(1, 2, 3, 4, 0)));
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(issuer).key, seq, _))
.WillByDefault(Return(
CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData()));
.WillByDefault(
Return(CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData())
);
auto const gets10XRPPays20USDOffer = CreateOfferLedgerObject(
ACCOUNT2,
@@ -1245,7 +1260,8 @@ TEST_F(RPCBookOffersHandlerTest, Limit)
ripple::to_string(ripple::to_currency("USD")),
toBase58(ripple::xrpAccount()),
ACCOUNT,
PAYS20USDGETS10XRPBOOKDIR);
PAYS20USDGETS10XRPBOOKDIR
);
std::vector<Blob> const bbs(10, gets10XRPPays20USDOffer.getSerializer().peekData());
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
@@ -1264,7 +1280,8 @@ TEST_F(RPCBookOffersHandlerTest, Limit)
}},
"limit": 5
}})",
ACCOUNT));
ACCOUNT
));
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
runSpawn([&](boost::asio::yield_context yield) {
auto const output = handler.process(input, Context{yield});
@@ -1290,7 +1307,8 @@ TEST_F(RPCBookOffersHandlerTest, LimitMoreThanMax)
EXPECT_CALL(*rawBackendPtr, doFetchSuccessorKey).Times(1);
auto const getsXRPPaysUSDBook = getBookBase(std::get<ripple::Book>(
rpc::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())));
rpc::parseBook(ripple::to_currency("USD"), issuer, ripple::xrpCurrency(), ripple::xrpAccount())
));
ON_CALL(*rawBackendPtr, doFetchSuccessorKey(getsXRPPaysUSDBook, seq, _))
.WillByDefault(Return(ripple::uint256{PAYS20USDGETS10XRPBOOKDIR}));
@@ -1306,8 +1324,9 @@ TEST_F(RPCBookOffersHandlerTest, LimitMoreThanMax)
.WillByDefault(Return(CreateFeeSettingBlob(1, 2, 3, 4, 0)));
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::account(issuer).key, seq, _))
.WillByDefault(Return(
CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData()));
.WillByDefault(
Return(CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2, TRANSFERRATEX2).getSerializer().peekData())
);
auto const gets10XRPPays20USDOffer = CreateOfferLedgerObject(
ACCOUNT2,
@@ -1317,7 +1336,8 @@ TEST_F(RPCBookOffersHandlerTest, LimitMoreThanMax)
ripple::to_string(ripple::to_currency("USD")),
toBase58(ripple::xrpAccount()),
ACCOUNT,
PAYS20USDGETS10XRPBOOKDIR);
PAYS20USDGETS10XRPBOOKDIR
);
std::vector<Blob> const bbs(BookOffersHandler::LIMIT_MAX + 1, gets10XRPPays20USDOffer.getSerializer().peekData());
ON_CALL(*rawBackendPtr, doFetchLedgerObjects).WillByDefault(Return(bbs));
@@ -1337,7 +1357,8 @@ TEST_F(RPCBookOffersHandlerTest, LimitMoreThanMax)
"limit": {}
}})",
ACCOUNT,
BookOffersHandler::LIMIT_MAX + 1));
BookOffersHandler::LIMIT_MAX + 1
));
auto const handler = AnyHandler{BookOffersHandler{mockBackendPtr}};
runSpawn([&](boost::asio::yield_context yield) {
auto const output = handler.process(input, Context{yield});