14#include <boost/test/unit_test.hpp>
40 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)
42 memcpy(charstrval, charstrvalin,
sizeof(charstrval));
56 return intval == rhs.
intval &&
110 for (
int i = 0; i < 100000; i++) {
116 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
123 for (
int i = 0; i < 100000; i++) {
126 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
129 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
130 uint64_t j = std::numeric_limits<uint64_t>::max();
132 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
160 std::vector<char>::size_type i, j;
170 BOOST_CHECK_MESSAGE((i-1) == j,
"decoded:" << j <<
" expected:" << (i-1));
172 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
178 std::ios_base::failure expectedException(
"non-canonical ReadCompactSize()");
184 return strcmp(expectedException.what(), ex.what()) == 0;
189 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};
190 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};
192 BOOST_CHECK(vec1 == std::vector<uint8_t>(vec2.begin(), vec2.end()));
198 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};
201 std::array<uint8_t, 32> array2;
211 std::vector<char>::size_type n;
227 ss <<
Span{
"\xfe\x00\x00\x00\x00"}.
first(5);
231 ss <<
Span{
"\xfe\xff\xff\x00\x00"}.
first(5);
235 ss <<
Span{
"\xff\x00\x00\x00\x00\x00\x00\x00\x00"}.
first(9);
239 ss <<
Span{
"\xff\xff\xff\xff\x01\x00\x00\x00\x00"}.
first(9);
247 std::string stringval(
"testing");
248 const uint8_t charstrval[16]{
"testing charstr"};
266 ss2 << intval << boolval << stringval << charstrval <<
TX_WITH_WITNESS(txval);
271 const std::string in{
"ab"};
272 ds <<
Span{in} << std::byte{
'c'};
273 std::array<std::byte, 2>
out;
301 template <
typename Stream>
311 template <
typename Stream>
317 std::string hex{
"aa"};
319 m_base_data = TryParseHex<uint8_t>(hex).value().at(0);
345 READWRITE(fmt.m_base_format(AsBase<Base>(obj)));
347 if (ser_action.ForRead()) {
350 SER_READ(obj, obj.m_derived_data = str);
370 template <
typename Stream>
373 const uint8_t param =
s.template GetParams<OtherParam>().param;
377 template <
typename Stream>
380 const uint8_t param =
s.template GetParams<OtherParam>().param;
401 ParamsStream pstream{stream,
RAW, other_param_used, other_param_ignored};
404 pstream << base1 << check << other_param_override(check);
408 pstream >> base2 >> check >> other_param_override(check);
418 pstream.GetStream().clear();
454 std::vector<Base> v{
Base{0x0F},
Base{0xFF}};
461 v[0].m_base_data = 0;
462 v[1].m_base_data = 0;
473 v[0].m_base_data = 0;
474 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.
A Span is an object that can refer to a contiguous sequence of objects.
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
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 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
size_t GetSerializeSize(const T &t)
#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.
constexpr DerivedAndBaseFormat HEX_UPPER
constexpr DerivedAndBaseFormat RAW_LOWER
static bool isCanonicalException(const std::ios_base::failure &ex)
BOOST_AUTO_TEST_CASE(sizes)
Span< const std::byte > MakeByteSpan(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.