XRPLF / rippled

Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
https://xrpl.org
ISC License
4.51k stars 1.46k forks source link

Add RPC error checking support to unit tests #4987

Closed ximinez closed 5 months ago

ximinez commented 5 months ago

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

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.]

codecov-commenter commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/XRPLF/rippled/pull/4987/graphs/tree.svg?width=650&height=150&src=pr&token=i2RPGI5xGF&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XRPLF)](https://app.codecov.io/gh/XRPLF/rippled/pull/4987?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XRPLF) ```diff @@ 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](https://app.codecov.io/gh/XRPLF/rippled/pull/4987/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XRPLF) [![Impacted file tree graph](https://app.codecov.io/gh/XRPLF/rippled/pull/4987/graphs/tree.svg?width=650&height=150&src=pr&token=i2RPGI5xGF&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XRPLF)](https://app.codecov.io/gh/XRPLF/rippled/pull/4987?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XRPLF)
ximinez commented 5 months ago

Proposed commit message:

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