diff options
Diffstat (limited to 'src/test/util')
-rw-r--r-- | src/test/util/mining.cpp | 14 | ||||
-rw-r--r-- | src/test/util/mining.h | 7 | ||||
-rw-r--r-- | src/test/util/setup_common.cpp | 3 | ||||
-rw-r--r-- | src/test/util/setup_common.h | 3 |
4 files changed, 17 insertions, 10 deletions
diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp index 30f0f5d7e6..1df6844062 100644 --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -8,22 +8,23 @@ #include <consensus/merkle.h> #include <key_io.h> #include <miner.h> +#include <node/context.h> #include <pow.h> #include <script/standard.h> #include <validation.h> -CTxIn generatetoaddress(const std::string& address) +CTxIn generatetoaddress(const NodeContext& node, const std::string& address) { const auto dest = DecodeDestination(address); assert(IsValidDestination(dest)); const auto coinbase_script = GetScriptForDestination(dest); - return MineBlock(coinbase_script); + return MineBlock(node, coinbase_script); } -CTxIn MineBlock(const CScript& coinbase_scriptPubKey) +CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) { - auto block = PrepareBlock(coinbase_scriptPubKey); + auto block = PrepareBlock(node, coinbase_scriptPubKey); while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) { ++block->nNonce; @@ -36,10 +37,11 @@ CTxIn MineBlock(const CScript& coinbase_scriptPubKey) return CTxIn{block->vtx[0]->GetHash(), 0}; } -std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey) +std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) { + assert(node.mempool); auto block = std::make_shared<CBlock>( - BlockAssembler{Params()} + BlockAssembler{*node.mempool, Params()} .CreateNewBlock(coinbase_scriptPubKey) ->block); diff --git a/src/test/util/mining.h b/src/test/util/mining.h index afe4de684f..5f250fffe8 100644 --- a/src/test/util/mining.h +++ b/src/test/util/mining.h @@ -11,14 +11,15 @@ class CBlock; class CScript; class CTxIn; +struct NodeContext; /** Returns the generated coin */ -CTxIn MineBlock(const CScript& coinbase_scriptPubKey); +CTxIn MineBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); /** Prepare a block to be mined */ -std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey); +std::shared_ptr<CBlock> PrepareBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); /** RPC-like helper function, returns the generated coin */ -CTxIn generatetoaddress(const std::string& address); +CTxIn generatetoaddress(const NodeContext&, const std::string& address); #endif // BITCOIN_TEST_UTIL_MINING_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 86c355fdcd..ccb3064d59 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -71,6 +71,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName) SelectParams(chainName); SeedInsecureRand(); gArgs.ForceSetArg("-printtoconsole", "0"); + if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN); InitLogging(); LogInstance().StartLogging(); SHA256AutoDetect(); @@ -175,7 +176,7 @@ TestChain100Setup::TestChain100Setup() CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey) { const CChainParams& chainparams = Params(); - std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey); + std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(*m_node.mempool, chainparams).CreateNewBlock(scriptPubKey); CBlock& block = pblocktemplate->block; // Replace mempool-selected txns with just coinbase plus passed-in txns: diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 1e2e059a56..6741be8480 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -18,6 +18,9 @@ #include <boost/thread.hpp> +/** This is connected to the logger. Can be used to redirect logs to any other log */ +extern const std::function<void(const std::string&)> G_TEST_LOG_FUN; + // Enable BOOST_CHECK_EQUAL for enum class types template <typename T> std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e) |