Skip to content

Commit

Permalink
Add unit tests related to:
Browse files Browse the repository at this point in the history
    Use error codes throughout fast Base58 implementation
    Improve error handling in some RPC commands
  • Loading branch information
ximinez committed Oct 31, 2024
1 parent 0d887ad commit 0f79609
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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,8 +169,9 @@ 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;
static constexpr std::uint64_t B_58_10 = 430804206899405824; // 58^10;
assert(input < B_58_10);
(void)B_58_10;
constexpr std::size_t resultSize = 10;
std::array<std::uint8_t, resultSize> result{};
int i = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/test/protocol/types_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
{
auto const s =
"âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f";
BEAST_EXPECT(!parseBase58<AccountID>(s));
}
}

void
Expand Down
29 changes: 29 additions & 0 deletions src/test/rpc/AccountObjects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,35 @@ class AccountObjects_test : public beast::unit_test::suite
}
}

void
testAccountNFTs()
{
testcase("account_nfts");

using namespace jtx;
Env env(*this);

// test validation
{
auto testInvalidAccountParam = [&](auto const& param) {
Json::Value params;
params[jss::account] = param;
auto jrr = env.rpc(
"json", "account_nfts", to_string(params))[jss::result];
BEAST_EXPECT(jrr[jss::error] == "invalidParams");
BEAST_EXPECT(
jrr[jss::error_message] == "Invalid field 'account'.");
};

testInvalidAccountParam(1);
testInvalidAccountParam(1.1);
testInvalidAccountParam(true);
testInvalidAccountParam(Json::Value(Json::nullValue));
testInvalidAccountParam(Json::Value(Json::objectValue));
testInvalidAccountParam(Json::Value(Json::arrayValue));
}
}

void
testAccountObjectMarker()
{
Expand Down

0 comments on commit 0f79609

Please sign in to comment.