15#include <boost/test/unit_test.hpp>
41 CSerializeMethodsTestSingle(
int intvalin,
bool boolvalin, std::string stringvalin,
const uint8_t* charstrvalin,
const CTransactionRef& txvalin) : intval(intvalin), boolval(boolvalin), stringval(
std::move(stringvalin)), txval(txvalin)
43 memcpy(charstrval, charstrvalin,
sizeof(charstrval));
57 return intval == rhs.
intval &&
111 for (
int i = 0; i < 100000; i++) {
117 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
124 for (
int i = 0; i < 100000; i++) {
127 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
130 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
131 uint64_t j = std::numeric_limits<uint64_t>::max();
133 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
161 std::vector<char>::size_type i, j;
171 BOOST_CHECK_MESSAGE((i-1) == j,
"decoded:" << j <<
" expected:" << (i-1));
173 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
179 std::ios_base::failure expectedException(
"non-canonical ReadCompactSize()");
185 return strcmp(expectedException.what(), ex.what()) == 0;
190 std::vector<uint8_t> vec1{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1};
191 std::vector<bool> vec2{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1};
193 BOOST_CHECK(vec1 == std::vector<uint8_t>(vec2.begin(), vec2.end()));
199 std::array<uint8_t, 32> array1{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1};
202 std::array<uint8_t, 32> array2;
212 std::vector<char>::size_type n;
215 ss << std::span{
"\xfd\x00\x00"}.first(3);
219 ss << std::span{
"\xfd\xfc\x00"}.first(3);
223 ss << std::span{
"\xfd\xfd\x00"}.first(3);
228 ss << std::span{
"\xfe\x00\x00\x00\x00"}.first(5);
232 ss << std::span{
"\xfe\xff\xff\x00\x00"}.first(5);
236 ss << std::span{
"\xff\x00\x00\x00\x00\x00\x00\x00\x00"}.first(9);
240 ss << std::span{
"\xff\xff\xff\xff\x01\x00\x00\x00\x00"}.first(9);
248 std::string stringval(
"testing");
249 const uint8_t charstrval[16]{
"testing charstr"};
267 ss2 << intval << boolval << stringval << charstrval <<
TX_WITH_WITNESS(txval);
272 const std::string in{
"ab"};
273 ds << std::span{in} << std::byte{
'c'};
274 std::array<std::byte, 2>
out;
276 ds >> std::span{
out} >> out_3;
302 template <
typename Stream>
312 template <
typename Stream>
318 std::string hex{
"aa"};
319 s >> std::span{hex}.first(hex.size());
320 m_base_data = TryParseHex<uint8_t>(hex).value().at(0);
346 READWRITE(fmt.m_base_format(AsBase<Base>(obj)));
348 if (ser_action.ForRead()) {
351 SER_READ(obj, obj.m_derived_data = str);
371 template <
typename Stream>
374 const uint8_t param =
s.template GetParams<OtherParam>().param;
378 template <
typename Stream>
381 const uint8_t param =
s.template GetParams<OtherParam>().param;
402 ParamsStream pstream{stream,
RAW, other_param_used, other_param_ignored};
405 pstream << base1 <<
check << other_param_override(
check);
409 pstream >> base2 >>
check >> other_param_override(
check);
419 pstream.GetStream().clear();
455 std::vector<Base> v{
Base{0x0F},
Base{0xFF}};
462 v[0].m_base_data = 0;
463 v[1].m_base_data = 0;
474 v[0].m_base_data = 0;
475 v[1].m_base_data = 0;
(Un)serialize a number as raw byte or 2 hexadecimal chars.
void Unserialize(Stream &s)
void Serialize(Stream &s) const
SERIALIZE_METHODS(CSerializeMethodsTestMany, obj)
CSerializeMethodsTestSingle(int intvalin, bool boolvalin, std::string stringvalin, const uint8_t *charstrvalin, const CTransactionRef &txvalin)
CSerializeMethodsTestSingle()=default
SERIALIZE_METHODS(CSerializeMethodsTestSingle, obj)
bool operator==(const CSerializeMethodsTestSingle &rhs) const
Double ended buffer combining vector and stream-like interfaces.
vector_type::size_type size_type
std::string m_derived_data
SERIALIZE_METHODS(Derived, obj)
A writer stream (for serialization) that computes a 256-bit hash.
Checker for value of OtherParam.
void Unserialize(Stream &s) const
void Serialize(Stream &s) const
Wrapper that overrides the GetParams() function of a stream.
UncopyableStream & operator=(const UncopyableStream &)=delete
UncopyableStream(const UncopyableStream &)=delete
UncopyableStream(UncopyableStream &&) noexcept=default
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
#define VARINT_MODE(obj, mode)
#define SER_PARAMS(type)
Formatter methods can retrieve parameters attached to a stream using the SER_PARAMS(type) macro as lo...
static constexpr uint64_t MAX_SIZE
The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size...
void WriteCompactSize(SizeComputer &os, uint64_t nSize)
#define SER_READ(obj, code)
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
uint64_t GetSerializeSize(const T &t)
constexpr DerivedAndBaseFormat HEX_UPPER
constexpr DerivedAndBaseFormat RAW_LOWER
static bool isCanonicalException(const std::ios_base::failure &ex)
BOOST_AUTO_TEST_CASE(sizes)
auto MakeByteSpan(const V &v) noexcept
A mutable version of CTransaction.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.