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

Add RPC error checking support to unit tests #4987

Merged
merged 7 commits into from
Apr 24, 2024
Merged

Conversation

ximinez
Copy link
Collaborator

@ximinez ximinez commented Apr 12, 2024

High Level Overview of Change

Adds RPC error verification functionality to unit tests. There are two ways to specify the expected result:

  1. By RPC code and an optional detail message. If a detail message is not specified, it will be expected to match the message defined in the RPC code lookup table.
  2. By the expected error string, and an optional error_exception detail message. If the detail message is not specified, it will not be checked.

These checks are not comprehensive (for example, nothing checks the optional error_what field), but I think they are sufficient for any expected test case results.

Context of Change

PR #4887 introduced a new TER result code to indicate that an RPC request failed during transaction processing, but it does not indicate which RPC failure occurred. Inspired by a discussion on that PR, I added the ability to explicitly check the RPC result.

(Props to @ckeshava for the pre-review.)

Type of Change

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

API Impact

None.

Test Plan

There should be no observable external effects for this change. This is a developer tool to help write more and better unit tests.

Future Tasks

Now that we can distinguish RPC failures, it might be useful to add more test cases that explicitly test the various combinations of failures. (Thanks to @ckeshava again for the suggestion.]

@ximinez ximinez added the Perf impact not expected Change is not expected to improve nor harm performance. label Apr 12, 2024
@ximinez ximinez added this to the 2.2.0 (Apr 2024) milestone Apr 12, 2024
@ximinez ximinez requested review from scottschurr and ckeshava April 12, 2024 17:57
@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.0%. Comparing base (b84f7e7) to head (f0dc9af).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #4987     +/-   ##
=========================================
- Coverage     71.0%   71.0%   -0.0%     
=========================================
  Files          796     796             
  Lines        66727   66727             
  Branches     10978   10973      -5     
=========================================
- Hits         47347   47346      -1     
- Misses       19380   19381      +1     

see 2 files with indirect coverage changes

Impacted file tree graph

@@ -748,8 +748,12 @@ class Env_test : public beast::unit_test::suite
params[jss::fee_mult_max] = 1;
params[jss::fee_div_max] = 2;
// RPC errors result in telENV_RPC_FAILED
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel this comment is more appropriate in src/test/jtx/rpc.h. Specifically, in the operator() of the rpc class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in f58d42d

src/test/jtx/rpc.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

This looks like a good change and the implementation is pretty clever. I spotted a few changes that might be improvements, but feel free to push back on any of them. I put all of my suggestions into a commit that you can see here: https://github.com/scottschurr/rippled/commits/ed-jtx_rpc/ You probably don't want to take all of my suggestions, but the commit will at least show you what I was thinking.

src/test/jtx/Env.h Outdated Show resolved Hide resolved
src/test/app/TxQ_test.cpp Outdated Show resolved Hide resolved
src/test/jtx/Env.h Outdated Show resolved Hide resolved
src/test/jtx/Env.h Outdated Show resolved Hide resolved
src/test/jtx/impl/Env.cpp Show resolved Hide resolved
src/test/jtx/impl/Env.cpp Outdated Show resolved Hide resolved
src/test/jtx/impl/Env.cpp Show resolved Hide resolved
src/test/jtx/Env.h Outdated Show resolved Hide resolved
ximinez added 3 commits April 18, 2024 19:25
* Make ter and rpcCode optional in ParsedResult
* Remove didApply from ParsedResult
* upstream/develop:
  fix: Remove redundant STAmount conversion in test (4996)
  fix: resolve database deadlock: (4989)
  test: verify the rounding behavior of equal-asset AMM deposits (4982)
  test: Add tests to raise coverage of AMM (4971)
  chore: Improve codecov coverage reporting (4977)
  test: Unit test for AMM offer overflow (4986)
  fix amendment to add `PreviousTxnID`/`PreviousTxnLgrSequence` (4751)
* upstream/develop:
  Set version to 2.2.0-b3
@ximinez
Copy link
Collaborator Author

ximinez commented Apr 24, 2024

Proposed commit message:

test: Add RPC error checking support to unit tests (#4987)

@ximinez ximinez added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Apr 24, 2024
@ximinez ximinez merged commit e9859ac into XRPLF:develop Apr 24, 2024
16 of 17 checks passed
@ximinez ximinez deleted the pr/jtx_rpc branch April 24, 2024 17:54
legleux added a commit to legleux/rippled that referenced this pull request Apr 26, 2024
* Remove unused files

* Remove packaging scripts

* Consolidate external libraries

* Simplify protobuf generation

* Rename .hpp to .h

* Format formerly .hpp files

* Rewrite includes

$ find src/ripple/ src/test/ -type f -exec sed -i 's:include\s*["<]ripple/\(.*\)\.h\(pp\)\?[">]:include <ripple/\1.h>:' {} +

* Fix source lists

* Add markers around source lists

* Address compiler warnings

* Ignore more commits

* test: Add RPC error checking support to unit tests (XRPLF#4987)

* chore: fix typos (XRPLF#4958)

* file

* new commit

* file sucks

---------

Co-authored-by: John Freeman <[email protected]>
Co-authored-by: Pretty Printer <[email protected]>
Co-authored-by: Ed Hennis <[email protected]>
Co-authored-by: Snoppy <[email protected]>
sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
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. Perf impact not expected Change is not expected to improve nor harm performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants