From dd5511d31aa91b94c22c2d0117fc8667043cca0c Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 5 Jul 2023 11:01:41 -0400 Subject: [PATCH 1/5] Fix malformed optional param --- src/ripple/rpc/handlers/AccountInfo.cpp | 3 +- src/ripple/rpc/handlers/AccountTx.cpp | 14 ++++ src/ripple/rpc/handlers/NoRippleCheck.cpp | 9 +++ src/test/rpc/AccountTx_test.cpp | 21 ++++++ src/test/rpc/NoRipple_test.cpp | 89 +++++++++++++++-------- 5 files changed, 104 insertions(+), 32 deletions(-) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 13487dd2dae..1f849cc89da 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -128,7 +128,8 @@ doAccountInfo(RPC::JsonContext& context) // The document states that signer_lists is a bool, however // assigning any string value works. Do not allow this. // This check is for api Version 2 onwards only - if (!params[jss::signer_lists].isBool() && context.apiVersion > 1) + if (params.isMember(jss::signer_lists) && + !params[jss::signer_lists].isBool() && context.apiVersion > 1) { RPC::inject_error(rpcINVALID_PARAMS, result); return result; diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index bfbc76362a3..7d4233bfaeb 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -389,6 +389,20 @@ doAccountTxJson(RPC::JsonContext& context) AccountTxArgs args; Json::Value response; + // The document states that binary and forward params is a boolean value, + // however, assigning any string value works. Do not allow this. + // This check is for api Version 2 onwards only + if (params.isMember(jss::binary) && !params[jss::binary].isBool() && + context.apiVersion > 1) + { + return rpcError(rpcINVALID_PARAMS); + } + if (params.isMember(jss::forward) && !params[jss::forward].isBool() && + context.apiVersion > 1) + { + return rpcError(rpcINVALID_PARAMS); + } + args.limit = params.isMember(jss::limit) ? params[jss::limit].asUInt() : 0; args.binary = params.isMember(jss::binary) && params[jss::binary].asBool(); args.forward = diff --git a/src/ripple/rpc/handlers/NoRippleCheck.cpp b/src/ripple/rpc/handlers/NoRippleCheck.cpp index 20137c985c9..c570cce83a1 100644 --- a/src/ripple/rpc/handlers/NoRippleCheck.cpp +++ b/src/ripple/rpc/handlers/NoRippleCheck.cpp @@ -83,6 +83,15 @@ doNoRippleCheck(RPC::JsonContext& context) if (params.isMember(jss::transactions)) transactions = params["transactions"].asBool(); + // The document states that transactions params is a boolean value, + // however, assigning any string value works. Do not allow this. + // This check is for api Version 2 onwards only + if (params.isMember(jss::transactions) && + !params[jss::transactions].isBool() && context.apiVersion > 1) + { + return rpcError(rpcINVALID_PARAMS); + } + std::shared_ptr ledger; auto result = RPC::lookupLedger(ledger, context); if (!ledger) diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 2e09ad93b86..8c6adb7f139 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -315,6 +315,27 @@ class AccountTx_test : public beast::unit_test::suite env.rpc("json", "account_tx", to_string(p)), rpcLGR_IDX_MALFORMED)); } + // test binary and forward for bool/non bool values + { + Json::Value p{jParms}; + p[jss::binary] = "asdf"; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + rpcINVALID_PARAMS)); + + p[jss::binary] = true; + Json::Value result{env.rpc("json", "account_tx", to_string(p))}; + BEAST_EXPECT(result[jss::result][jss::status] == "success"); + + p[jss::forward] = "true"; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + rpcINVALID_PARAMS)); + + p[jss::forward] = false; + result = env.rpc("json", "account_tx", to_string(p)); + BEAST_EXPECT(result[jss::result][jss::status] == "success"); + } } } diff --git a/src/test/rpc/NoRipple_test.cpp b/src/test/rpc/NoRipple_test.cpp index aa7358f77c8..7686c3b870a 100644 --- a/src/test/rpc/NoRipple_test.cpp +++ b/src/test/rpc/NoRipple_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace ripple { @@ -204,9 +205,12 @@ class NoRipple_test : public beast::unit_test::suite } void - testDefaultRipple(FeatureBitset features) + testDefaultRipple(FeatureBitset features, unsigned int apiVersion) { - testcase("Set default ripple on an account and check new trustlines"); + testcase( + "Set default ripple on an account and check new trustlines " + "Version " + + std::to_string(apiVersion)); using namespace jtx; Env env(*this, features); @@ -223,42 +227,60 @@ class NoRipple_test : public beast::unit_test::suite env(trust(gw, USD(100), alice, 0)); env(trust(gw, USD(100), bob, 0)); + Json::Value params; + params[jss::api_version] = apiVersion; + if (params[jss::api_version] < 2) { - Json::Value params; - params[jss::account] = gw.human(); - params[jss::peer] = alice.human(); + { + params[jss::account] = gw.human(); + params[jss::peer] = alice.human(); - auto lines = env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == true); - } - { - Json::Value params; - params[jss::account] = alice.human(); - params[jss::peer] = gw.human(); + auto lines = + env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == true); + } + { + params[jss::account] = alice.human(); + params[jss::peer] = gw.human(); - auto lines = env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple].asBool() == true); - } - { - Json::Value params; - params[jss::account] = gw.human(); - params[jss::peer] = bob.human(); + auto lines = + env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == true); + } + { + params[jss::account] = gw.human(); + params[jss::peer] = bob.human(); + + auto lines = + env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == false); + } + { + params[jss::account] = bob.human(); + params[jss::peer] = gw.human(); - auto lines = env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple].asBool() == false); + auto lines = + env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == false); + } } + else { - Json::Value params; - params[jss::account] = bob.human(); - params[jss::peer] = gw.human(); + // test for transactions + { + params[jss::account] = bob.human(); + params[jss::role] = "gateway"; + params[jss::transactions] = "asdf"; - auto lines = env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == false); + auto lines = + env.rpc("json", "noripple_check", to_string(params)); + BEAST_EXPECT(lines[jss::result][jss::error] == "invalidParams"); + } } } @@ -268,9 +290,14 @@ class NoRipple_test : public beast::unit_test::suite testSetAndClear(); auto withFeatsTests = [this](FeatureBitset features) { + for (auto testVersion = RPC::apiMinimumSupportedVersion; + testVersion <= RPC::apiBetaVersion; + ++testVersion) + { + testDefaultRipple(features, testVersion); + } testNegativeBalance(features); testPairwise(features); - testDefaultRipple(features); }; using namespace jtx; auto const sa = supported_amendments(); From 014ae3c0b00f691a35989d8dc39662e6ef044640 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 18 Jul 2023 10:06:38 -0400 Subject: [PATCH 2/5] quick fix --- src/ripple/rpc/handlers/AccountInfo.cpp | 2 +- src/ripple/rpc/handlers/AccountTx.cpp | 8 ++++---- src/ripple/rpc/handlers/NoRippleCheck.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 1f849cc89da..81bbb48bf72 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -129,7 +129,7 @@ doAccountInfo(RPC::JsonContext& context) // assigning any string value works. Do not allow this. // This check is for api Version 2 onwards only if (params.isMember(jss::signer_lists) && - !params[jss::signer_lists].isBool() && context.apiVersion > 1) + !params[jss::signer_lists].isBool() && context.apiVersion > 1u) { RPC::inject_error(rpcINVALID_PARAMS, result); return result; diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index 7d4233bfaeb..02e5bf914ee 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -58,7 +58,7 @@ parseLedgerArgs(RPC::Context& context, Json::Value const& params) Json::Value response; // if ledger_index_min or max is specified, then ledger_hash or ledger_index // should not be specified. Error out if it is - if (context.apiVersion > 1) + if (context.apiVersion > 1u) { if ((params.isMember(jss::ledger_index_min) || params.isMember(jss::ledger_index_max)) && @@ -162,7 +162,7 @@ getLedgerRange( // if ledger_index_min or ledger_index_max is out of // valid ledger range, error out. exclude -1 as // it is a valid input - if (context.apiVersion > 1) + if (context.apiVersion > 1u) { if ((ls.max > uValidatedMax && ls.max != -1) || (ls.min < uValidatedMin && ls.min != 0)) @@ -393,12 +393,12 @@ doAccountTxJson(RPC::JsonContext& context) // however, assigning any string value works. Do not allow this. // This check is for api Version 2 onwards only if (params.isMember(jss::binary) && !params[jss::binary].isBool() && - context.apiVersion > 1) + context.apiVersion > 1u) { return rpcError(rpcINVALID_PARAMS); } if (params.isMember(jss::forward) && !params[jss::forward].isBool() && - context.apiVersion > 1) + context.apiVersion > 1u) { return rpcError(rpcINVALID_PARAMS); } diff --git a/src/ripple/rpc/handlers/NoRippleCheck.cpp b/src/ripple/rpc/handlers/NoRippleCheck.cpp index c570cce83a1..900c7cff89e 100644 --- a/src/ripple/rpc/handlers/NoRippleCheck.cpp +++ b/src/ripple/rpc/handlers/NoRippleCheck.cpp @@ -87,7 +87,7 @@ doNoRippleCheck(RPC::JsonContext& context) // however, assigning any string value works. Do not allow this. // This check is for api Version 2 onwards only if (params.isMember(jss::transactions) && - !params[jss::transactions].isBool() && context.apiVersion > 1) + !params[jss::transactions].isBool() && context.apiVersion > 1u) { return rpcError(rpcINVALID_PARAMS); } From 869782c37b4c68010aebd96342cee9c5b496a6fc Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 18 Jul 2023 16:28:39 -0400 Subject: [PATCH 3/5] Empty-commit From 2b33487f3b51913bb38ccb47c5e93ffe40cd2f49 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 17 Aug 2023 15:53:29 -0400 Subject: [PATCH 4/5] change unittest + comments --- src/ripple/rpc/handlers/AccountInfo.cpp | 11 +- src/ripple/rpc/handlers/AccountTx.cpp | 15 +- src/ripple/rpc/handlers/NoRippleCheck.cpp | 11 +- src/test/rpc/AccountTx_test.cpp | 269 +++++++++++----------- src/test/rpc/NoRipple_test.cpp | 66 +++--- 5 files changed, 185 insertions(+), 187 deletions(-) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 968a4a61674..bd2184f49a3 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -134,11 +134,12 @@ doAccountInfo(RPC::JsonContext& context) result[jss::account_flags] = std::move(acctFlags); - // The document states that signer_lists is a bool, however - // assigning any string value works. Do not allow this. - // This check is for api Version 2 onwards only - if (params.isMember(jss::signer_lists) && - !params[jss::signer_lists].isBool() && context.apiVersion > 1u) + // The document[https://xrpl.org/account_info.html#account_info] states + // that signer_lists is a bool, however assigning any string value + // works. Do not allow this. This check is for api Version 2 onwards + // only + if (context.apiVersion > 1u && params.isMember(jss::signer_lists) && + !params[jss::signer_lists].isBool()) { RPC::inject_error(rpcINVALID_PARAMS, result); return result; diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index 02e5bf914ee..6a2dba01f2c 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -389,16 +389,17 @@ doAccountTxJson(RPC::JsonContext& context) AccountTxArgs args; Json::Value response; - // The document states that binary and forward params is a boolean value, - // however, assigning any string value works. Do not allow this. - // This check is for api Version 2 onwards only - if (params.isMember(jss::binary) && !params[jss::binary].isBool() && - context.apiVersion > 1u) + // The document[https://xrpl.org/account_tx.html#account_tx] states that + // binary and forward params are both boolean values, however, assigning any + // string value works. Do not allow this. This check is for api Version 2 + // onwards only + if (context.apiVersion > 1u && params.isMember(jss::binary) && + !params[jss::binary].isBool()) { return rpcError(rpcINVALID_PARAMS); } - if (params.isMember(jss::forward) && !params[jss::forward].isBool() && - context.apiVersion > 1u) + if (context.apiVersion > 1u && params.isMember(jss::forward) && + !params[jss::forward].isBool()) { return rpcError(rpcINVALID_PARAMS); } diff --git a/src/ripple/rpc/handlers/NoRippleCheck.cpp b/src/ripple/rpc/handlers/NoRippleCheck.cpp index 900c7cff89e..1942372f3e3 100644 --- a/src/ripple/rpc/handlers/NoRippleCheck.cpp +++ b/src/ripple/rpc/handlers/NoRippleCheck.cpp @@ -83,11 +83,12 @@ doNoRippleCheck(RPC::JsonContext& context) if (params.isMember(jss::transactions)) transactions = params["transactions"].asBool(); - // The document states that transactions params is a boolean value, - // however, assigning any string value works. Do not allow this. - // This check is for api Version 2 onwards only - if (params.isMember(jss::transactions) && - !params[jss::transactions].isBool() && context.apiVersion > 1u) + // The document[https://xrpl.org/noripple_check.html#noripple_check] states + // that transactions params is a boolean value, however, assigning any + // string value works. Do not allow this. This check is for api Version 2 + // onwards only + if (context.apiVersion > 1u && params.isMember(jss::transactions) && + !params[jss::transactions].isBool()) { return rpcError(rpcINVALID_PARAMS); } diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 8c6adb7f139..cbfc4aeba6a 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -145,197 +145,196 @@ class AccountTx_test : public beast::unit_test::suite Json::Value jParms; jParms[jss::api_version] = apiVersion; - if (apiVersion < 2) - { - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(jParms)), - rpcINVALID_PARAMS)); + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(jParms)), + rpcINVALID_PARAMS)); - jParms[jss::account] = "0xDEADBEEF"; + jParms[jss::account] = "0xDEADBEEF"; - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(jParms)), - rpcACT_MALFORMED)); - - jParms[jss::account] = A1.human(); - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(jParms)))); + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(jParms)), + rpcACT_MALFORMED)); - // Ledger min/max index - { - Json::Value p{jParms}; - p[jss::ledger_index_min] = -1; - p[jss::ledger_index_max] = -1; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + jParms[jss::account] = A1.human(); + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(jParms)))); - p[jss::ledger_index_min] = 0; - p[jss::ledger_index_max] = 100; + // Ledger min/max index + { + Json::Value p{jParms}; + p[jss::ledger_index_min] = -1; + p[jss::ledger_index_max] = -1; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); + + p[jss::ledger_index_min] = 0; + p[jss::ledger_index_max] = 100; + if (apiVersion < 2u) BEAST_EXPECT( hasTxs(env.rpc("json", "account_tx", to_string(p)))); + else + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + rpcLGR_IDX_MALFORMED)); - p[jss::ledger_index_min] = 1; - p[jss::ledger_index_max] = 2; + p[jss::ledger_index_min] = 1; + p[jss::ledger_index_max] = 2; + if (apiVersion < 2u) BEAST_EXPECT( noTxs(env.rpc("json", "account_tx", to_string(p)))); - - p[jss::ledger_index_min] = 2; - p[jss::ledger_index_max] = 1; + else BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), - (RPC::apiMaximumSupportedVersion == 1 - ? rpcLGR_IDXS_INVALID - : rpcINVALID_LGR_RANGE))); - } + rpcLGR_IDX_MALFORMED)); - // Ledger index min only - { - Json::Value p{jParms}; - p[jss::ledger_index_min] = -1; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + p[jss::ledger_index_min] = 2; + p[jss::ledger_index_max] = 1; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + (apiVersion == 1 ? rpcLGR_IDXS_INVALID + : rpcINVALID_LGR_RANGE))); + } + // Ledger index min only + { + Json::Value p{jParms}; + p[jss::ledger_index_min] = -1; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); - p[jss::ledger_index_min] = 1; + p[jss::ledger_index_min] = 1; + if (apiVersion < 2u) + { BEAST_EXPECT( hasTxs(env.rpc("json", "account_tx", to_string(p)))); - - p[jss::ledger_index_min] = env.current()->info().seq; + } + else + { BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), - (RPC::apiMaximumSupportedVersion == 1 - ? rpcLGR_IDXS_INVALID - : rpcINVALID_LGR_RANGE))); + rpcLGR_IDX_MALFORMED)); } - // Ledger index max only - { - Json::Value p{jParms}; - p[jss::ledger_index_max] = -1; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + p[jss::ledger_index_min] = env.current()->info().seq; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + (apiVersion == 1 ? rpcLGR_IDXS_INVALID + : rpcINVALID_LGR_RANGE))); + } - p[jss::ledger_index_max] = env.current()->info().seq; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + // Ledger index max only + { + Json::Value p{jParms}; + p[jss::ledger_index_max] = -1; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); - p[jss::ledger_index_max] = 3; + p[jss::ledger_index_max] = env.current()->info().seq; + if (apiVersion < 2u) BEAST_EXPECT( hasTxs(env.rpc("json", "account_tx", to_string(p)))); + else + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + rpcLGR_IDX_MALFORMED)); - p[jss::ledger_index_max] = env.closed()->info().seq; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + p[jss::ledger_index_max] = 3; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); - p[jss::ledger_index_max] = env.closed()->info().seq - 1; - BEAST_EXPECT( - noTxs(env.rpc("json", "account_tx", to_string(p)))); - } + p[jss::ledger_index_max] = env.closed()->info().seq; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); - // Ledger Sequence - { - Json::Value p{jParms}; + p[jss::ledger_index_max] = env.closed()->info().seq - 1; + BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); + } - p[jss::ledger_index] = env.closed()->info().seq; - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + // Ledger Sequence + { + Json::Value p{jParms}; - p[jss::ledger_index] = env.closed()->info().seq - 1; - BEAST_EXPECT( - noTxs(env.rpc("json", "account_tx", to_string(p)))); + p[jss::ledger_index] = env.closed()->info().seq; + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); - p[jss::ledger_index] = env.current()->info().seq; - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcLGR_NOT_VALIDATED)); + p[jss::ledger_index] = env.closed()->info().seq - 1; + BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); - p[jss::ledger_index] = env.current()->info().seq + 1; - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcLGR_NOT_FOUND)); - } + p[jss::ledger_index] = env.current()->info().seq; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), + rpcLGR_NOT_VALIDATED)); - // Ledger Hash - { - Json::Value p{jParms}; + p[jss::ledger_index] = env.current()->info().seq + 1; + BEAST_EXPECT(isErr( + env.rpc("json", "account_tx", to_string(p)), rpcLGR_NOT_FOUND)); + } - p[jss::ledger_hash] = to_string(env.closed()->info().hash); - BEAST_EXPECT( - hasTxs(env.rpc("json", "account_tx", to_string(p)))); + // Ledger Hash + { + Json::Value p{jParms}; - p[jss::ledger_hash] = - to_string(env.closed()->info().parentHash); - BEAST_EXPECT( - noTxs(env.rpc("json", "account_tx", to_string(p)))); - } + p[jss::ledger_hash] = to_string(env.closed()->info().hash); + BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); + + p[jss::ledger_hash] = to_string(env.closed()->info().parentHash); + BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); } - else + + // Ledger index max/min/index all specified + // ERRORS out with invalid Parenthesis { - // Ledger index max/min/index all specified - // ERRORS out with invalid Parenthesis - { - jParms[jss::account] = "0xDEADBEEF"; - jParms[jss::account] = A1.human(); - Json::Value p{jParms}; + jParms[jss::account] = "0xDEADBEEF"; + jParms[jss::account] = A1.human(); + Json::Value p{jParms}; - p[jss::ledger_index_max] = -1; - p[jss::ledger_index_min] = -1; - p[jss::ledger_index] = -1; + p[jss::ledger_index_max] = -1; + p[jss::ledger_index_min] = -1; + p[jss::ledger_index] = -1; + if (apiVersion < 2u) + BEAST_EXPECT( + hasTxs(env.rpc("json", "account_tx", to_string(p)))); + else BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), rpcINVALID_PARAMS)); - } - - // Ledger index min/max only - { - Json::Value p{jParms}; - p[jss::ledger_index_max] = 100; - p[jss::ledger_index_min] = 0; - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcLGR_IDX_MALFORMED)); + } - p[jss::ledger_index_max] = -1; - p[jss::ledger_index_min] = -1; + // Ledger index max only + { + Json::Value p{jParms}; + p[jss::ledger_index_max] = env.current()->info().seq; + if (apiVersion < 2u) BEAST_EXPECT( hasTxs(env.rpc("json", "account_tx", to_string(p)))); - - p[jss::ledger_index_min] = 2; - p[jss::ledger_index_max] = 1; - BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcINVALID_LGR_RANGE)); - } - - // Ledger index max only - { - Json::Value p{jParms}; - p[jss::ledger_index_max] = env.current()->info().seq; + else BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), rpcLGR_IDX_MALFORMED)); - } - // test binary and forward for bool/non bool values + } + // test binary and forward for bool/non bool values + { + Json::Value p{jParms}; + p[jss::binary] = "asdf"; + if (apiVersion < 2u) { - Json::Value p{jParms}; - p[jss::binary] = "asdf"; + Json::Value result{env.rpc("json", "account_tx", to_string(p))}; + BEAST_EXPECT(result[jss::result][jss::status] == "success"); + } + else BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), rpcINVALID_PARAMS)); - p[jss::binary] = true; - Json::Value result{env.rpc("json", "account_tx", to_string(p))}; - BEAST_EXPECT(result[jss::result][jss::status] == "success"); + p[jss::binary] = true; + Json::Value result{env.rpc("json", "account_tx", to_string(p))}; + BEAST_EXPECT(result[jss::result][jss::status] == "success"); - p[jss::forward] = "true"; + p[jss::forward] = "true"; + if (apiVersion < 2u) + BEAST_EXPECT(result[jss::result][jss::status] == "success"); + else BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), rpcINVALID_PARAMS)); - p[jss::forward] = false; - result = env.rpc("json", "account_tx", to_string(p)); - BEAST_EXPECT(result[jss::result][jss::status] == "success"); - } + p[jss::forward] = false; + result = env.rpc("json", "account_tx", to_string(p)); + BEAST_EXPECT(result[jss::result][jss::status] == "success"); } } diff --git a/src/test/rpc/NoRipple_test.cpp b/src/test/rpc/NoRipple_test.cpp index f9e2b517a0d..3c58e90558c 100644 --- a/src/test/rpc/NoRipple_test.cpp +++ b/src/test/rpc/NoRipple_test.cpp @@ -229,46 +229,38 @@ class NoRipple_test : public beast::unit_test::suite Json::Value params; params[jss::api_version] = apiVersion; - if (params[jss::api_version] < 2) { - { - params[jss::account] = gw.human(); - params[jss::peer] = alice.human(); + params[jss::account] = gw.human(); + params[jss::peer] = alice.human(); - auto lines = - env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == true); - } - { - params[jss::account] = alice.human(); - params[jss::peer] = gw.human(); + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == true); + } + { + params[jss::account] = alice.human(); + params[jss::peer] = gw.human(); - auto lines = - env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple].asBool() == true); - } - { - params[jss::account] = gw.human(); - params[jss::peer] = bob.human(); + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == true); + } + { + params[jss::account] = gw.human(); + params[jss::peer] = bob.human(); - auto lines = - env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple].asBool() == false); - } - { - params[jss::account] = bob.human(); - params[jss::peer] = gw.human(); + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple].asBool() == false); + } + { + params[jss::account] = bob.human(); + params[jss::peer] = gw.human(); - auto lines = - env.rpc("json", "account_lines", to_string(params)); - auto const& line0 = lines[jss::result][jss::lines][0u]; - BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == false); - } + auto lines = env.rpc("json", "account_lines", to_string(params)); + auto const& line0 = lines[jss::result][jss::lines][0u]; + BEAST_EXPECT(line0[jss::no_ripple_peer].asBool() == false); } - else { // test for transactions { @@ -278,7 +270,11 @@ class NoRipple_test : public beast::unit_test::suite auto lines = env.rpc("json", "noripple_check", to_string(params)); - BEAST_EXPECT(lines[jss::result][jss::error] == "invalidParams"); + if (apiVersion < 2u) + BEAST_EXPECT(lines[jss::result][jss::status] == "success"); + else + BEAST_EXPECT( + lines[jss::result][jss::error] == "invalidParams"); } } } From a790d15fd0a5a0da76e6b2759b4088618fd65dfe Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 17 Aug 2023 15:55:46 -0400 Subject: [PATCH 5/5] fix --- src/test/rpc/AccountTx_test.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index cbfc4aeba6a..b1bd5600b20 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -200,16 +200,12 @@ class AccountTx_test : public beast::unit_test::suite p[jss::ledger_index_min] = 1; if (apiVersion < 2u) - { BEAST_EXPECT( hasTxs(env.rpc("json", "account_tx", to_string(p)))); - } else - { BEAST_EXPECT(isErr( env.rpc("json", "account_tx", to_string(p)), rpcLGR_IDX_MALFORMED)); - } p[jss::ledger_index_min] = env.current()->info().seq; BEAST_EXPECT(isErr(