From 9c1b088d8fed88bad52f060edd19b7dd12034c78 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 31 Oct 2024 12:59:57 -0400 Subject: [PATCH 1/4] test: Add more test cases for Base58 and NFTs --- include/xrpl/protocol/detail/b58_utils.h | 3 ++- src/test/protocol/types_test.cpp | 5 ++++ src/test/rpc/AccountObjects_test.cpp | 29 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/xrpl/protocol/detail/b58_utils.h b/include/xrpl/protocol/detail/b58_utils.h index b060fc7e166..ae2ee31b68a 100644 --- a/include/xrpl/protocol/detail/b58_utils.h +++ b/include/xrpl/protocol/detail/b58_utils.h @@ -169,8 +169,9 @@ inplace_bigint_div_rem(std::span numerator, std::uint64_t divisor) [[nodiscard]] inline std::array 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 result{}; int i = 0; diff --git a/src/test/protocol/types_test.cpp b/src/test/protocol/types_test.cpp index ac4314df640..a58670b184d 100644 --- a/src/test/protocol/types_test.cpp +++ b/src/test/protocol/types_test.cpp @@ -30,6 +30,11 @@ struct types_test : public beast::unit_test::suite auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; if (BEAST_EXPECT(parseBase58(s))) BEAST_EXPECT(toBase58(*parseBase58(s)) == s); + { + auto const s = + "âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f"; + BEAST_EXPECT(!parseBase58(s)); + } } void diff --git a/src/test/rpc/AccountObjects_test.cpp b/src/test/rpc/AccountObjects_test.cpp index 7326fff0c76..9bd8858920a 100644 --- a/src/test/rpc/AccountObjects_test.cpp +++ b/src/test/rpc/AccountObjects_test.cpp @@ -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() { From 046f49c15adb296d8fbb182cf06aa40a734dfa03 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 31 Oct 2024 16:46:03 -0400 Subject: [PATCH 2/4] Oops. Remove duplicated function. --- src/test/rpc/AccountObjects_test.cpp | 29 ---------------------------- 1 file changed, 29 deletions(-) diff --git a/src/test/rpc/AccountObjects_test.cpp b/src/test/rpc/AccountObjects_test.cpp index 9bd8858920a..7326fff0c76 100644 --- a/src/test/rpc/AccountObjects_test.cpp +++ b/src/test/rpc/AccountObjects_test.cpp @@ -1220,35 +1220,6 @@ 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() { From 2472ba16d32033207c6253f019177757b04c19dd Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Mon, 4 Nov 2024 15:42:51 -0500 Subject: [PATCH 3/4] [FOLD] Review feedback from @vlntb --- include/xrpl/protocol/detail/b58_utils.h | 4 ++-- src/test/protocol/types_test.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/xrpl/protocol/detail/b58_utils.h b/include/xrpl/protocol/detail/b58_utils.h index ae2ee31b68a..57cfa460d98 100644 --- a/include/xrpl/protocol/detail/b58_utils.h +++ b/include/xrpl/protocol/detail/b58_utils.h @@ -169,9 +169,9 @@ inplace_bigint_div_rem(std::span numerator, std::uint64_t divisor) [[nodiscard]] inline std::array b58_10_to_b58_be(std::uint64_t input) { - static constexpr std::uint64_t B_58_10 = 430804206899405824; // 58^10; + static constexpr [[maybe_unused]] 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 result{}; int i = 0; diff --git a/src/test/protocol/types_test.cpp b/src/test/protocol/types_test.cpp index a58670b184d..8257d9c6495 100644 --- a/src/test/protocol/types_test.cpp +++ b/src/test/protocol/types_test.cpp @@ -28,8 +28,11 @@ struct types_test : public beast::unit_test::suite testAccountID() { auto const s = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"; - if (BEAST_EXPECT(parseBase58(s))) - BEAST_EXPECT(toBase58(*parseBase58(s)) == s); + if (auto const parsed = parseBase58(s); BEAST_EXPECT(parsed)) + { + BEAST_EXPECT(toBase58(*parsed) == s); + } + { auto const s = "âabcd1rNxp4h8apvRis6mJf9Sh8C6iRxfrDWNâabcdAVâ\xc2\x80\xc2\x8f"; From d188efbb637b3986442a8c120118063717a1ffaf Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Mon, 4 Nov 2024 18:43:06 -0500 Subject: [PATCH 4/4] [FOLD] Move [[maybe_unused]] to make linux clang compiler happy --- include/xrpl/protocol/detail/b58_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/xrpl/protocol/detail/b58_utils.h b/include/xrpl/protocol/detail/b58_utils.h index 57cfa460d98..c3a480d2a47 100644 --- a/include/xrpl/protocol/detail/b58_utils.h +++ b/include/xrpl/protocol/detail/b58_utils.h @@ -169,7 +169,7 @@ inplace_bigint_div_rem(std::span numerator, std::uint64_t divisor) [[nodiscard]] inline std::array b58_10_to_b58_be(std::uint64_t input) { - static constexpr [[maybe_unused]] std::uint64_t B_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;