-
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
Allow account_objects RPC to filter by "check" (RIPD-1589) #2356
Conversation
Jenkins Build SummaryBuilt from this commit Built at 20180203 - 00:52:48 Test Results
|
(For tracking purposes, this fixes #2350) |
src/test/rpc/AccountObjects_test.cpp
Outdated
|
||
// Verify that the non-returning types still don't return anything. | ||
// Note that, interestingly, they now return a null object rather | ||
// than an empty array. Not sure what triggers that... |
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.
This null object thing might be worth looking into
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.
Agreed. Surprised me a bit too (which is why I called it out). But I have other stuff I need to chase down before I look into this one. My inclination would be to change it so it always return an empty array. But there might be a downside for users who expect a null object to be returned in this case. I'll let you think about that. If we (conservatively) decide not to change the behavior then it's not really worth investigating...
src/test/rpc/AccountObjects_test.cpp
Outdated
[&env, &acct_objs] (Account const& acct, char const* type) | ||
{ | ||
Json::Value const resp = acct_objs (acct, type); | ||
return resp["result"]["account_objects"].isNull(); |
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.
What is the rest of the resp
onse? status
? Is there an error?
src/test/rpc/AccountObjects_test.cpp
Outdated
// Verify that the non-returning types still don't return anything. | ||
// Note that, interestingly, they now return a null object rather | ||
// than an empty array. Not sure what triggers that... | ||
BEAST_EXPECT (acct_objs_is_null (gw, jss::account)); |
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.
These are essentially jibberish, unrecognized types ?
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.
Nevermind, I see. I thought amendments
and hashes
was non sensical in the context of account_objects. So non-returning types
means there was just no results?
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 guess it's this line here:
https://github.com/ripple/rippled/blob/develop/src/ripple/rpc/impl/RPCHelpers.cpp#L100
It is probably the weird json library, which creates a null node, until you run append on it.
This is probably the "fix":
auto& jvObjects = jvResult[jss::account_objects] = Json::Value(Json::objectValue);
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.
Looks good.
I recommend making the change @sublimator suggested; you can cherry-pick bachase@8cff40e.
Thanks @bachase. Your |
src/test/rpc/AccountObjects_test.cpp
Outdated
|
||
bool const isArray = resp["result"]["account_objects"].isArray(); | ||
return isArray && (resp["result"]["account_objects"].size() == 0); | ||
}; |
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.
Suggestion: If the lambda takes a size param, it can be called from other instances in the test.
auto acct_objs_is_size =
[&env, &acct_objs](Account const& acct, char const* type, unsigned size)
{
Json::Value const resp = acct_objs(acct, type);
return resp[jss::result][jss::account_objects].isArray() &&
resp[jss::result][jss::account_objects].size() == size;
};
These instances
BEAST_EXPECT (resp["result"]["account_objects"].isArray());
BEAST_EXPECT (resp["result"]["account_objects"].size() == 1);
Can become
BEAST_EXPECT (acct_objs_is_size(gw, jss::state, 1));
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.
Most of this is over my head, but I didn't spot any problems.
src/test/rpc/AccountObjects_test.cpp
Outdated
@@ -316,10 +316,215 @@ class AccountObjects_test : public beast::unit_test::suite | |||
} | |||
} | |||
|
|||
void testObjectTypes() | |||
{ | |||
testcase ("object types"); |
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.
Looks like (elsewhere in the file) there usually isn't a space between testcase
and (
?
i.e.
testcase("object types");
{ { | ||
{ jss::account, ltACCOUNT_ROOT }, | ||
{ jss::amendments, ltAMENDMENTS }, | ||
{ jss::check, ltCHECK }, |
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.
This is just adding 1 new type (check
) and reordering a few others?
src/test/rpc/AccountObjects_test.cpp
Outdated
auto const& escrow = resp["result"]["account_objects"][0u]; | ||
BEAST_EXPECT (escrow["Account"] == gw.human()); | ||
BEAST_EXPECT (escrow["Destination"] == gw.human()); | ||
BEAST_EXPECT (escrow["Amount"].asInt() == 100'000'000); |
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.
Consider asUInt()
?
src/test/rpc/AccountObjects_test.cpp
Outdated
// Find the trustline and make sure it's the right one. | ||
Json::Value const resp = acct_objs (gw, jss::state); | ||
|
||
BEAST_EXPECT (resp["result"]["account_objects"].isArray()); |
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.
Consider using defined json fields instead.
eg. resp[jss::result][jss::account_objects]
src/test/rpc/AccountObjects_test.cpp
Outdated
} | ||
// Run up the number of directory entries so gw has two | ||
// directory nodes. | ||
for (int d = 1'000'032; d >= 1'000'000; d -= 1) |
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.
Nit: --d
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.
Left a few suggestions but not holding back. Excellent work @scottschurr 👍
f1ed64c
to
e8396a2
Compare
Thanks for the review, @miguelportilla and @intelliot. Great suggestions. I believe the most recent commit (e8396a2) addresses your comments. If you're good with it I'll mark the pull request passed. Thanks. |
e8396a2
to
ff81627
Compare
@ximinez: Here I got trained on how to handle RIPD comments and now you want me to adapt to GitHub issues too. 😉 Commit message updated. |
It never ends! |
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.
👍
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::amendments), 0)); | ||
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::directory), 0)); | ||
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::fee), 0)); | ||
BEAST_EXPECT (acct_objs_is_size (acct_objs (gw, jss::hashes), 0)); |
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.
These tests are great. I'm was going to suggest you do one more unfiltered, but it looks like testUnsteppedThenStepped
has that covered.
Merged in 88570df |
@mDuo13 found a bug in the Checks implementation (Thanks!). This fixes that particular bug. Also adds some more unit tests for
account_objects
.