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

Increase test coverage #4971

Merged
merged 29 commits into from
Apr 18, 2024
Merged

Increase test coverage #4971

merged 29 commits into from
Apr 18, 2024

Conversation

thejohnfreeman
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

Thanks for extending AMM code coverage!
I left a few minor comments.
I still need to go over LCOV_EXCL to check whether it can be covered or not. I wanted to provide the feedback on the unit-tests sooner.

src/test/app/AMMWithdraw_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMMWithdraw_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/jtx/AMM.h Outdated Show resolved Hide resolved
src/test/jtx/AMM.h Show resolved Hide resolved
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

Added LCOV_EXCL looks correct.

@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.9%. Comparing base (aae4383) to head (20e69b2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #4971     +/-   ##
=========================================
+ Coverage     70.8%   70.9%   +0.1%     
=========================================
  Files          796     796             
  Lines        66785   66727     -58     
  Branches     11034   10978     -56     
=========================================
+ Hits         47301   47341     +40     
+ Misses       19484   19386     -98     
Files Coverage Δ
src/ripple/app/misc/impl/AMMUtils.cpp 99.2% <ø> (+17.5%) ⬆️
src/ripple/app/paths/AMMOffer.h 83.3% <ø> (ø)
src/ripple/app/paths/impl/AMMOffer.cpp 81.8% <ø> (+2.9%) ⬆️
src/ripple/app/tx/impl/AMMDeposit.cpp 95.1% <ø> (+8.2%) ⬆️
src/ripple/app/tx/impl/AMMWithdraw.cpp 90.4% <ø> (+6.1%) ⬆️
src/ripple/protocol/STIssue.h 80.0% <ø> (+5.0%) ⬆️
src/ripple/protocol/impl/STIssue.cpp 93.5% <ø> (+10.7%) ⬆️

... and 10 files with indirect coverage changes

Impacted file tree graph

@thejohnfreeman
Copy link
Collaborator Author

@gregtatcam can you help me try to convert the last tests, in 43a251c, to use BidArg? I don't understand why my attempt fails.

@gregtatcam
Copy link
Collaborator

@gregtatcam can you help me try to convert the last tests, in 43a251c, to use BidArg? I don't understand why my attempt fails.

Will do

@gregtatcam
Copy link
Collaborator

@gregtatcam can you help me try to convert the last tests, in 43a251c, to use BidArg? I don't understand why my attempt fails.

@thejohnfreeman submit is missing in AMM::bid(BidArg const& arg). It just returns Json::Value.

@thejohnfreeman
Copy link
Collaborator Author

@gregtatcam Right, that's why the return value is passed to env, e.g. env(bid({ ... }));, to apply the transaction. I think this more closely follows the original design of these tests: build a JSON transaction object, then apply it like env(tx), with optional extras like msig, seq, and ter. This way, tests can intercept the JSON transaction before it is applied, to "disturb" it in some way and test that the disturbance leads to an expected error. If bid(...) applies the transaction with no chance to intercept, then that opportunity is lost.

@gregtatcam
Copy link
Collaborator

@gregtatcam Right, that's why the return value is passed to env, e.g. env(bid({ ... }));, to apply the transaction. I think this more closely follows the original design of these tests: build a JSON transaction object, then apply it like env(tx), with optional extras like msig, seq, and ter. This way, tests can intercept the JSON transaction before it is applied, to "disturb" it in some way and test that the disturbance leads to an expected error. If bid(...) applies the transaction with no chance to intercept, then that opportunity is lost.

Right, sorry. But then all tests would have to be changed. I'm doing a few things in submit as well.

@gregtatcam
Copy link
Collaborator

@gregtatcam Right, that's why the return value is passed to env, e.g. env(bid({ ... }));, to apply the transaction. I think this more closely follows the original design of these tests: build a JSON transaction object, then apply it like env(tx), with optional extras like msig, seq, and ter. This way, tests can intercept the JSON transaction before it is applied, to "disturb" it in some way and test that the disturbance leads to an expected error. If bid(...) applies the transaction with no chance to intercept, then that opportunity is lost.

Right, sorry. But then all tests would have to be changed. I'm doing a few things in submit as well.

submit calls env.close();. So if you add this after each bid then it'll work. But then again, to make this consistent deposit,withdraw,vote would have to change too. This is pretty substantial change.

@thejohnfreeman
Copy link
Collaborator Author

@gregtatcam I only changed the calls to bid() (not deposit(), withdraw(), etc.) because I had to touch them anyway to restore BidArg, and as a proof-of-concept. I don't plan to move on to the others, but I think we should take away some lessons on how to design these tests going forward. The revision of existing tests can be left for future work. "Good first issue" kind of thing.

@gregtatcam
Copy link
Collaborator

@gregtatcam I only changed the calls to bid() (not deposit(), withdraw(), etc.) because I had to touch them anyway to restore BidArg, and as a proof-of-concept. I don't plan to move on to the others, but I think we should take away some lessons on how to design these tests going forward. The revision of existing tests can be left for future work. "Good first issue" kind of thing.

Thanks. Will review today or Monday.

src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

Overall looks good.
Remaining areas to address:

  • Move AMMWithdraw_test to AMM_test. It would be great overall to be able to run tests individually like AMMWitrhdraw, AMMDeposit, etc.; but not in this PR.
  • Updated bid method changes the default behavior. I.e., env.close() is generally called after every bid but the updated tests don't always call close. Should it be added?
  • Can deposit non-frozen token comment should be updated.
  • There are two suggestions to consider for the comments update.

src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
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.

Note, if we merged https://app.codecov.io/gh/XRPLF/rippled/pull/4977 into develop before this PR, then codecov statistics would be relative to the changes (we would have merged) in #4977 , and it would be quite visible that this PR has increased overall coverage from 70.8% to 70.9%

@@ -56,9 +56,6 @@ class STIssue final : public STBase, CountedObject<STIssue>
SerializedTypeID
getSType() const override;

std::string
getText() const override;

Json::Value getJson(JsonOptions) const override;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I love how this PR also contains the removal of dead code 🥇

Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

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

👍

editing the JSON.
*/
std::shared_ptr<STTx const>
ust(JTx const& jt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider giving this a more descriptive name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mtrippled please suggest a name. I don't know what this should be named, or what "ust" stands for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unsanitized serialized transaction?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ximinez I think John wanted to update the name of this function before the merge 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Woops. @thejohnfreeman, if you (or someone else) wants to open a "trivial" PR with the name change, I'll approve and merge it.

@@ -60,9 +60,12 @@ ammHolds(
*optIssue2,
std::make_optional(std::make_pair(issue1, issue2))))
{
// This error can only be hit if the AMM is corrupted
// LCOV_EXCL_START
Copy link
Collaborator

Choose a reason for hiding this comment

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

I looked at the exclusions, and I'm OK with keeping them. I might feel differently if there were an excessive number of them, but there are relatively few and seem reasonably justified. I don't think we're in danger if we keep them.

I'm guessing we'll do another PR in the future with more exclusions. We may want to revisit some of these exclusions in that PR, but this is OK for now and also not the end of the world if we don't revisit in the future PR.

@seelabs seelabs added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Apr 17, 2024
@ximinez ximinez merged commit 24a275b into XRPLF:develop Apr 18, 2024
16 of 17 checks passed
@Bronek Bronek mentioned this pull request Apr 19, 2024
9 tasks
@thejohnfreeman thejohnfreeman deleted the amm-tests branch April 23, 2024 11:59
sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
---------

Co-authored-by: Howard Hinnant <[email protected]>
Co-authored-by: Mark Travis <[email protected]>
Co-authored-by: Bronek Kozicki <[email protected]>
Co-authored-by: Mayukha Vadari <[email protected]>
Co-authored-by: Chenna Keshava <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants