5 #include <test/data/base58_encode_decode.json.h>
16 #include <boost/test/unit_test.hpp>
19 using namespace std::literals;
26 UniValue tests =
read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode +
sizeof(json_tests::base58_encode_decode)));
27 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
29 std::string strTest = test.
write();
32 BOOST_ERROR(
"Bad test: " << strTest);
35 std::vector<unsigned char> sourcedata =
ParseHex(test[0].get_str());
36 std::string base58string = test[1].
get_str();
46 UniValue tests =
read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode +
sizeof(json_tests::base58_encode_decode)));
47 std::vector<unsigned char> result;
49 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
51 std::string strTest = test.
write();
54 BOOST_ERROR(
"Bad test: " << strTest);
57 std::vector<unsigned char> expected =
ParseHex(test[0].get_str());
58 std::string base58string = test[1].
get_str();
59 BOOST_CHECK_MESSAGE(
DecodeBase58(base58string, result, 256), strTest);
60 BOOST_CHECK_MESSAGE(result.size() == expected.size() && std::equal(result.begin(), result.end(), expected.begin()), strTest);
75 std::vector<unsigned char> expected =
ParseHex(
"971a55");
76 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
86 for (
int n = 0; n < 1000; ++n) {
91 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)
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
BOOST_AUTO_TEST_SUITE_END()
UniValue read_json(const std::string &jsondata)
#define BOOST_CHECK(expr)
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
static uint64_t InsecureRandRange(uint64_t range)
static uint64_t InsecureRandBits(int bits)
static bool InsecureRandBool()
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.