21 #include "validation.h"
25 #include <boost/test/unit_test.hpp>
57 std::atomic<bool> interruptDummy(
false);
59 connman->ClearBanned();
69 peerLogic->SendMessages(&dummyNode1, interruptDummy);
83 peerLogic->SendMessages(&dummyNode2, interruptDummy);
90 peerLogic->SendMessages(&dummyNode2, interruptDummy);
97 std::atomic<bool> interruptDummy(
false);
99 connman->ClearBanned();
110 peerLogic->SendMessages(&dummyNode1, interruptDummy);
116 peerLogic->SendMessages(&dummyNode1, interruptDummy);
122 peerLogic->SendMessages(&dummyNode1, interruptDummy);
130 std::atomic<bool> interruptDummy(
false);
132 connman->ClearBanned();
133 int64_t nStartTime =
GetTime();
146 peerLogic->SendMessages(&dummyNode, interruptDummy);
159 std::map<uint256, COrphanTx>::iterator it;
161 it = mapOrphanTransactions.lower_bound(InsecureRand256());
162 if (it == mapOrphanTransactions.end())
163 it = mapOrphanTransactions.begin();
164 return it->second.tx;
167 static void MakeNewKeyWithFastRandomContext(
CKey& key)
169 std::vector<unsigned char> keydata;
171 key.
Set(keydata.data(), keydata.data() + keydata.size(),
true);
186 MakeNewKeyWithFastRandomContext(key);
191 for (
int i = 0; i < 50; i++)
195 tx.
vin[0].prevout.n = 0;
196 tx.
vin[0].prevout.hash = InsecureRand256();
199 tx.
vout[0].nValue = 1*CENT;
206 for (
int i = 0; i < 50; i++)
212 tx.
vin[0].prevout.n = 0;
213 tx.
vin[0].prevout.hash = txPrev->GetHash();
215 tx.
vout[0].nValue = 1*CENT;
223 for (
int i = 0; i < 10; i++)
229 tx.
vout[0].nValue = 1*CENT;
232 for (
unsigned int j = 0; j < tx.
vin.size(); j++)
234 tx.
vin[j].prevout.n = j;
235 tx.
vin[j].prevout.hash = txPrev->GetHash();
240 for (
unsigned int j = 1; j < tx.
vin.size(); j++)
241 tx.
vin[j].scriptSig = tx.
vin[0].scriptSig;
248 for (
NodeId i = 0; i < 3; i++)
250 size_t sizeBefore = mapOrphanTransactions.size();
252 BOOST_CHECK(mapOrphanTransactions.size() < sizeBefore);
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
RecursiveMutex g_cs_orphans
bool AddOrphanTx(const CTransactionRef &tx, NodeId peer)
void EraseOrphansFor(NodeId peer)
For random eviction.
BOOST_AUTO_TEST_CASE(DoS_banning)
CTransactionRef RandomOrphan()
void misbehave(NodeId id, int value)
std::map< uint256, COrphanTx > mapOrphanTransactions GUARDED_BY(g_cs_orphans)
uint256 ArithToUint256(const arith_uint256 &a)
const CChainParams & Params()
Return the currently selected parameters.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
A CService with information about it as peer.
Basic key store, that keeps keys in an address->secret map.
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
virtual bool AddKey(const CKey &key)
Information about a peer.
std::atomic< int > nVersion
void SetSendVersion(int nVersionIn)
RecursiveMutex cs_sendProcessing
std::atomic_bool fSuccessfullyConnected
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
A combination of a network address (CNetAddr) and a (TCP) port.
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
256-bit unsigned big integer.
BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< PeerLogicValidation > peerLogic
void Misbehaving(NodeId pnode, int howmuch, const std::string &message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Increase a node's misbehavior score.
RecursiveMutex cs_main
Global state.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK(expr)
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, bool fColdStake)
Produce a script signature for a transaction.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
std::vector< CTxOut > vout
FastRandomContext g_insecure_rand_ctx
std::shared_ptr< const CTransaction > CTransactionRef
void SetMockTime(int64_t nMockTimeIn)
For testing.
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)