<commit_before>#include "googletest/googletest/include/gtest/gtest.h"

#include <boost/algorithm/hex.hpp>
#include <string>
#include <vector>

#include "serialize.h"

TEST(serialize_tests, varints)
{
    // encode

    CDataStream            ss(SER_DISK, 0);
    CDataStream::size_type size = 0;
    for (int i = 0; i < 100000; i++) {
        ss << VARINT(i);
        size += ::GetSerializeSize(VARINT(i), 0, 0);
        EXPECT_TRUE(size == ss.size());
    }

    for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
        ss << VARINT(i);
        size += ::GetSerializeSize(VARINT(i), 0, 0);
        EXPECT_TRUE(size == ss.size());
    }

    // decode
    for (int i = 0; i < 100000; i++) {
        int j = 0;
        ss >> VARINT(j);
        EXPECT_TRUE(i == j) << "decoded:" << j << " expected:" << i;
    }

    for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
        uint64_t j = 0;
        ss >> VARINT(j);
        EXPECT_TRUE(i == j) << "decoded:" << j << " expected:" << i;
    }
}

    /**
     * Classes that use serialization:
     * CAddrInfo
    CAddrMan
    CUnsignedAlert
    CAlert
    CBloomFilter
    CUnsignedSyncCheckpoint
    CSyncCheckpoint
    CMasterKey
    CPubKey
    CDiskTxPos
    COutPoint
    CTxIn
    CTxOut
    CTransaction
    CTxOutCompressor
    CTxUndo
    CMerkleTx
    CTxIndex
    CPartialMerkleTree
    CBlock
    CDiskBlockIndex
    CBlockLocator
    CMerkleBlock
    CNetAddr
    CService
    NTP1OutPoint
    NTP1TokenTxData
    NTP1Transaction
    NTP1TxIn
    NTP1TxOut
    CMessageHeader
    CAddress
    CInv
    CKeyPool
    CWalletTx
    CWalletKey
    CAccount
    CAccountingEntry
    CKeyMetadata
    Accumulator
    AccumulatorProofOfKnowledge
    PublicCoin
    PrivateCoin
    CoinSpend
    Commitment
    CommitmentProofOfKnowledge
    IntegerGroupParams
    AccumulatorAndProofParams
    Params
    SerialNumberSignatureOfKnowledge
    SpendMetaData
     */

#include "addrman.h"
#include "alert.h"
#include "bloom.h"
#include "checkpoints.h"
#include "crypter.h"
#include "main.h"
#include "ntp1/ntp1outpoint.h"
#include "ntp1/ntp1script.h"
#include "ntp1/ntp1tokentxdata.h"
#include "ntp1/ntp1transaction.h"
#include "ntp1/ntp1txin.h"
#include "ntp1/ntp1txout.h"
#include "protocol.h"
#include "wallet.h"
#include "zerocoin/Accumulator.h"
#include "zerocoin/AccumulatorProofOfKnowledge.h"

#include <boost/utility/string_view.hpp>
#include <type_traits>

void TEST_EQUALITY(boost::string_view a, boost::string_view b, unsigned line)
{
#ifdef EXPECT_EQ
    EXPECT_EQ(a, b) << " failure at line number: " << line;
#else
    if (a != b) {<commit_msg>Fix string_view for older versions of boost<commit_after>#include "googletest/googletest/include/gtest/gtest.h"

#include <boost/algorithm/hex.hpp>
#include <string>
#include <vector>

#include "serialize.h"

TEST(serialize_tests, varints)
{
    // encode

    CDataStream            ss(SER_DISK, 0);
    CDataStream::size_type size = 0;
    for (int i = 0; i < 100000; i++) {
        ss << VARINT(i);
        size += ::GetSerializeSize(VARINT(i), 0, 0);
        EXPECT_TRUE(size == ss.size());
    }

    for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
        ss << VARINT(i);
        size += ::GetSerializeSize(VARINT(i), 0, 0);
        EXPECT_TRUE(size == ss.size());
    }

    // decode
    for (int i = 0; i < 100000; i++) {
        int j = 0;
        ss >> VARINT(j);
        EXPECT_TRUE(i == j) << "decoded:" << j << " expected:" << i;
    }

    for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
        uint64_t j = 0;
        ss >> VARINT(j);
        EXPECT_TRUE(i == j) << "decoded:" << j << " expected:" << i;
    }
}

    /**
     * Classes that use serialization:
     * CAddrInfo
    CAddrMan
    CUnsignedAlert
    CAlert
    CBloomFilter
    CUnsignedSyncCheckpoint
    CSyncCheckpoint
    CMasterKey
    CPubKey
    CDiskTxPos
    COutPoint
    CTxIn
    CTxOut
    CTransaction
    CTxOutCompressor
    CTxUndo
    CMerkleTx
    CTxIndex
    CPartialMerkleTree
    CBlock
    CDiskBlockIndex
    CBlockLocator
    CMerkleBlock
    CNetAddr
    CService
    NTP1OutPoint
    NTP1TokenTxData
    NTP1Transaction
    NTP1TxIn
    NTP1TxOut
    CMessageHeader
    CAddress
    CInv
    CKeyPool
    CWalletTx
    CWalletKey
    CAccount
    CAccountingEntry
    CKeyMetadata
    Accumulator
    AccumulatorProofOfKnowledge
    PublicCoin
    PrivateCoin
    CoinSpend
    Commitment
    CommitmentProofOfKnowledge
    IntegerGroupParams
    AccumulatorAndProofParams
    Params
    SerialNumberSignatureOfKnowledge
    SpendMetaData
     */

#include "addrman.h"
#include "alert.h"
#include "bloom.h"
#include "checkpoints.h"
#include "crypter.h"
#include "main.h"
#include "ntp1/ntp1outpoint.h"
#include "ntp1/ntp1script.h"
#include "ntp1/ntp1tokentxdata.h"
#include "ntp1/ntp1transaction.h"
#include "ntp1/ntp1txin.h"
#include "ntp1/ntp1txout.h"
#include "protocol.h"
#include "wallet.h"
#include "zerocoin/Accumulator.h"
#include "zerocoin/AccumulatorProofOfKnowledge.h"

#include <type_traits>

#if BOOST_VERSION >= 106100
#include <boost/utility/string_view.hpp>
using StringViewT = boost::string_view;
#else
#include <boost/utility/string_ref.hpp>
using StringViewT = boost::string_ref;
#endif

void TEST_EQUALITY(StringViewT a, StringViewT b, unsigned line)
{
#ifdef EXPECT_EQ
    EXPECT_EQ(a, b) << " failure at line number: " << line;
#else
    if (a != b) {
{'fraction_non_alphanumeric': 0.11315547378104876, 'fraction_numerical': 0.03385464581416743, 'mean_word_length': 2.85805535841022, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3807702', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2029, 'n_words': 417}