Changeset View
Changeset View
Standalone View
Standalone View
src/test/cashaddrenc_tests.cpp
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <cashaddrenc.h> | #include <cashaddrenc.h> | ||||
#include <cashaddr.h> | #include <cashaddr.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <key_io.h> | |||||
#include <random.h> | #include <random.h> | ||||
#include <streams.h> | |||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <key_io.h> | |||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
namespace { | namespace { | ||||
std::vector<std::string> GetNetworks() { | std::vector<std::string> GetNetworks() { | ||||
return {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, | return {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, | ||||
▲ Show 20 Lines • Show All 424 Lines • ▼ Show 20 Lines | for (const auto &t : cases) { | ||||
err += t.addr; | err += t.addr; | ||||
content = DecodeCashAddrContent(t.addr, t.prefix); | content = DecodeCashAddrContent(t.addr, t.prefix); | ||||
BOOST_CHECK_EQUAL(t.type, content.type); | BOOST_CHECK_EQUAL(t.type, content.type); | ||||
BOOST_CHECK_MESSAGE(t.hash == content.hash, err); | BOOST_CHECK_MESSAGE(t.hash == content.hash, err); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(serialize_cashaddrcontent) { | |||||
FastRandomContext rand(true); | |||||
for (auto ps : valid_sizes) { | |||||
std::vector<uint8_t> data = | |||||
insecure_GetRandomByteArray(rand, ps.second); | |||||
CashAddrContent content = {PUBKEY_TYPE, data}; | |||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | |||||
ss << content; | |||||
CashAddrContent deserContent; | |||||
ss >> deserContent; | |||||
BOOST_CHECK_EQUAL(content.type, deserContent.type); | |||||
BOOST_CHECK_EQUAL_COLLECTIONS(content.hash.begin(), content.hash.end(), | |||||
deserContent.hash.begin(), | |||||
deserContent.hash.end()); | |||||
} | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |