-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unit test api_version to enable api_version 2 #4785
Changes from all commits
737a89f
c15fd32
2d3d91c
e1d1c27
3e9b260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1472,10 +1472,11 @@ struct RPCCallImp | |
//------------------------------------------------------------------------------ | ||
|
||
// Used internally by rpcClient. | ||
static Json::Value | ||
rpcCmdLineToJson( | ||
Json::Value | ||
rpcCmdToJson( | ||
std::vector<std::string> const& args, | ||
Json::Value& retParams, | ||
unsigned int apiVersion, | ||
beast::Journal j) | ||
{ | ||
Json::Value jvRequest(Json::objectValue); | ||
|
@@ -1493,11 +1494,11 @@ rpcCmdLineToJson( | |
|
||
jvRequest = rpParser.parseCommand(args[0], jvRpcParams, true); | ||
|
||
auto insert_api_version = [](Json::Value& jr) { | ||
auto insert_api_version = [apiVersion](Json::Value& jr) { | ||
if (jr.isObject() && !jr.isMember(jss::error) && | ||
!jr.isMember(jss::api_version)) | ||
{ | ||
jr[jss::api_version] = RPC::apiMaximumSupportedVersion; | ||
jr[jss::api_version] = apiVersion; | ||
} | ||
}; | ||
|
||
|
@@ -1510,42 +1511,14 @@ rpcCmdLineToJson( | |
return jvRequest; | ||
} | ||
|
||
Json::Value | ||
cmdLineToJSONRPC(std::vector<std::string> const& args, beast::Journal j) | ||
{ | ||
Json::Value jv = Json::Value(Json::objectValue); | ||
auto const paramsObj = rpcCmdLineToJson(args, jv, j); | ||
|
||
// Re-use jv to return our formatted result. | ||
jv.clear(); | ||
|
||
// Allow parser to rewrite method. | ||
jv[jss::method] = paramsObj.isMember(jss::method) | ||
? paramsObj[jss::method].asString() | ||
: args[0]; | ||
|
||
// If paramsObj is not empty, put it in a [params] array. | ||
if (paramsObj.begin() != paramsObj.end()) | ||
{ | ||
auto& paramsArray = Json::setArray(jv, jss::params); | ||
paramsArray.append(paramsObj); | ||
} | ||
if (paramsObj.isMember(jss::jsonrpc)) | ||
jv[jss::jsonrpc] = paramsObj[jss::jsonrpc]; | ||
if (paramsObj.isMember(jss::ripplerpc)) | ||
jv[jss::ripplerpc] = paramsObj[jss::ripplerpc]; | ||
if (paramsObj.isMember(jss::id)) | ||
jv[jss::id] = paramsObj[jss::id]; | ||
return jv; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
|
||
std::pair<int, Json::Value> | ||
rpcClient( | ||
std::vector<std::string> const& args, | ||
Config const& config, | ||
Logs& logs, | ||
unsigned int apiVersion, | ||
std::unordered_map<std::string, std::string> const& headers) | ||
{ | ||
static_assert( | ||
|
@@ -1561,7 +1534,8 @@ rpcClient( | |
try | ||
{ | ||
Json::Value jvRpc = Json::Value(Json::objectValue); | ||
jvRequest = rpcCmdLineToJson(args, jvRpc, logs.journal("RPCParser")); | ||
jvRequest = | ||
rpcCmdToJson(args, jvRpc, apiVersion, logs.journal("RPCParser")); | ||
|
||
if (jvRequest.isMember(jss::error)) | ||
{ | ||
|
@@ -1698,7 +1672,8 @@ fromCommandLine( | |
const std::vector<std::string>& vCmd, | ||
Logs& logs) | ||
{ | ||
auto const result = rpcClient(vCmd, config, logs); | ||
auto const result = | ||
rpcClient(vCmd, config, logs, RPC::apiMaximumSupportedVersion); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, this means that as soon as we bump |
||
|
||
std::cout << result.second.toStyledString(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this comment ! 👍