6 #define BOOST_TEST_MODULE Pivx Test Suite
27 #include "validation.h"
29 #include <boost/test/unit_test.hpp>
40 static uint256 GetUintFromEnv(
const std::string& env_name)
42 const char* num = std::getenv(env_name.c_str());
51 static const std::string RANDOM_CTX_SEED{
"RANDOM_CTX_SEED"};
52 if (seed.IsNull()) seed = GetUintFromEnv(RANDOM_CTX_SEED);
54 LogPrintf(
"%s: Setting random seed for current tests to %s=%s\n", __func__, RANDOM_CTX_SEED, seed.GetHex());
68 : m_path_root{fs::temp_directory_path() /
"test_pivx" /
std::to_string(g_insecure_rand_ctx_temp_path.rand32())}
92 fs::create_directories(ret);
104 threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>,
"scheduler", serviceLoop));
111 g_connman = std::make_unique<CConnman>(0x1337, 0x1337);
120 RegisterAllCoreRPCCommands(
tableRPC);
128 throw std::runtime_error(
"Error initializing block database");
174 for (
int i = 0; i < blockCount; i++)
176 std::vector<CMutableTransaction> noTxns;
200 bool fTestBlockValidity,
214 std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);
218 pblock->vtx.push_back(MakeTransactionRef(tx));
221 const int nHeight = (customPrevBlock !=
nullptr ? customPrevBlock->
nHeight + 1
233 bool fTestBlockValidity)
236 return CreateBlock(txns, scriptPubKey, fTestBlockValidity);
242 while (!
CheckProofOfWork(pblock->GetHash(), pblock->nBits)) { ++(pblock->nNonce); }
bool SolveBlock(std::shared_ptr< CBlock > &pblock, int nHeight)
Modify the nonce/extranonce in a block.
uint256 CalculateSaplingTreeRoot(CBlock *pblock, int nHeight, const CChainParams &chainparams)
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
Allows modifying the network upgrade regtest parameters.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
const CChainParams & Params()
Return the currently selected parameters.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn, CWallet *pwallet=nullptr, bool fProofOfStake=false, std::vector< CStakeableOutput > *availableCoins=nullptr, bool fNoMempoolTx=false, bool fTestValidity=true, CBlockIndex *prevBlock=nullptr, bool stopPoSOnNewBlock=true, bool fIncludeQfc=true)
Construct a new block template with coinbase to scriptPubKeyIn.
CBaseChainParams defines the base parameters (shared between pivx-cli and pivxd) of a given instance ...
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
int nHeight
height of the entry in the chain. The genesis block has height 0
Access to the block database (blocks/index/)
int Height() const
Return the maximal height in the chain.
Signals for UI communication.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CCoinsView backed by the LevelDB coin database (chainstate/)
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once)
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
void stop(bool drain=false)
std::function< void(void)> Function
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Capture information about block/transaction validation.
Zerocoin database (zerocoin/)
std::string ToString() const
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
std::unique_ptr< CEvoDB > evoDb
void ECC_Start()
Initialize the elliptic curve support.
void ECC_Stop()
Deinitialize the elliptic curve support.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
void InterruptLLMQSystem()
void InitLLMQSystem(CEvoDB &evoDb, CScheduler *scheduler, bool unitTests)
RecursiveMutex cs_main
Global state.
#define BOOST_CHECK(expr)
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
uint256 GetRandHash() noexcept
std::vector< unsigned char > ToByteVector(const T &in)
void InitSignatureCache()
BasicTestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
fs::path SetDataDir(const std::string &name)
const fs::path m_path_root
A mutable version of CTransaction.
TestChainSetup(int blockCount)
std::vector< CTransaction > coinbaseTxns
CBlock CreateBlock(const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey, bool fNoMempoolTx=true, bool fTestBlockValidity=true, bool fIncludeQfc=true, CBlockIndex *customPrevBlock=nullptr)
CBlock CreateAndProcessBlock(const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey, bool fNoMempoolTx=true)
bool spendsCoinbaseOrCoinstake
CTxMemPoolEntry FromTx(const CMutableTransaction &tx)
EvoNotificationInterface * pEvoNotificationInterface
TestingSetup(const std::string &chainName=CBaseChainParams::MAIN)
boost::thread_group threadGroup
std::unique_ptr< PeerLogicValidation > peerLogic
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::unique_ptr< CConnman > g_connman
std::ostream & operator<<(std::ostream &os, const uint256 &num)
CClientUIInterface uiInterface
std::shared_ptr< CBlock > FinalizeBlock(std::shared_ptr< CBlock > pblock)
void Seed(FastRandomContext &ctx)
Seed the given random ctx or use the seed passed in via an environment var.
void Shutdown(void *parg)
FastRandomContext g_insecure_rand_ctx
uint256 uint256S(const char *str)
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
std::unique_ptr< CZerocoinDB > zerocoinDB
Global variable that points to the zerocoin database (protected by cs_main)
std::unique_ptr< CSporkDB > pSporkDB
Global variable that points to the spork database (protected by cs_main)
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
bool ActivateBestChain(CValidationState &state, std::shared_ptr< const CBlock > pblock)
Make the best chain active, in multiple steps.
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
void ThreadScriptCheck()
Run an instance of the script checking thread.
std::unique_ptr< CCoinsViewDB > pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
void UnloadBlockIndex()
Unload database information.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
CMainSignals & GetMainSignals()
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.