5#include <test/data/base58_encode_decode.json.h>
16#include <boost/test/unit_test.hpp>
19using namespace std::literals;
28 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
30 std::string strTest = test.
write();
33 BOOST_ERROR(
"Bad test: " << strTest);
36 std::vector<unsigned char> sourcedata =
ParseHex(test[0].get_str());
37 std::string base58string = test[1].
get_str();
48 std::vector<unsigned char> result;
50 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
52 std::string strTest = test.
write();
55 BOOST_ERROR(
"Bad test: " << strTest);
58 std::vector<unsigned char> expected =
ParseHex(test[0].get_str());
59 std::string base58string = test[1].
get_str();
60 BOOST_CHECK_MESSAGE(
DecodeBase58(base58string, result, 256), strTest);
61 BOOST_CHECK_MESSAGE(result.size() == expected.size() && std::equal(result.begin(), result.end(), expected.begin()), strTest);
76 constexpr auto expected{
"971a55"_hex_u8};
77 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
87 for (
int n = 0; n < 1000; ++n) {
88 unsigned int len = 1 + m_rng.randbits(8);
89 unsigned int zeroes = m_rng.randbool() ? m_rng.randrange(len + 1) : 0;
90 auto data =
Cat(std::vector<unsigned char>(zeroes,
'\000'), m_rng.randbytes(len - zeroes));
92 std::vector<unsigned char> decoded;
std::string EncodeBase58(Span< const unsigned char > input)
Why base-58 instead of standard base-64 encoding?
std::string EncodeBase58Check(Span< const unsigned char > input)
Encode a byte span into a base58-encoded string, including checksum.
static bool DecodeBase58Check(const char *psz, std::vector< unsigned char > &vchRet, int max_ret_len)
static bool DecodeBase58(const char *psz, std::vector< unsigned char > &vch, int max_ret_len)
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
UniValue read_json(std::string_view jsondata)
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
#define BOOST_CHECK(expr)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.