Skip to content

Commit

Permalink
Add constants for "None"
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed May 7, 2024
1 parent b67d3c3 commit ee7247c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/test/jtx/Oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ using AnyValue = std::variant<std::string, double, Json::Int, Json::UInt>;
using OraclesData =
std::vector<std::pair<std::optional<Account>, std::optional<AnyValue>>>;

// Special string value, which is converted to unquoted string in the string
// passed to rpc.
constexpr char const* NoneTag = "%None%";
constexpr char const* UnquotedNone = "None";
constexpr char const* NonePattern = "\"%None%\"";

std::uint32_t
asUInt(AnyValue const& v);

Expand Down
6 changes: 3 additions & 3 deletions src/test/jtx/impl/Oracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Oracle::aggregatePrice(
toJson(jv[jss::time_threshold], *timeThreshold);
// Convert "%None%" to None
auto str = to_string(jv);
str = boost::regex_replace(str, boost::regex("\"%None%\""), "None");
str = boost::regex_replace(str, boost::regex(NonePattern), UnquotedNone);
auto jr = env.rpc("json", "get_aggregate_price", str);

if (jr.isObject())
Expand Down Expand Up @@ -312,8 +312,8 @@ Oracle::ledgerEntry(
}
// Convert "%None%" to None
auto str = to_string(jvParams);
str = boost::regex_replace(str, boost::regex("\"%None%\""), "None");
return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
str = boost::regex_replace(str, boost::regex(NonePattern), UnquotedNone);
return env.rpc("json", "ledger_entry", str)[jss::result];
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/test/rpc/GetAggregatePrice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite

// invalid base_asset, quote_asset
std::vector<AnyValue> invalidAsset = {
"%None%",
NoneTag,
1,
-1,
1.2,
Expand Down Expand Up @@ -100,7 +100,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite
BEAST_EXPECT(ret[jss::error].asString() == "objectNotFound");
// invalid values
std::vector<AnyValue> invalidDocument = {
"%None%", 1.2, -1, "", "none", "1.2"};
NoneTag, 1.2, -1, "", "none", "1.2"};
for (auto const& v : invalidDocument)
{
ret = Oracle::aggregatePrice(env, "XRP", "USD", {{{owner, v}}});
Expand Down Expand Up @@ -131,7 +131,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite

// invalid trim value
std::vector<AnyValue> invalidTrim = {
"%None%", 0, 26, -1, 1.2, "", "none", "1.2"};
NoneTag, 0, 26, -1, 1.2, "", "none", "1.2"};
for (auto const& v : invalidTrim)
{
ret = Oracle::aggregatePrice(
Expand All @@ -141,7 +141,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite

// invalid time threshold value
std::vector<AnyValue> invalidTime = {
"%None%", -1, 1.2, "", "none", "1.2"};
NoneTag, -1, 1.2, "", "none", "1.2"};
for (auto const& v : invalidTime)
{
ret = Oracle::aggregatePrice(
Expand Down
2 changes: 1 addition & 1 deletion src/test/rpc/LedgerRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ class LedgerRPC_test : public beast::unit_test::suite
Oracle oracle(env, {.owner = owner});

// Malformed document id
std::vector<AnyValue> invalid = {"%None%", -1, 1.2, "", "Invalid"};
std::vector<AnyValue> invalid = {NoneTag, -1, 1.2, "", "Invalid"};
for (auto const& v : invalid)
{
auto const res = Oracle::ledgerEntry(env, owner, v);
Expand Down

0 comments on commit ee7247c

Please sign in to comment.