Promote API version 2 to supported (#4803)

* Promote API version 2 to supported

* Switch command line to API version 1

* Fix LedgerRequestRPC test

* Remove obsolete tx_account method

This method is not implemented, the only parts which are removed are related to command-line parsing

* Fix RPCCall test

* Reduce diff size, small test improvements

* Minor fixes

* Support for the mold linker

* [fold] handle case where both mold and gold are installed

* [fold] Use first non-default linker

* Fix TransactionEntry_test

* Fix AccountTx_test

---------

Co-authored-by: seelabs <scott.determan@yahoo.com>
This commit is contained in:
Bronek Kozicki
2023-11-13 23:04:27 +00:00
committed by Manoj Doshi
parent 4dff203787
commit 96c926c71e
9 changed files with 347 additions and 643 deletions

View File

@@ -91,6 +91,7 @@ createHTTPPost(
class RPCParser
{
private:
unsigned const apiVersion_;
beast::Journal const j_;
// TODO New routine for parsing ledger parameters, other routines should
@@ -321,8 +322,7 @@ private:
if (uLedgerMax != -1 && uLedgerMax < uLedgerMin)
{
// The command line always follows apiMaximumSupportedVersion
if (RPC::apiMaximumSupportedVersion == 1)
if (apiVersion_ == 1)
return rpcError(rpcLGR_IDXS_INVALID);
return rpcError(rpcNOT_SYNCED);
}
@@ -340,76 +340,6 @@ private:
return jvRequest;
}
// tx_account accountID [ledger_min [ledger_max [limit]]]] [binary] [count]
// [forward]
Json::Value
parseTxAccount(Json::Value const& jvParams)
{
Json::Value jvRequest(Json::objectValue);
unsigned int iParams = jvParams.size();
auto const account = parseBase58<AccountID>(jvParams[0u].asString());
if (!account)
return rpcError(rpcACT_MALFORMED);
jvRequest[jss::account] = toBase58(*account);
bool bDone = false;
while (!bDone && iParams >= 2)
{
if (jvParams[iParams - 1].asString() == jss::binary)
{
jvRequest[jss::binary] = true;
--iParams;
}
else if (jvParams[iParams - 1].asString() == jss::count)
{
jvRequest[jss::count] = true;
--iParams;
}
else if (jvParams[iParams - 1].asString() == jss::forward)
{
jvRequest[jss::forward] = true;
--iParams;
}
else
{
bDone = true;
}
}
if (1 == iParams)
{
}
else if (2 == iParams)
{
if (!jvParseLedger(jvRequest, jvParams[1u].asString()))
return jvRequest;
}
else
{
std::int64_t uLedgerMin = jvParams[1u].asInt();
std::int64_t uLedgerMax = jvParams[2u].asInt();
if (uLedgerMax != -1 && uLedgerMax < uLedgerMin)
{
// The command line always follows apiMaximumSupportedVersion
if (RPC::apiMaximumSupportedVersion == 1)
return rpcError(rpcLGR_IDXS_INVALID);
return rpcError(rpcNOT_SYNCED);
}
jvRequest[jss::ledger_index_min] = jvParams[1u].asInt();
jvRequest[jss::ledger_index_max] = jvParams[2u].asInt();
if (iParams >= 4)
jvRequest[jss::limit] = jvParams[3u].asInt();
}
return jvRequest;
}
// book_offers <taker_pays> <taker_gets> [<taker> [<ledger> [<limit>
// [<proof> [<marker>]]]]] limit: 0 = no limit proof: 0 or 1
//
@@ -1221,7 +1151,8 @@ private:
public:
//--------------------------------------------------------------------------
explicit RPCParser(beast::Journal j) : j_(j)
explicit RPCParser(unsigned apiVersion, beast::Journal j)
: apiVersion_(apiVersion), j_(j)
{
}
@@ -1317,7 +1248,6 @@ public:
{"submit_multisigned", &RPCParser::parseSubmitMultiSigned, 1, 1},
{"transaction_entry", &RPCParser::parseTransactionEntry, 2, 2},
{"tx", &RPCParser::parseTx, 1, 4},
{"tx_account", &RPCParser::parseTxAccount, 1, 7},
{"tx_history", &RPCParser::parseTxHistory, 1, 1},
{"unl_list", &RPCParser::parseAsIs, 0, 0},
{"validation_create", &RPCParser::parseValidationCreate, 0, 1},
@@ -1481,7 +1411,7 @@ rpcCmdToJson(
{
Json::Value jvRequest(Json::objectValue);
RPCParser rpParser(j);
RPCParser rpParser(apiVersion, j);
Json::Value jvRpcParams(Json::arrayValue);
for (int i = 1; i != args.size(); i++)
@@ -1673,7 +1603,7 @@ fromCommandLine(
Logs& logs)
{
auto const result =
rpcClient(vCmd, config, logs, RPC::apiMaximumSupportedVersion);
rpcClient(vCmd, config, logs, RPC::apiCommandLineVersion);
std::cout << result.second.toStyledString();

View File

@@ -234,8 +234,9 @@ extern beast::SemanticVersion const lastVersion;
constexpr unsigned int apiInvalidVersion = 0;
constexpr unsigned int apiVersionIfUnspecified = 1;
constexpr unsigned int apiMinimumSupportedVersion = 1;
constexpr unsigned int apiMaximumSupportedVersion = 1;
constexpr unsigned int apiBetaVersion = 2;
constexpr unsigned int apiMaximumSupportedVersion = 2;
constexpr unsigned int apiCommandLineVersion = 1; // TODO Bump to 2 later
constexpr unsigned int apiBetaVersion = 3;
constexpr unsigned int apiMaximumValidVersion = apiBetaVersion;
static_assert(apiMinimumSupportedVersion >= apiVersionIfUnspecified);

View File

@@ -279,6 +279,17 @@ public:
The command is examined and used to build
the correct JSON as per the arguments.
*/
template <class... Args>
Json::Value
rpc(unsigned apiVersion,
std::unordered_map<std::string, std::string> const& headers,
std::string const& cmd,
Args&&... args);
template <class... Args>
Json::Value
rpc(unsigned apiVersion, std::string const& cmd, Args&&... args);
template <class... Args>
Json::Value
rpc(std::unordered_map<std::string, std::string> const& headers,
@@ -655,6 +666,7 @@ protected:
Json::Value
do_rpc(
unsigned apiVersion,
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers = {});
@@ -698,12 +710,39 @@ protected:
template <class... Args>
Json::Value
Env::rpc(
unsigned apiVersion,
std::unordered_map<std::string, std::string> const& headers,
std::string const& cmd,
Args&&... args)
{
return do_rpc(
std::vector<std::string>{cmd, std::forward<Args>(args)...}, headers);
apiVersion,
std::vector<std::string>{cmd, std::forward<Args>(args)...},
headers);
}
template <class... Args>
Json::Value
Env::rpc(unsigned apiVersion, std::string const& cmd, Args&&... args)
{
return rpc(
apiVersion,
std::unordered_map<std::string, std::string>(),
cmd,
std::forward<Args>(args)...);
}
template <class... Args>
Json::Value
Env::rpc(
std::unordered_map<std::string, std::string> const& headers,
std::string const& cmd,
Args&&... args)
{
return do_rpc(
RPC::apiCommandLineVersion,
std::vector<std::string>{cmd, std::forward<Args>(args)...},
headers);
}
template <class... Args>
@@ -743,7 +782,7 @@ void
forAllApiVersions(VersionedTestCallable auto... testCallable)
{
for (auto testVersion = RPC::apiMinimumSupportedVersion;
testVersion <= RPC::apiBetaVersion;
testVersion <= RPC::apiMaximumValidVersion;
++testVersion)
{
(..., testCallable(testVersion));

View File

@@ -460,15 +460,11 @@ Env::st(JTx const& jt)
Json::Value
Env::do_rpc(
unsigned apiVersion,
std::vector<std::string> const& args,
std::unordered_map<std::string, std::string> const& headers)
{
return rpcClient(
args,
app().config(),
app().logs(),
RPC::apiMaximumSupportedVersion,
headers)
return rpcClient(args, app().config(), app().logs(), apiVersion, headers)
.second;
}

View File

@@ -67,7 +67,7 @@ Json::Value
cmdToJSONRPC(
std::vector<std::string> const& args,
beast::Journal j,
unsigned int apiVersion = RPC::apiMaximumSupportedVersion);
unsigned int apiVersion);
} // namespace jtx
} // namespace test

View File

@@ -137,6 +137,7 @@ class AccountTx_test : public beast::unit_test::suite
j[jss::result][jss::transactions][1u][jss::tx]
[jss::DeliverMax]);
case 2:
case 3:
if (j.isMember(jss::result) &&
(j[jss::result][jss::status] == "success") &&
(j[jss::result][jss::transactions].size() == 2) &&
@@ -198,20 +199,22 @@ class AccountTx_test : public beast::unit_test::suite
rpcACT_MALFORMED));
jParms[jss::account] = A1.human();
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(jParms))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(jParms))));
// 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))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "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))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
else
BEAST_EXPECT(isErr(
env.rpc("json", "account_tx", to_string(p)),
@@ -238,12 +241,13 @@ class AccountTx_test : public beast::unit_test::suite
{
Json::Value p{jParms};
p[jss::ledger_index_min] = -1;
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
p[jss::ledger_index_min] = 1;
if (apiVersion < 2u)
BEAST_EXPECT(
hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
else
BEAST_EXPECT(isErr(
env.rpc("json", "account_tx", to_string(p)),
@@ -260,22 +264,25 @@ class AccountTx_test : public beast::unit_test::suite
{
Json::Value p{jParms};
p[jss::ledger_index_max] = -1;
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
p[jss::ledger_index_max] = env.current()->info().seq;
if (apiVersion < 2u)
BEAST_EXPECT(
hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "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] = 3;
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "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))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "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))));
@@ -286,7 +293,8 @@ class AccountTx_test : public beast::unit_test::suite
Json::Value p{jParms};
p[jss::ledger_index] = env.closed()->info().seq;
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
p[jss::ledger_index] = env.closed()->info().seq - 1;
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p))));
@@ -306,7 +314,8 @@ class AccountTx_test : public beast::unit_test::suite
Json::Value p{jParms};
p[jss::ledger_hash] = to_string(env.closed()->info().hash);
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "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))));
@@ -324,8 +333,8 @@ class AccountTx_test : public beast::unit_test::suite
p[jss::ledger_index] = -1;
if (apiVersion < 2u)
BEAST_EXPECT(
hasTxs(env.rpc("json", "account_tx", to_string(p))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
else
BEAST_EXPECT(isErr(
env.rpc("json", "account_tx", to_string(p)),
@@ -337,8 +346,8 @@ class AccountTx_test : public beast::unit_test::suite
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))));
BEAST_EXPECT(hasTxs(
env.rpc(apiVersion, "json", "account_tx", to_string(p))));
else
BEAST_EXPECT(isErr(
env.rpc("json", "account_tx", to_string(p)),

View File

@@ -24,6 +24,8 @@
#include <ripple/rpc/impl/RPCHelpers.h>
#include <test/jtx.h>
#include <functional>
namespace ripple {
namespace RPC {
@@ -263,7 +265,7 @@ public:
}
void
testBadInput()
testBadInput(unsigned apiVersion)
{
using namespace test::jtx;
Env env{*this};
@@ -287,9 +289,9 @@ public:
// the purpose in this test is to force the ledger expiration/out of
// date check to trigger
env.timeKeeper().adjustCloseTime(weeks{3});
result = env.rpc("ledger_request", "1")[jss::result];
result = env.rpc(apiVersion, "ledger_request", "1")[jss::result];
BEAST_EXPECT(result[jss::status] == "error");
if (RPC::apiMaximumSupportedVersion == 1)
if (apiVersion == 1)
{
BEAST_EXPECT(result[jss::error] == "noCurrent");
BEAST_EXPECT(
@@ -357,7 +359,8 @@ public:
{
testLedgerRequest();
testEvolution();
testBadInput();
test::jtx::forAllApiVersions(
std::bind_front(&LedgerRequestRPC_test::testBadInput, this));
testMoreThan256Closed();
testNonAdmin();
}

File diff suppressed because it is too large Load Diff

View File

@@ -230,22 +230,20 @@ class TransactionEntry_test : public beast::unit_test::suite
}
// Use the command line form with the index.
if (apiVersion == RPC::apiMaximumSupportedVersion)
{
Json::Value const clIndex{env.rpc(
"transaction_entry", txhash, std::to_string(index))};
BEAST_EXPECT(clIndex["result"] == resIndex);
}
Json::Value const clIndex{env.rpc(
apiVersion,
"transaction_entry",
txhash,
std::to_string(index))};
BEAST_EXPECT(clIndex["result"] == resIndex);
// Use the command line form with the ledger_hash.
if (apiVersion == RPC::apiMaximumSupportedVersion)
{
Json::Value const clHash{env.rpc(
"transaction_entry",
txhash,
resIndex[jss::ledger_hash].asString())};
BEAST_EXPECT(clHash["result"] == resIndex);
}
Json::Value const clHash{env.rpc(
apiVersion,
"transaction_entry",
txhash,
resIndex[jss::ledger_hash].asString())};
BEAST_EXPECT(clHash["result"] == resIndex);
};
Account A1{"A1"};