diff --git a/src/test/jtx/Oracle.h b/src/test/jtx/Oracle.h index 474a003ff87..ac46b32d092 100644 --- a/src/test/jtx/Oracle.h +++ b/src/test/jtx/Oracle.h @@ -32,6 +32,12 @@ using AnyValue = std::variant; using OraclesData = std::vector, std::optional>>; +// 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); diff --git a/src/test/jtx/impl/Oracle.cpp b/src/test/jtx/impl/Oracle.cpp index a24540f7326..a6d08e21198 100644 --- a/src/test/jtx/impl/Oracle.cpp +++ b/src/test/jtx/impl/Oracle.cpp @@ -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()) @@ -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 diff --git a/src/test/rpc/GetAggregatePrice_test.cpp b/src/test/rpc/GetAggregatePrice_test.cpp index 2ec65dac192..1fb263bbc55 100644 --- a/src/test/rpc/GetAggregatePrice_test.cpp +++ b/src/test/rpc/GetAggregatePrice_test.cpp @@ -56,7 +56,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite // invalid base_asset, quote_asset std::vector invalidAsset = { - "%None%", + NoneTag, 1, -1, 1.2, @@ -100,7 +100,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite BEAST_EXPECT(ret[jss::error].asString() == "objectNotFound"); // invalid values std::vector 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}}}); @@ -131,7 +131,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite // invalid trim value std::vector 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( @@ -141,7 +141,7 @@ class GetAggregatePrice_test : public beast::unit_test::suite // invalid time threshold value std::vector invalidTime = { - "%None%", -1, 1.2, "", "none", "1.2"}; + NoneTag, -1, 1.2, "", "none", "1.2"}; for (auto const& v : invalidTime) { ret = Oracle::aggregatePrice( diff --git a/src/test/rpc/LedgerRPC_test.cpp b/src/test/rpc/LedgerRPC_test.cpp index e58d1b69e5d..ee10a1cdd88 100644 --- a/src/test/rpc/LedgerRPC_test.cpp +++ b/src/test/rpc/LedgerRPC_test.cpp @@ -2293,7 +2293,7 @@ class LedgerRPC_test : public beast::unit_test::suite Oracle oracle(env, {.owner = owner}); // Malformed document id - std::vector invalid = {"%None%", -1, 1.2, "", "Invalid"}; + std::vector invalid = {NoneTag, -1, 1.2, "", "Invalid"}; for (auto const& v : invalid) { auto const res = Oracle::ledgerEntry(env, owner, v);