-
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 3 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 |
---|---|---|
|
@@ -65,18 +65,22 @@ fromNetwork( | |
std::unordered_map<std::string, std::string> headers = {}); | ||
} // namespace RPCCall | ||
|
||
/** Given a rippled command line, return the corresponding JSON. | ||
*/ | ||
Json::Value | ||
cmdLineToJSONRPC(std::vector<std::string> const& args, beast::Journal j); | ||
rpcCmdToJson( | ||
std::vector<std::string> const& args, | ||
Json::Value& retParams, | ||
beast::Journal j, | ||
unsigned int apiVersion); | ||
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. Maybe not for this PR, but we should consider making apiVersion either an enum type with one enum per API version or maybe a strongly-typed int (int with a tag, like we do with base_uint). |
||
|
||
/** Internal invocation of RPC client. | ||
* Used by both rippled command line as well as rippled unit tests | ||
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. I like this comment ! 👍 |
||
*/ | ||
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 = {}); | ||
|
||
} // namespace ripple | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1472,11 +1472,12 @@ struct RPCCallImp | |
//------------------------------------------------------------------------------ | ||
|
||
// Used internally by rpcClient. | ||
static Json::Value | ||
rpcCmdLineToJson( | ||
Json::Value | ||
rpcCmdToJson( | ||
std::vector<std::string> const& args, | ||
Json::Value& retParams, | ||
beast::Journal j) | ||
beast::Journal j, | ||
unsigned int apiVersion) | ||
{ | ||
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, logs.journal("RPCParser"), apiVersion); | ||
|
||
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.
Usually we make
journal
the last parameter.