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

test: Add more test cases for Base58 parser #5174

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

ximinez
Copy link
Collaborator

@ximinez ximinez commented Oct 31, 2024

High Level Overview of Change

Adds unit tests related to the AccountID handling updated in 2.2.1 (#5078)

Context of Change

2.2.1 was released without all of the relevant unit tests for reasons. This PR finally follows up on that and adds the tests.

(Also fixes an unused variable build warning on Release builds.)

Type of Change

  • Refactor (non-breaking change that only restructures code)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)

@ximinez ximinez added Tech Debt Non-urgent improvements Perf impact not expected Change is not expected to improve nor harm performance. labels Oct 31, 2024
assert(input < B_58_10);
(void)B_58_10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this line do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It fools the compiler into thinking the variable is used, so you don't get unused variable warnings when asserts are disabled.

In file included from /home/extra/ed/dev/rippled/current/src/ripple/protocol/impl/tokens.cpp:32:
/home/extra/ed/dev/rippled/current/src/ripple/protocol/impl/b58_utils.h: In function ‘std::array<unsigned char, 10> ripple::b58_fast::detail::b58_10_to_b58_be(uint64_t)’:
/home/extra/ed/dev/rippled/current/src/ripple/protocol/impl/b58_utils.h:172:29: warning: unused variable ‘B_58_10’ [-Wunused-variable]
  172 |     constexpr std::uint64_t B_58_10 = 430804206899405824;  // 58^10;
      |                             ^~~~~~~

It's just an annoyance, but it was on the branch I had sitting around, so I included it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case it would be better to use maybe_unused attribute:

static constexpr [[maybe_unused]] std::uint64_t B_58_10 = 430804206899405824; // 58^10

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I keep forgetting that exists. LOL

@ximinez ximinez changed the title test: Add more test cases for Base58 and NFTs test: Add more test cases for Base58 Oct 31, 2024
@ximinez ximinez changed the title test: Add more test cases for Base58 test: Add more test cases for Base58 parse Oct 31, 2024
@ximinez ximinez changed the title test: Add more test cases for Base58 parse test: Add more test cases for Base58 parser Oct 31, 2024
@ximinez
Copy link
Collaborator Author

ximinez commented Oct 31, 2024

The final commit message should not include "NFTs". That function was an unintentional duplicate.

Also need to add @thejohnfreeman as a coauthor, since he wrote the original unit test.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.9%. Comparing base (838978b) to head (a7d0dd3).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5174     +/-   ##
=========================================
- Coverage     77.9%   77.9%   -0.0%     
=========================================
  Files          782     782             
  Lines        66621   66619      -2     
  Branches      8161    8136     -25     
=========================================
- Hits         51902   51899      -3     
- Misses       14719   14720      +1     
Files with missing lines Coverage Δ
include/xrpl/protocol/detail/b58_utils.h 95.5% <ø> (-0.1%) ⬇️

... and 4 files with indirect coverage changes

Impacted file tree graph

Copy link
Collaborator

@vlntb vlntb left a comment

Choose a reason for hiding this comment

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

Very minor changes.

assert(input < B_58_10);
(void)B_58_10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case it would be better to use maybe_unused attribute:

static constexpr [[maybe_unused]] std::uint64_t B_58_10 = 430804206899405824; // 58^10

@@ -30,6 +30,11 @@ struct types_test : public beast::unit_test::suite
auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
if (BEAST_EXPECT(parseBase58<AccountID>(s)))
BEAST_EXPECT(toBase58(*parseBase58<AccountID>(s)) == s);
{
Copy link
Collaborator

@vlntb vlntb Nov 4, 2024

Choose a reason for hiding this comment

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

[nit] For me the intention is not very clear - is this a deliberate scope introduction or a mistake in using if statement. To make it clearer I would mark the borders of the scope of if explicitly to make clearly separate for the new scope.

if (BEAST_EXPECT(parseBase58<AccountID>(s)))
{
    BEAST_EXPECT(toBase58(*parseBase58<AccountID>(s)) == s);
}

{
    auto const s =
        "âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f";
    BEAST_EXPECT(!parseBase58<AccountID>(s));
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, now that you mention it, it does look a little off. I changed the test a little bit to make that all clearer, and to remove the need to parse s twice.

@ximinez ximinez requested a review from vlntb November 4, 2024 22:27
* upstream/develop:
  Add AMMClawback Transaction (XLS-0073d) (5142)
  Add hubs.xrpkuwait.com to bootstrap (5169)
@ximinez ximinez added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Nov 5, 2024
@ximinez
Copy link
Collaborator Author

ximinez commented Nov 5, 2024

Proposed commit message:

 test: Add more test cases for Base58 parser (#5174)

---------
Co-authored-by: John Freeman <[email protected]>

@ximinez ximinez added the Blocked label Nov 7, 2024
@ximinez
Copy link
Collaborator Author

ximinez commented Nov 7, 2024

Hold merging until after 2.3.0 final release.

@ximinez ximinez added this to the 2.4.0 (2025) milestone Nov 7, 2024
* upstream/develop:
  Set version to 2.3.0-rc1
  Replace Uint192 with Hash192 in server_definitions response (5177)
  Fix potential deadlock (5124)
  Introduce Credentials support (XLS-70d): (5103)
  Fix token comparison in Payment (5172)
  Add fixAMMv1_2 amendment (5176)
* upstream/develop:
  fix: include `index` in `server_definitions` RPC (5190)
  Fix ledger_entry crash on invalid credentials request (5189)
* upstream/develop:
  Set version to 2.3.0-rc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked 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. Tech Debt Non-urgent improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants