12 #include <boost/test/unit_test.hpp> 17 #include <string_view> 23 "\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
24 "\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
25 const
char R1ArrayHex[] = "7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
30 "\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
31 "\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
36 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
37 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
42 "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
43 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
48 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
49 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
55 std::stringstream Stream;
57 for (
unsigned int i = 0; i < width; ++i)
59 Stream<<std::setw(2)<<std::setfill(
'0')<<(
unsigned int)A[width-i-1];
131 for (
int i = 255; i >= 0; --i) {
133 *(TmpL.
begin() + (i>>3)) |= 1<<(7-(i&7));
134 BOOST_CHECK_LT(LastL, TmpL);
146 for (
int i = 159; i >= 0; --i) {
148 *(TmpS.
begin() + (i>>3)) |= 1<<(7-(i&7));
149 BOOST_CHECK_LT(LastS, TmpS);
166 BOOST_CHECK_LT(
uint256{
"1000000000000000000000000000000000000000000000000000000000000000"},
167 uint256{
"0000000000000000000000000000000000000000000000000000000000000001"});
179 TmpL.SetHexDeprecated(
"21");
180 BOOST_CHECK_EQUAL(TmpL.ToString(),
"0000000000000000000000000000000000000000000000000000000000000021");
297 #if defined(__clang__) 298 # pragma clang diagnostic push 299 # pragma clang diagnostic ignored "-Wself-assign-overloaded" 310 #if defined(__clang__) 311 # pragma clang diagnostic pop 318 std::string s_12{
"0000000000000000000000000000000000000000000000000000000000000012"};
347 template <
typename T>
350 constexpr
unsigned int num_chars{T::size() * 2};
351 static_assert(num_chars <= 64);
352 const std::string valid_64char_input{
"0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF"};
353 const auto valid_input{valid_64char_input.substr(0, num_chars)};
357 BOOST_REQUIRE(valid_result);
370 std::string invalid_chars{R
"( !"#$%&'()*+,-./:;<=>?@GHIJKLMNOPQRSTUVWXYZ[\]^_`ghijklmnopqrstuvwxyz{|}~)"}; 371 for (
auto c : invalid_chars) {
375 std::string invalid_prefix{
"0x" + valid_input};
381 std::string chars_68{valid_64char_input +
"0123"};
390 TestFromHex<uint160>();
391 TestFromHex<uint256>();
393 TestFromHex<Wtxid>();
398 uint256 one =
uint256{
"0000000000000000000000000000000000000000000000000000000000000001"};
404 auto runtime_uint{
uint256::FromHex(
"4A5E1E4BAAB89F3A32518A88C31BC87F618f76673e2cc77ab2127b7afdeda33b").value()};
405 constexpr
uint256 consteval_uint{
"4a5e1e4baab89f3a32518a88c31bc87f618F76673E2CC77AB2127B7AFDEDA33B"};
static constexpr unsigned int size()
size_t GetSerializeSize(const T &t)
static void from_hex(unsigned char *data, int len, const char *hex)
void TestFromHex()
Implemented as a templated function so it can be reused by other classes that have a FromHex() method...
const unsigned char R1Array[]
const unsigned char ZeroArray[]
arith_uint256 UintToArith256(const uint256 &a)
constexpr unsigned char * begin()
const unsigned char MaxArray[]
void SetHexDeprecated(std::string_view str)
Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated! ...
static std::string ArrayToString(const unsigned char A[], unsigned int width)
std::optional< uintN_t > FromHex(std::string_view str)
Writes the hex string (in reverse byte order) into a new uintN_t object and only returns a value iff ...
BOOST_AUTO_TEST_CASE(basics)
Double ended buffer combining vector and stream-like interfaces.
BOOST_AUTO_TEST_SUITE_END()
static std::optional< uint256 > FromHex(std::string_view str)
static const uint256 ZERO
const unsigned char R2Array[]
std::string ToString() const
256-bit unsigned big integer.
const unsigned char OneArray[]
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
uint256 ArithToUint256(const arith_uint256 &a)
#define BOOST_CHECK_EQUAL(v1, v2)
static std::optional< uint160 > FromHex(std::string_view str)
constexpr unsigned char * end()
std::string GetHex() const
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
uint256 uint256S(std::string_view str)
std::string GetHex() const
Hex encoding of the number (with the most significant digits first).
#define BOOST_CHECK(expr)
uint160 uint160S(std::string_view str)