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
3 changes: 2 additions & 1 deletion include/xrpl/protocol/detail/b58_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ inplace_bigint_div_rem(std::span<uint64_t> numerator, std::uint64_t divisor)
[[nodiscard]] inline std::array<std::uint8_t, 10>
b58_10_to_b58_be(std::uint64_t input)
{
constexpr std::uint64_t B_58_10 = 430804206899405824; // 58^10;
[[maybe_unused]] static constexpr std::uint64_t B_58_10 =
430804206899405824; // 58^10;
assert(input < B_58_10);
constexpr std::size_t resultSize = 10;
std::array<std::uint8_t, resultSize> result{};
Expand Down
12 changes: 10 additions & 2 deletions src/test/protocol/types_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ struct types_test : public beast::unit_test::suite
testAccountID()
{
auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
if (BEAST_EXPECT(parseBase58<AccountID>(s)))
BEAST_EXPECT(toBase58(*parseBase58<AccountID>(s)) == s);
if (auto const parsed = parseBase58<AccountID>(s); BEAST_EXPECT(parsed))
{
BEAST_EXPECT(toBase58(*parsed) == 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.

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

void
Expand Down
Loading