Skip to content
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

Unit tests to recreate invalid index logic error #5242

Merged
merged 4 commits into from
Jan 23, 2025

Conversation

ximinez
Copy link
Collaborator

@ximinez ximinez commented Jan 10, 2025

High Level Overview of Change

Add unit tests and extra checks to reproduce and check that the caching issue fixed in version 2.3.0 is resolved and does not recur.

Context of Change

https://dev.to/ripplexdev/november-25-xrpl-bug-current-status-and-whats-next-b61

The tests were not released with the fix because it makes it obvious how to exploit the issue, which would give bad actors too much information.

Type of Change

  • Tests (you added tests for code that already exists, or your new feature included in this PR)

Test Plan

Only changes unit tests and an assert, so as long as tests pass, all is well.

Future Tasks

  • Maybe add more test cases covering more transaction types the accept object IDs.
  • Developers adding or modifying transactions that accept object IDs should consider adding test cases that exercise this issue, either with their new tests or in this test function.

@ximinez ximinez added Bug Tech Debt Non-urgent improvements Perf impact not expected Change is not expected to improve nor harm performance. labels Jan 10, 2025
@ximinez ximinez added this to the 2.4.0 (2025) milestone Jan 10, 2025
@ximinez ximinez requested a review from Bronek January 10, 2025 18:02
ximinez added a commit that referenced this pull request Jan 10, 2025
* One hits the global cache, one does not.
* Also some extra checking.

Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
@ximinez ximinez force-pushed the ximinez/objectid_tests branch from dda3887 to 95b80a7 Compare January 10, 2025 18:04
* One hits the global cache, one does not.
* Also some extra checking.

Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
@ximinez ximinez force-pushed the ximinez/objectid_tests branch from 95b80a7 to aef823e Compare January 10, 2025 18:07
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.0%. Comparing base (e1e67b2) to head (9157951).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5242   +/-   ##
=======================================
  Coverage     78.0%   78.0%           
=======================================
  Files          789     789           
  Lines        66951   66953    +2     
  Branches      8111    8106    -5     
=======================================
+ Hits         52211   52226   +15     
+ Misses       14740   14727   -13     
Files with missing lines Coverage Δ
src/xrpld/ledger/detail/CachedView.cpp 100.0% <100.0%> (+5.6%) ⬆️

... and 6 files with indirect coverage changes

Impacted file tree graph

Comment on lines 267 to 282
auto index = [&](auto account) {
Json::Value req(Json::objectValue);
req[jss::account] = account;
auto const resp = env.rpc("json", "account_info", to_string(req));
BEAST_EXPECT(
resp.isMember(jss::result) && resp[jss::result].isObject());
auto const& result = resp[jss::result];
BEAST_EXPECT(
result.isMember(jss::account_data) &&
result[jss::account_data].isObject());
auto const& ad = result[jss::account_data];
BEAST_EXPECT(ad.isMember(jss::index) && ad[jss::index].isString());
uint256 index;
BEAST_EXPECT(index.parseHex(ad[jss::index].asString()));
return index;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be greatly simplified by using keylet::account(alice)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent idea. That will make this whole lambda unnecessary. I added the necessary proposed changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be greatly simplified by using keylet::account(alice)

Thanks @mvadari. That was a great observation and suggestion.

src/test/app/Regression_test.cpp Outdated Show resolved Hide resolved
src/test/app/Regression_test.cpp Outdated Show resolved Hide resolved
src/test/app/Regression_test.cpp Show resolved Hide resolved
Comment on lines 267 to 282
auto index = [&](auto account) {
Json::Value req(Json::objectValue);
req[jss::account] = account;
auto const resp = env.rpc("json", "account_info", to_string(req));
BEAST_EXPECT(
resp.isMember(jss::result) && resp[jss::result].isObject());
auto const& result = resp[jss::result];
BEAST_EXPECT(
result.isMember(jss::account_data) &&
result[jss::account_data].isObject());
auto const& ad = result[jss::account_data];
BEAST_EXPECT(ad.isMember(jss::index) && ad[jss::index].isString());
uint256 index;
BEAST_EXPECT(index.parseHex(ad[jss::index].asString()));
return index;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent idea. That will make this whole lambda unnecessary. I added the necessary proposed changes.

Copy link
Collaborator

@Bronek Bronek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice !

@ximinez ximinez requested a review from mvadari January 16, 2025 20:16
@ximinez ximinez added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Jan 23, 2025
@ximinez
Copy link
Collaborator Author

ximinez commented Jan 23, 2025

Ready to merge once CI finishes. The commit message from the first commit will be sufficient for the merge.

@ximinez ximinez merged commit 870882f into develop Jan 23, 2025
23 checks passed
@ximinez ximinez deleted the ximinez/objectid_tests branch January 23, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Perf impact not expected Change is not expected to improve nor harm performance. Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. Tech Debt Non-urgent improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants