Skip to content

Commit

Permalink
style: Fix formatting via clang-format (#1809)
Browse files Browse the repository at this point in the history
For #1760
  • Loading branch information
PeterChen13579 authored Jan 4, 2025
1 parent 820b32c commit cce7aa2
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ TEST_F(MigrationCassandraManagerLedgerTableTest, MigrateExampleLedgerMigrator)
EXPECT_EQ(newTableSize, gLedgerHeaderRawData.size());

auto const getAccountHash = [this](std::uint32_t seq) {
return data::synchronous([&](auto ctx) { return testMigrationBackend_->fetchAccountHashViaSequence(seq, ctx); });
return data::synchronous([&](auto ctx) { return testMigrationBackend_->fetchAccountHashViaSequence(seq, ctx); }
);
};

EXPECT_EQ(
Expand Down
385 changes: 202 additions & 183 deletions tests/unit/rpc/handlers/BookOffersTests.cpp

Large diffs are not rendered by default.

95 changes: 51 additions & 44 deletions tests/unit/rpc/handlers/GatewayBalancesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ generateNormalPathTestBundles()
overflowState.setFieldAmount(ripple::sfBalance, ripple::STAmount(getIssue("JPY", kISSUER), min64, 80));
return std::vector<NormalTestBundle>{
NormalTestBundle{
.testName="AllBranches",
.mockedDir=createOwnerDirLedgerObject(
.testName = "AllBranches",
.mockedDir = createOwnerDirLedgerObject(
{ripple::uint256{kINDEX2},
ripple::uint256{kINDEX2},
ripple::uint256{kINDEX2},
Expand All @@ -454,20 +454,22 @@ generateNormalPathTestBundles()
ripple::uint256{kINDEX2}},
kINDEX1
),
.mockedObjects=std::vector{// hotwallet
createRippleStateLedgerObject("USD", kISSUER, -10, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
// hotwallet
createRippleStateLedgerObject("CNY", kISSUER, -20, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
// positive balance -> asset
createRippleStateLedgerObject("EUR", kISSUER, 30, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123),
// positive balance -> asset
createRippleStateLedgerObject("JPY", kISSUER, 40, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123),
// obligation
createRippleStateLedgerObject("JPY", kISSUER, -50, kACCOUNT, 10, kACCOUNT3, 20, kTXN_ID, 123),
frozenState

},
.expectedJson=fmt::format(
.mockedObjects =
std::vector{
// hotwallet
createRippleStateLedgerObject("USD", kISSUER, -10, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
// hotwallet
createRippleStateLedgerObject("CNY", kISSUER, -20, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
// positive balance -> asset
createRippleStateLedgerObject("EUR", kISSUER, 30, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123),
// positive balance -> asset
createRippleStateLedgerObject("JPY", kISSUER, 40, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123),
// obligation
createRippleStateLedgerObject("JPY", kISSUER, -50, kACCOUNT, 10, kACCOUNT3, 20, kTXN_ID, 123),
frozenState

},
.expectedJson = fmt::format(
R"({{
"obligations":{{
"JPY":"50"
Expand Down Expand Up @@ -513,13 +515,15 @@ generateNormalPathTestBundles()
kACCOUNT3,
kACCOUNT
),
.hotwallet=fmt::format(R"("hotwallet": "{}")", kACCOUNT2)
.hotwallet = fmt::format(R"("hotwallet": "{}")", kACCOUNT2)
},
NormalTestBundle{
.testName="NoHotwallet",
.mockedDir=createOwnerDirLedgerObject({ripple::uint256{kINDEX2}}, kINDEX1),
.mockedObjects=std::vector{createRippleStateLedgerObject("JPY", kISSUER, -50, kACCOUNT, 10, kACCOUNT3, 20, kTXN_ID, 123)},
.expectedJson=fmt::format(
.testName = "NoHotwallet",
.mockedDir = createOwnerDirLedgerObject({ripple::uint256{kINDEX2}}, kINDEX1),
.mockedObjects = std::vector{createRippleStateLedgerObject(
"JPY", kISSUER, -50, kACCOUNT, 10, kACCOUNT3, 20, kTXN_ID, 123
)},
.expectedJson = fmt::format(
R"({{
"obligations":{{
"JPY":"50"
Expand All @@ -533,10 +537,10 @@ generateNormalPathTestBundles()
.hotwallet = R"("ledger_index" : "validated")"
},
NormalTestBundle{
.testName="ObligationOverflow",
.mockedDir=createOwnerDirLedgerObject({ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}}, kINDEX1),
.mockedObjects=std::vector{overflowState, overflowState},
.expectedJson=fmt::format(
.testName = "ObligationOverflow",
.mockedDir = createOwnerDirLedgerObject({ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}}, kINDEX1),
.mockedObjects = std::vector{overflowState, overflowState},
.expectedJson = fmt::format(
R"({{
"obligations":{{
"JPY":"9999999999999999e80"
Expand All @@ -550,20 +554,22 @@ generateNormalPathTestBundles()
.hotwallet = R"("ledger_index" : "validated")"
},
NormalTestBundle{
.testName="HighID",
.mockedDir=createOwnerDirLedgerObject(
.testName = "HighID",
.mockedDir = createOwnerDirLedgerObject(
{ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}
},
kINDEX1
),
.mockedObjects=std::vector{// hotwallet
createRippleStateLedgerObject("USD", kISSUER, 10, kACCOUNT2, 100, kACCOUNT, 200, kTXN_ID, 123),
// hotwallet
createRippleStateLedgerObject("CNY", kISSUER, 20, kACCOUNT2, 100, kACCOUNT, 200, kTXN_ID, 123),
createRippleStateLedgerObject("EUR", kISSUER, 30, kACCOUNT3, 100, kACCOUNT, 200, kTXN_ID, 123),
createRippleStateLedgerObject("JPY", kISSUER, -50, kACCOUNT3, 10, kACCOUNT, 20, kTXN_ID, 123)
},
.expectedJson=fmt::format(
.mockedObjects =
std::vector{
// hotwallet
createRippleStateLedgerObject("USD", kISSUER, 10, kACCOUNT2, 100, kACCOUNT, 200, kTXN_ID, 123),
// hotwallet
createRippleStateLedgerObject("CNY", kISSUER, 20, kACCOUNT2, 100, kACCOUNT, 200, kTXN_ID, 123),
createRippleStateLedgerObject("EUR", kISSUER, 30, kACCOUNT3, 100, kACCOUNT, 200, kTXN_ID, 123),
createRippleStateLedgerObject("JPY", kISSUER, -50, kACCOUNT3, 10, kACCOUNT, 20, kTXN_ID, 123)
},
.expectedJson = fmt::format(
R"({{
"obligations":{{
"EUR":"30"
Expand Down Expand Up @@ -596,19 +602,20 @@ generateNormalPathTestBundles()
kACCOUNT3,
kACCOUNT
),
.hotwallet=fmt::format(R"("hotwallet": "{}")", kACCOUNT2)
.hotwallet = fmt::format(R"("hotwallet": "{}")", kACCOUNT2)
},
NormalTestBundle{
.testName="HotWalletArray",
.mockedDir=createOwnerDirLedgerObject(
.testName = "HotWalletArray",
.mockedDir = createOwnerDirLedgerObject(
{ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}, ripple::uint256{kINDEX2}}, kINDEX1
),
.mockedObjects=std::vector{
createRippleStateLedgerObject("USD", kISSUER, -10, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
createRippleStateLedgerObject("CNY", kISSUER, -20, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
createRippleStateLedgerObject("EUR", kISSUER, -30, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123)
.mockedObjects =
std::vector{
createRippleStateLedgerObject("USD", kISSUER, -10, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
createRippleStateLedgerObject("CNY", kISSUER, -20, kACCOUNT, 100, kACCOUNT2, 200, kTXN_ID, 123),
createRippleStateLedgerObject("EUR", kISSUER, -30, kACCOUNT, 100, kACCOUNT3, 200, kTXN_ID, 123)

},
},
.expectedJson = fmt::format(
R"({{
"balances":{{
Expand Down Expand Up @@ -637,7 +644,7 @@ generateNormalPathTestBundles()
kACCOUNT2,
kACCOUNT
),
.hotwallet=fmt::format(R"("hotwallet": ["{}", "{}"])", kACCOUNT2, kACCOUNT3)
.hotwallet = fmt::format(R"("hotwallet": ["{}", "{}"])", kACCOUNT2, kACCOUNT3)
},
};
}
Expand Down
30 changes: 24 additions & 6 deletions tests/unit/rpc/handlers/LedgerIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,30 @@ class LedgerIndexTests : public RPCLedgerIndexTest, public WithParamInterface<Le
{
// start from 2024-06-25T12:23:10Z to 2024-06-25T12:23:50Z with step 2
return std::vector<LedgerIndexTestsCaseBundle>{
{.testName="LaterThanMaxLedger", .json=R"({"date": "2024-06-25T12:23:55Z"})", .expectedLedgerIndex=kRANGE_MAX, .closeTimeIso="2024-06-25T12:23:50Z"},
{.testName="GreaterThanMinLedger", .json=R"({"date": "2024-06-25T12:23:11Z"})", .expectedLedgerIndex=kRANGE_MIN, .closeTimeIso="2024-06-25T12:23:10Z"},
{.testName="IsMinLedger", .json=R"({"date": "2024-06-25T12:23:10Z"})", .expectedLedgerIndex=kRANGE_MIN, .closeTimeIso="2024-06-25T12:23:10Z"},
{.testName="IsMaxLedger", .json=R"({"date": "2024-06-25T12:23:50Z"})", .expectedLedgerIndex=kRANGE_MAX, .closeTimeIso="2024-06-25T12:23:50Z"},
{.testName="IsMidLedger", .json=R"({"date": "2024-06-25T12:23:30Z"})", .expectedLedgerIndex=20, .closeTimeIso="2024-06-25T12:23:30Z"},
{.testName="BetweenLedgers", .json=R"({"date": "2024-06-25T12:23:29Z"})", .expectedLedgerIndex=19, .closeTimeIso="2024-06-25T12:23:28Z"}
{.testName = "LaterThanMaxLedger",
.json = R"({"date": "2024-06-25T12:23:55Z"})",
.expectedLedgerIndex = kRANGE_MAX,
.closeTimeIso = "2024-06-25T12:23:50Z"},
{.testName = "GreaterThanMinLedger",
.json = R"({"date": "2024-06-25T12:23:11Z"})",
.expectedLedgerIndex = kRANGE_MIN,
.closeTimeIso = "2024-06-25T12:23:10Z"},
{.testName = "IsMinLedger",
.json = R"({"date": "2024-06-25T12:23:10Z"})",
.expectedLedgerIndex = kRANGE_MIN,
.closeTimeIso = "2024-06-25T12:23:10Z"},
{.testName = "IsMaxLedger",
.json = R"({"date": "2024-06-25T12:23:50Z"})",
.expectedLedgerIndex = kRANGE_MAX,
.closeTimeIso = "2024-06-25T12:23:50Z"},
{.testName = "IsMidLedger",
.json = R"({"date": "2024-06-25T12:23:30Z"})",
.expectedLedgerIndex = 20,
.closeTimeIso = "2024-06-25T12:23:30Z"},
{.testName = "BetweenLedgers",
.json = R"({"date": "2024-06-25T12:23:29Z"})",
.expectedLedgerIndex = 19,
.closeTimeIso = "2024-06-25T12:23:28Z"}
};
}
};
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/rpc/handlers/LedgerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,11 @@ TEST_F(RPCLedgerHandlerTest, DiffNotBinary)

EXPECT_CALL(*backend_, fetchLedgerDiff).Times(1);

los.push_back(LedgerObject{.key=ripple::uint256{kINDEX2}, .blob=Blob{}}); // NOLINT(modernize-use-emplace)
los.push_back(LedgerObject{.key = ripple::uint256{kINDEX2}, .blob = Blob{}}); // NOLINT(modernize-use-emplace)
los.push_back(LedgerObject{
.key=ripple::uint256{kINDEX1},
.blob=createAccountRootObject(kACCOUNT, ripple::lsfGlobalFreeze, 1, 10, 2, kINDEX1, 3).getSerializer().peekData()
.key = ripple::uint256{kINDEX1},
.blob =
createAccountRootObject(kACCOUNT, ripple::lsfGlobalFreeze, 1, 10, 2, kINDEX1, 3).getSerializer().peekData()
});

ON_CALL(*backend_, fetchLedgerDiff(kRANGE_MAX, _)).WillByDefault(Return(los));
Expand Down Expand Up @@ -809,10 +810,11 @@ TEST_F(RPCLedgerHandlerTest, DiffBinary)

EXPECT_CALL(*backend_, fetchLedgerDiff).Times(1);

los.push_back(LedgerObject{.key=ripple::uint256{kINDEX2}, .blob=Blob{}}); // NOLINT(modernize-use-emplace)
los.push_back(LedgerObject{.key = ripple::uint256{kINDEX2}, .blob = Blob{}}); // NOLINT(modernize-use-emplace)
los.push_back(LedgerObject{
.key=ripple::uint256{kINDEX1},
.blob=createAccountRootObject(kACCOUNT, ripple::lsfGlobalFreeze, 1, 10, 2, kINDEX1, 3).getSerializer().peekData()
.key = ripple::uint256{kINDEX1},
.blob =
createAccountRootObject(kACCOUNT, ripple::lsfGlobalFreeze, 1, 10, 2, kINDEX1, 3).getSerializer().peekData()
});

ON_CALL(*backend_, fetchLedgerDiff(kRANGE_MAX, _)).WillByDefault(Return(los));
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/rpc/handlers/MPTHoldersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ TEST_F(RPCMPTHoldersHandlerTest, NonExistLedgerViaLedgerStringIndex)
));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{MPTHoldersHandler{backend_}};
auto const output = handler.process(input, Context{.yield=std::ref(yield)});
auto const output = handler.process(input, Context{.yield = std::ref(yield)});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
Expand All @@ -285,7 +285,7 @@ TEST_F(RPCMPTHoldersHandlerTest, NonExistLedgerViaLedgerIntIndex)
));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{MPTHoldersHandler{backend_}};
auto const output = handler.process(input, Context{.yield=std::ref(yield)});
auto const output = handler.process(input, Context{.yield = std::ref(yield)});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
Expand All @@ -311,7 +311,7 @@ TEST_F(RPCMPTHoldersHandlerTest, NonExistLedgerViaLedgerHash2)
));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{MPTHoldersHandler{backend_}};
auto const output = handler.process(input, Context{.yield=std::ref(yield)});
auto const output = handler.process(input, Context{.yield = std::ref(yield)});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
Expand All @@ -334,7 +334,7 @@ TEST_F(RPCMPTHoldersHandlerTest, NonExistLedgerViaLedgerIndex2)
));
runSpawn([&, this](boost::asio::yield_context yield) {
auto const handler = AnyHandler{MPTHoldersHandler{backend_}};
auto const output = handler.process(input, Context{.yield=std::ref(yield)});
auto const output = handler.process(input, Context{.yield = std::ref(yield)});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "lgrNotFound");
Expand All @@ -361,7 +361,7 @@ TEST_F(RPCMPTHoldersHandlerTest, MPTNotFound)
));
runSpawn([&, this](boost::asio::yield_context yield) {
auto handler = AnyHandler{MPTHoldersHandler{this->backend_}};
auto const output = handler.process(input, Context{.yield=yield});
auto const output = handler.process(input, Context{.yield = yield});
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "objectNotFound");
Expand Down Expand Up @@ -391,7 +391,7 @@ TEST_F(RPCMPTHoldersHandlerTest, DefaultParameters)

auto const mptoken = createMpTokenObject(kHOLDE_R1_ACCOUNT, ripple::uint192(kMPT_ID));
std::vector<Blob> const mpts = {mptoken.getSerializer().peekData()};
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor={}}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = {}}));
EXPECT_CALL(
*backend_,
fetchMPTHolders(ripple::uint192(kMPT_ID), testing::_, testing::Eq(std::nullopt), Const(30), testing::_)
Expand Down Expand Up @@ -439,7 +439,7 @@ TEST_F(RPCMPTHoldersHandlerTest, CustomAmounts)

auto const mptoken = createMpTokenObject(kHOLDE_R1_ACCOUNT, ripple::uint192(kMPT_ID), 0);
std::vector<Blob> const mpts = {mptoken.getSerializer().peekData()};
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor={}}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = {}}));
EXPECT_CALL(
*backend_,
fetchMPTHolders(ripple::uint192(kMPT_ID), testing::_, testing::Eq(std::nullopt), Const(30), testing::_)
Expand Down Expand Up @@ -485,7 +485,7 @@ TEST_F(RPCMPTHoldersHandlerTest, SpecificLedgerIndex)

auto const mptoken = createMpTokenObject(kHOLDE_R1_ACCOUNT, ripple::uint192(kMPT_ID));
std::vector<Blob> const mpts = {mptoken.getSerializer().peekData()};
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor={}}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = {}}));
EXPECT_CALL(
*backend_,
fetchMPTHolders(
Expand Down Expand Up @@ -534,7 +534,7 @@ TEST_F(RPCMPTHoldersHandlerTest, MarkerParameter)
auto const mptoken = createMpTokenObject(kHOLDE_R2_ACCOUNT, ripple::uint192(kMPT_ID));
std::vector<Blob> const mpts = {mptoken.getSerializer().peekData()};
auto const marker = getAccountIdWithString(kHOLDE_R1_ACCOUNT);
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor=marker}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = marker}));
EXPECT_CALL(
*backend_, fetchMPTHolders(ripple::uint192(kMPT_ID), testing::_, testing::Eq(marker), Const(30), testing::_)
)
Expand Down Expand Up @@ -580,7 +580,7 @@ TEST_F(RPCMPTHoldersHandlerTest, MultipleMPTs)
auto const mptoken1 = createMpTokenObject(kHOLDE_R1_ACCOUNT, ripple::uint192(kMPT_ID));
auto const mptoken2 = createMpTokenObject(kHOLDE_R2_ACCOUNT, ripple::uint192(kMPT_ID));
std::vector<Blob> const mpts = {mptoken1.getSerializer().peekData(), mptoken2.getSerializer().peekData()};
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor={}}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = {}}));
EXPECT_CALL(
*backend_,
fetchMPTHolders(ripple::uint192(kMPT_ID), testing::_, testing::Eq(std::nullopt), Const(30), testing::_)
Expand Down Expand Up @@ -622,7 +622,7 @@ TEST_F(RPCMPTHoldersHandlerTest, LimitMoreThanMAx)

auto const mptoken = createMpTokenObject(kHOLDE_R1_ACCOUNT, ripple::uint192(kMPT_ID));
std::vector<Blob> const mpts = {mptoken.getSerializer().peekData()};
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens=mpts, .cursor={}}));
ON_CALL(*backend_, fetchMPTHolders).WillByDefault(Return(MPTHoldersAndCursor{.mptokens = mpts, .cursor = {}}));
EXPECT_CALL(
*backend_,
fetchMPTHolders(
Expand Down
Loading

0 comments on commit cce7aa2

Please sign in to comment.