Skip to content

Commit

Permalink
[FOLD] Fix gcc,clang compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Dec 20, 2023
1 parent a2b1011 commit 1e2ae18
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/ripple/rpc/handlers/GetAggregatePrice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ getStats(
{
STAmount avg{noIssue(), 0, 0};
Number sd{0};
std::uint16_t size = std::distance(begin, end);
std::uint16_t const size = std::distance(begin, end);
avg = std::accumulate(
begin, end, avg, [&](STAmount const& acc, auto const& it) {
return acc + it.first;
Expand Down Expand Up @@ -302,9 +302,9 @@ doGetAggregatePrice(RPC::JsonContext& context)
return it;
};

auto const median = [&]() {
size_t const middle = size / 2;
if ((size % 2) == 0)
auto const median = [&prices, &itAdvance, &size_ = size]() {
auto const middle = size_ / 2;
if ((size_ % 2) == 0)
{
static STAmount two{noIssue(), 2, 0};
auto it = itAdvance(prices.right.begin(), middle - 1);
Expand Down
72 changes: 36 additions & 36 deletions src/test/app/Oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ struct Oracle_test : public beast::unit_test::suite
Account const bad("bad");
env.memoize(bad);
Oracle oracle(
env, {.owner = bad, .seq = seq(1), .ter = ter(terNO_ACCOUNT)});
env, {.owner = bad, .seq = seq(1), .err = ter(terNO_ACCOUNT)});
}

// Insufficient reserve
{
Env env(*this);
env.fund(env.current()->fees().accountReserve(0), owner);
Oracle oracle(
env, {.owner = owner, .ter = ter(tecINSUFFICIENT_RESERVE)});
env, {.owner = owner, .err = ter(tecINSUFFICIENT_RESERVE)});
}
// Insufficient reserve if the data series extends to greater than 5
{
Expand All @@ -78,7 +78,7 @@ struct Oracle_test : public beast::unit_test::suite
{"XRP", "CAD", 740, 1},
{"XRP", "AUD", 740, 1},
},
.ter = ter(tecINSUFFICIENT_RESERVE)});
.err = ter(tecINSUFFICIENT_RESERVE)});
}

{
Expand All @@ -88,29 +88,29 @@ struct Oracle_test : public beast::unit_test::suite

// Invalid flag
oracle.set(
CreateArg{.flags = tfSellNFToken, .ter = ter(temINVALID_FLAG)});
CreateArg{.flags = tfSellNFToken, .err = ter(temINVALID_FLAG)});

// Duplicate token pair
oracle.set(CreateArg{
.series = {{"XRP", "USD", 740, 1}, {"XRP", "USD", 750, 1}},
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});

// Price is not included
oracle.set(CreateArg{
.series =
{{"XRP", "USD", 740, 1}, {"XRP", "EUR", std::nullopt, 1}},
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});

// Token pair is in update and delete
oracle.set(CreateArg{
.series =
{{"XRP", "USD", 740, 1}, {"XRP", "USD", std::nullopt, 1}},
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});
// Token pair is in add and delete
oracle.set(CreateArg{
.series =
{{"XRP", "EUR", 740, 1}, {"XRP", "EUR", std::nullopt, 1}},
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});

// Array of token pair is 0 or exceeds 10
oracle.set(CreateArg{
Expand All @@ -126,8 +126,8 @@ struct Oracle_test : public beast::unit_test::suite
{"XRP", "US9", 740, 1},
{"XRP", "U10", 750, 1},
{"XRP", "U11", 740, 1}},
.ter = ter(temARRAY_TOO_LARGE)});
oracle.set(CreateArg{.series = {}, .ter = ter(temARRAY_EMPTY)});
.err = ter(temARRAY_TOO_LARGE)});
oracle.set(CreateArg{.series = {}, .err = ter(temARRAY_EMPTY)});
}

// Array of token pair exceeds 10 after update
Expand All @@ -153,7 +153,7 @@ struct Oracle_test : public beast::unit_test::suite
{"XRP", "US9", 740, 1},
{"XRP", "U10", 750, 1},
},
.ter = ter(tecARRAY_TOO_LARGE)});
.err = ter(tecARRAY_TOO_LARGE)});
}

{
Expand All @@ -165,12 +165,12 @@ struct Oracle_test : public beast::unit_test::suite
oracle.set(CreateArg{
.assetClass = std::nullopt,
.provider = "provider",
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});
oracle.set(CreateArg{
.assetClass = "currency",
.provider = std::nullopt,
.uri = "URI",
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});

// Symbol class or provider are included on update
// and don't match the current values
Expand All @@ -179,11 +179,11 @@ struct Oracle_test : public beast::unit_test::suite
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.provider = "provider1",
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.assetClass = "currency1",
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});
}

{
Expand All @@ -195,12 +195,12 @@ struct Oracle_test : public beast::unit_test::suite
// Symbol class
std::string assetClass(17, '0');
oracle.set(
CreateArg{.assetClass = assetClass, .ter = ter(temMALFORMED)});
CreateArg{.assetClass = assetClass, .err = ter(temMALFORMED)});
// provider
std::string const large(257, '0');
oracle.set(CreateArg{.provider = large, .ter = ter(temMALFORMED)});
oracle.set(CreateArg{.provider = large, .err = ter(temMALFORMED)});
// URI
oracle.set(CreateArg{.uri = large, .ter = ter(temMALFORMED)});
oracle.set(CreateArg{.uri = large, .err = ter(temMALFORMED)});
}

{
Expand All @@ -215,7 +215,7 @@ struct Oracle_test : public beast::unit_test::suite
oracle.set(UpdateArg{
.owner = some,
.series = {{"XRP", "USD", 740, 1}},
.ter = ter(temMALFORMED)});
.err = ter(temMALFORMED)});
}

{
Expand All @@ -229,19 +229,19 @@ struct Oracle_test : public beast::unit_test::suite
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime = 60,
.ter = ter(tecINVALID_UPDATE_TIME)});
.err = ter(tecINVALID_UPDATE_TIME)});
// Greater than last close time + 30 sec
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime = 500,
.ter = ter(tecINVALID_UPDATE_TIME)});
.err = ter(tecINVALID_UPDATE_TIME)});
oracle.set(UpdateArg{.series = {{"XRP", "USD", 740, 1}}});
BEAST_EXPECT(oracle.expectLastUpdateTime(150));
// Less than the previous lastUpdateTime
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.lastUpdateTime = 149,
.ter = ter(tecINVALID_UPDATE_TIME)});
.err = ter(tecINVALID_UPDATE_TIME)});
}

{
Expand All @@ -252,11 +252,11 @@ struct Oracle_test : public beast::unit_test::suite
BEAST_EXPECT(oracle.exists());
oracle.set(UpdateArg{
.series = {{"XRP", "EUR", std::nullopt, std::nullopt}},
.ter = ter(tecTOKEN_PAIR_NOT_FOUND)});
.err = ter(tecTOKEN_PAIR_NOT_FOUND)});
// delete all token pairs
oracle.set(UpdateArg{
.series = {{"XRP", "USD", std::nullopt, std::nullopt}},
.ter = ter(tecARRAY_EMPTY)});
.err = ter(tecARRAY_EMPTY)});
}
}

Expand Down Expand Up @@ -326,16 +326,16 @@ struct Oracle_test : public beast::unit_test::suite
Account const bad("bad");
env.memoize(bad);
oracle.remove(
{.owner = bad, .seq = seq(1), .ter = ter(terNO_ACCOUNT)});
{.owner = bad, .seq = seq(1), .err = ter(terNO_ACCOUNT)});
}

// Invalid Sequence
oracle.remove({.documentID = 2, .ter = ter(tecNO_ENTRY)});
oracle.remove({.documentID = 2, .err = ter(tecNO_ENTRY)});

// Invalid owner
Account const invalid("invalid");
env.fund(XRP(1'000), invalid);
oracle.remove({.owner = invalid, .ter = ter(tecNO_ENTRY)});
oracle.remove({.owner = invalid, .err = ter(tecNO_ENTRY)});
}

void
Expand Down Expand Up @@ -514,21 +514,21 @@ struct Oracle_test : public beast::unit_test::suite

// Create
Oracle oracle(env, CreateArg{.owner = alice}, false);
oracle.set(CreateArg{.msig = msig(becky), .ter = ter(tefBAD_QUORUM)});
oracle.set(CreateArg{.msig = msig(becky), .err = ter(tefBAD_QUORUM)});
oracle.set(
CreateArg{.msig = msig(zelda), .ter = ter(tefBAD_SIGNATURE)});
CreateArg{.msig = msig(zelda), .err = ter(tefBAD_SIGNATURE)});
oracle.set(CreateArg{.msig = msig(becky, bogie)});
BEAST_EXPECT(oracle.exists());

// Update
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.msig = msig(becky),
.ter = ter(tefBAD_QUORUM)});
.err = ter(tefBAD_QUORUM)});
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.msig = msig(zelda),
.ter = ter(tefBAD_SIGNATURE)});
.err = ter(tefBAD_SIGNATURE)});
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 741, 1}}, .msig = msig(becky, bogie)});
BEAST_EXPECT(oracle.expectPrice({{"XRP", "USD", 741, 1}}));
Expand All @@ -543,7 +543,7 @@ struct Oracle_test : public beast::unit_test::suite
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 740, 1}},
.msig = msig(becky, bogie),
.ter = ter(tefBAD_SIGNATURE)});
.err = ter(tefBAD_SIGNATURE)});
// updated list succeeds
oracle.set(UpdateArg{
.series = {{"XRP", "USD", 7412, 2}}, .msig = msig(zelda, bob)});
Expand All @@ -553,8 +553,8 @@ struct Oracle_test : public beast::unit_test::suite
BEAST_EXPECT(oracle.expectPrice({{"XRP", "USD", 74245, 3}}));

// Remove
oracle.remove({.msig = msig(bob), .ter = ter(tefBAD_QUORUM)});
oracle.remove({.msig = msig(becky), .ter = ter(tefBAD_SIGNATURE)});
oracle.remove({.msig = msig(bob), .err = ter(tefBAD_QUORUM)});
oracle.remove({.msig = msig(becky), .err = ter(tefBAD_SIGNATURE)});
oracle.remove({.msig = msig(ed)});
BEAST_EXPECT(!oracle.exists());
}
Expand All @@ -571,12 +571,12 @@ struct Oracle_test : public beast::unit_test::suite

env.fund(XRP(1'000), owner);
{
Oracle oracle(env, {.owner = owner, .ter = ter(temDISABLED)});
Oracle oracle(env, {.owner = owner, .err = ter(temDISABLED)});
}

{
Oracle oracle(env, {.owner = owner}, false);
oracle.remove({.ter = ter(temDISABLED)});
oracle.remove({.err = ter(temDISABLED)});
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/jtx/Oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct CreateArg
std::optional<jtx::msig> msig = std::nullopt;
std::optional<jtx::seq> seq = std::nullopt;
std::uint32_t fee = 10;
std::optional<ter> ter = std::nullopt;
std::optional<ter> err = std::nullopt;
};

// Typical defaults for Update
Expand All @@ -64,7 +64,7 @@ struct UpdateArg
std::optional<jtx::msig> msig = std::nullopt;
std::optional<jtx::seq> seq = std::nullopt;
std::uint32_t fee = 10;
std::optional<ter> ter = std::nullopt;
std::optional<ter> err = std::nullopt;
};

struct RemoveArg
Expand All @@ -74,7 +74,7 @@ struct RemoveArg
std::optional<jtx::msig> const& msig = std::nullopt;
std::optional<jtx::seq> seq = std::nullopt;
std::uint32_t fee = 10;
std::optional<ter> const& ter = std::nullopt;
std::optional<ter> const& err = std::nullopt;
};

/** Oracle class facilitates unit-testing of the Price Oracle feature.
Expand All @@ -96,7 +96,7 @@ class Oracle
Json::Value const& jv,
std::optional<jtx::msig> const& msig,
std::optional<jtx::seq> const& seq,
std::optional<ter> const& ter);
std::optional<ter> const& err);

public:
Oracle(Env& env, CreateArg const& arg, bool submit = true);
Expand Down
24 changes: 12 additions & 12 deletions src/test/jtx/impl/Oracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,33 @@ Oracle::remove(RemoveArg const& arg)
jv[jss::Fee] = std::to_string(arg.fee);
else
jv[jss::Fee] = std::to_string(env_.current()->fees().increment.drops());
submit(jv, arg.msig, arg.seq, arg.ter);
submit(jv, arg.msig, arg.seq, arg.err);
}

void
Oracle::submit(
Json::Value const& jv,
std::optional<jtx::msig> const& msig,
std::optional<jtx::seq> const& seq,
std::optional<ter> const& ter)
std::optional<ter> const& err)
{
if (msig)
{
if (seq && ter)
env_(jv, *msig, *seq, *ter);
if (seq && err)
env_(jv, *msig, *seq, *err);
else if (seq)
env_(jv, *msig, *seq);
else if (ter)
env_(jv, *msig, *ter);
else if (err)
env_(jv, *msig, *err);
else
env_(jv, *msig);
}
else if (seq && ter)
env_(jv, *seq, *ter);
else if (seq && err)
env_(jv, *seq, *err);
else if (seq)
env_(jv, *seq);
else if (ter)
env_(jv, *ter);
else if (err)
env_(jv, *err);
else
env_(jv);
env_.close();
Expand Down Expand Up @@ -229,7 +229,7 @@ Oracle::set(UpdateArg const& arg)
dataSeries.append(priceData);
}
jv[jss::PriceDataSeries] = dataSeries;
submit(jv, arg.msig, arg.seq, arg.ter);
submit(jv, arg.msig, arg.seq, arg.err);
}

void
Expand All @@ -247,7 +247,7 @@ Oracle::set(CreateArg const& arg)
.msig = arg.msig,
.seq = arg.seq,
.fee = arg.fee,
.ter = arg.ter});
.err = arg.err});
}

Json::Value
Expand Down
1 change: 0 additions & 1 deletion src/test/rpc/GetAggregatePrice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//==============================================================================

#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include <test/jtx.h>
#include <test/jtx/Oracle.h>
Expand Down

0 comments on commit 1e2ae18

Please sign in to comment.