13 #include <boost/test/unit_test.hpp>
27 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)
29 memcpy(charstrval, charstrvalin,
sizeof(charstrval));
43 return intval == rhs.
intval &&
58 READWRITE(obj.intval, obj.boolval, obj.stringval, obj.charstrval, obj.txval);
95 for (
int i = 0; i < 100000; i++) {
101 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
108 for (
int i = 0; i < 100000; i++) {
111 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
114 for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
115 uint64_t j = std::numeric_limits<uint64_t>::max();
117 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
145 std::vector<char>::size_type i, j;
155 BOOST_CHECK_MESSAGE((i-1) == j,
"decoded:" << j <<
" expected:" << (i-1));
157 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
163 std::ios_base::failure expectedException(
"non-canonical ReadCompactSize()");
169 return strcmp(expectedException.what(), ex.what()) == 0;
174 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};
175 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};
177 BOOST_CHECK(vec1 == std::vector<uint8_t>(vec2.begin(), vec2.end()));
186 std::vector<char>::size_type n;
202 ss.write(
MakeByteSpan(
"\xfe\x00\x00\x00\x00").first(5));
206 ss.write(
MakeByteSpan(
"\xfe\xff\xff\x00\x00").first(5));
210 ss.write(
MakeByteSpan(
"\xff\x00\x00\x00\x00\x00\x00\x00\x00").first(9));
214 ss.write(
MakeByteSpan(
"\xff\xff\xff\xff\x01\x00\x00\x00\x00").first(9));
222 std::string stringval(
"testing");
223 const uint8_t charstrval[16]{
"testing charstr"};
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.
void write(Span< const value_type > src)
vector_type::size_type size_type
BOOST_AUTO_TEST_SUITE_END()
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
#define VARINT_MODE(obj, mode)
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...
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
size_t GetSerializeSize(const T &t, int nVersion=0)
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
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 HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static const int PROTOCOL_VERSION
network protocol versioning