aboutsummaryrefslogtreecommitdiff
path: root/src/test/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/util')
-rw-r--r--src/test/util/json.cpp17
-rw-r--r--src/test/util/json.h14
-rw-r--r--src/test/util/mining.cpp12
-rw-r--r--src/test/util/mining.h4
-rw-r--r--src/test/util/net.cpp7
-rw-r--r--src/test/util/net.h4
-rw-r--r--src/test/util/setup_common.cpp21
7 files changed, 61 insertions, 18 deletions
diff --git a/src/test/util/json.cpp b/src/test/util/json.cpp
new file mode 100644
index 0000000000..ad3c346c84
--- /dev/null
+++ b/src/test/util/json.cpp
@@ -0,0 +1,17 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <test/util/json.h>
+
+#include <string>
+#include <util/check.h>
+
+#include <univalue.h>
+
+UniValue read_json(const std::string& jsondata)
+{
+ UniValue v;
+ Assert(v.read(jsondata) && v.isArray());
+ return v.get_array();
+}
diff --git a/src/test/util/json.h b/src/test/util/json.h
new file mode 100644
index 0000000000..5b1026762e
--- /dev/null
+++ b/src/test/util/json.h
@@ -0,0 +1,14 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_TEST_UTIL_JSON_H
+#define BITCOIN_TEST_UTIL_JSON_H
+
+#include <string>
+
+#include <univalue.h>
+
+UniValue read_json(const std::string& jsondata);
+
+#endif // BITCOIN_TEST_UTIL_JSON_H
diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp
index 55e9d4d63b..0df1db84c4 100644
--- a/src/test/util/mining.cpp
+++ b/src/test/util/mining.cpp
@@ -8,7 +8,6 @@
#include <consensus/merkle.h>
#include <key_io.h>
#include <node/context.h>
-#include <node/miner.h>
#include <pow.h>
#include <script/standard.h>
#include <test/util/script.h>
@@ -74,10 +73,11 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
return CTxIn{block->vtx[0]->GetHash(), 0};
}
-std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
+std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey,
+ const BlockAssembler::Options& assembler_options)
{
auto block = std::make_shared<CBlock>(
- BlockAssembler{Assert(node.chainman)->ActiveChainstate(), Assert(node.mempool.get())}
+ BlockAssembler{Assert(node.chainman)->ActiveChainstate(), Assert(node.mempool.get()), assembler_options}
.CreateNewBlock(coinbase_scriptPubKey)
->block);
@@ -87,3 +87,9 @@ std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coi
return block;
}
+std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
+{
+ BlockAssembler::Options assembler_options;
+ ApplyArgsManOptions(*node.args, assembler_options);
+ return PrepareBlock(node, coinbase_scriptPubKey, assembler_options);
+}
diff --git a/src/test/util/mining.h b/src/test/util/mining.h
index 09e712cd35..70b1f7b3fb 100644
--- a/src/test/util/mining.h
+++ b/src/test/util/mining.h
@@ -5,6 +5,8 @@
#ifndef BITCOIN_TEST_UTIL_MINING_H
#define BITCOIN_TEST_UTIL_MINING_H
+#include <node/miner.h>
+
#include <memory>
#include <string>
#include <vector>
@@ -25,6 +27,8 @@ CTxIn MineBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
/** Prepare a block to be mined */
std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
+std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext& node, const CScript& coinbase_scriptPubKey,
+ const node::BlockAssembler::Options& assembler_options);
/** RPC-like helper function, returns the generated coin */
CTxIn generatetoaddress(const node::NodeContext&, const std::string& address);
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp
index 975aff13c0..ac5dfe9e73 100644
--- a/src/test/util/net.cpp
+++ b/src/test/util/net.cpp
@@ -67,15 +67,14 @@ void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_by
assert(node.ReceiveMsgBytes(msg_bytes, complete));
if (complete) {
size_t nSizeAdded = 0;
- auto it(node.vRecvMsg.begin());
- for (; it != node.vRecvMsg.end(); ++it) {
+ for (const auto& msg : node.vRecvMsg) {
// vRecvMsg contains only completed CNetMessage
// the single possible partially deserialized message are held by TransportDeserializer
- nSizeAdded += it->m_raw_message_size;
+ nSizeAdded += msg.m_raw_message_size;
}
{
LOCK(node.cs_vProcessMsg);
- node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
+ node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg);
node.nProcessQueueSize += nSizeAdded;
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
}
diff --git a/src/test/util/net.h b/src/test/util/net.h
index 90c606306f..e6506b0d08 100644
--- a/src/test/util/net.h
+++ b/src/test/util/net.h
@@ -103,7 +103,7 @@ constexpr auto ALL_NETWORKS = std::array{
class StaticContentsSock : public Sock
{
public:
- explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0}
+ explicit StaticContentsSock(const std::string& contents) : m_contents{contents}
{
// Just a dummy number that is not INVALID_SOCKET.
m_socket = INVALID_SOCKET - 1;
@@ -191,7 +191,7 @@ public:
private:
const std::string m_contents;
- mutable size_t m_consumed;
+ mutable size_t m_consumed{0};
};
std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context);
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index efc8529bf6..6e72f69968 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -208,23 +208,24 @@ ChainTestingSetup::~ChainTestingSetup()
void TestingSetup::LoadVerifyActivateChainstate()
{
+ auto& chainman{*Assert(m_node.chainman)};
node::ChainstateLoadOptions options;
options.mempool = Assert(m_node.mempool.get());
options.block_tree_db_in_memory = m_block_tree_db_in_memory;
options.coins_db_in_memory = m_coins_db_in_memory;
options.reindex = node::fReindex;
options.reindex_chainstate = m_args.GetBoolArg("-reindex-chainstate", false);
- options.prune = node::fPruneMode;
+ options.prune = chainman.m_blockman.IsPruneMode();
options.check_blocks = m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
options.check_level = m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
- auto [status, error] = LoadChainstate(*Assert(m_node.chainman), m_cache_sizes, options);
+ auto [status, error] = LoadChainstate(chainman, m_cache_sizes, options);
assert(status == node::ChainstateLoadStatus::SUCCESS);
- std::tie(status, error) = VerifyLoadedChainstate(*Assert(m_node.chainman), options);
+ std::tie(status, error) = VerifyLoadedChainstate(chainman, options);
assert(status == node::ChainstateLoadStatus::SUCCESS);
BlockValidationState state;
- if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
+ if (!chainman.ActiveChainstate().ActivateBestChain(state)) {
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
}
}
@@ -397,15 +398,15 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
unspent_prevouts.pop_front();
}
const size_t num_outputs = det_rand.randrange(24) + 1;
- // Approximately 1000sat "fee," equal output amounts.
- const CAmount amount_per_output = (total_in - 1000) / num_outputs;
+ const CAmount fee = 100 * det_rand.randrange(30);
+ const CAmount amount_per_output = (total_in - fee) / num_outputs;
for (size_t n{0}; n < num_outputs; ++n) {
CScript spk = CScript() << CScriptNum(num_transactions + n);
mtx.vout.push_back(CTxOut(amount_per_output, spk));
}
CTransactionRef ptx = MakeTransactionRef(mtx);
mempool_transactions.push_back(ptx);
- if (amount_per_output > 2000) {
+ if (amount_per_output > 3000) {
// If the value is high enough to fund another transaction + fees, keep track of it so
// it can be used to build a more complex transaction graph. Insert randomly into
// unspent_prevouts for extra randomness in the resulting structures.
@@ -415,9 +416,11 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex
}
}
if (submit) {
- LOCK2(m_node.mempool->cs, cs_main);
+ LOCK2(cs_main, m_node.mempool->cs);
LockPoints lp;
- m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, 1000, 0, 1, false, 4, lp));
+ m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, /*fee=*/(total_in - num_outputs * amount_per_output),
+ /*time=*/0, /*entry_height=*/1,
+ /*spends_coinbase=*/false, /*sigops_cost=*/4, lp));
}
--num_transactions;
}