aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/amount_tests.cpp26
-rw-r--r--src/test/blockfilter_index_tests.cpp2
-rw-r--r--src/test/blockmanager_tests.cpp8
-rw-r--r--src/test/coinstatsindex_tests.cpp4
-rw-r--r--src/test/fs_tests.cpp9
-rw-r--r--src/test/fuzz/http_request.cpp4
-rw-r--r--src/test/fuzz/minisketch.cpp26
-rw-r--r--src/test/fuzz/process_message.cpp11
-rw-r--r--src/test/fuzz/process_messages.cpp3
-rw-r--r--src/test/script_p2sh_tests.cpp12
-rw-r--r--src/test/txindex_tests.cpp2
-rw-r--r--src/test/util/index.cpp6
-rw-r--r--src/test/util/index.h5
-rw-r--r--src/test/util/setup_common.cpp6
-rw-r--r--src/test/util/setup_common.h1
-rw-r--r--src/test/validation_chainstatemanager_tests.cpp4
16 files changed, 90 insertions, 39 deletions
diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp
index 3815a5bba6..e5ab1cfb90 100644
--- a/src/test/amount_tests.cpp
+++ b/src/test/amount_tests.cpp
@@ -85,6 +85,32 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34));
// Maximum size in bytes, should not crash
CFeeRate(MAX_MONEY, std::numeric_limits<uint32_t>::max()).GetFeePerK();
+
+ // check multiplication operator
+ // check multiplying by zero
+ feeRate = CFeeRate(1000);
+ BOOST_CHECK(0 * feeRate == CFeeRate(0));
+ BOOST_CHECK(feeRate * 0 == CFeeRate(0));
+ // check multiplying by a positive integer
+ BOOST_CHECK(3 * feeRate == CFeeRate(3000));
+ BOOST_CHECK(feeRate * 3 == CFeeRate(3000));
+ // check multiplying by a negative integer
+ BOOST_CHECK(-3 * feeRate == CFeeRate(-3000));
+ BOOST_CHECK(feeRate * -3 == CFeeRate(-3000));
+ // check commutativity
+ BOOST_CHECK(2 * feeRate == feeRate * 2);
+ // check with large numbers
+ int largeNumber = 1000000;
+ BOOST_CHECK(largeNumber * feeRate == feeRate * largeNumber);
+ // check boundary values
+ int maxInt = std::numeric_limits<int>::max();
+ feeRate = CFeeRate(maxInt);
+ BOOST_CHECK(feeRate * 2 == CFeeRate(static_cast<int64_t>(maxInt) * 2));
+ BOOST_CHECK(2 * feeRate == CFeeRate(static_cast<int64_t>(maxInt) * 2));
+ // check with zero fee rate
+ feeRate = CFeeRate(0);
+ BOOST_CHECK(feeRate * 5 == CFeeRate(0));
+ BOOST_CHECK(5 * feeRate == CFeeRate(0));
}
BOOST_AUTO_TEST_CASE(BinaryOperatorTest)
diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp
index 97ea5cfbf3..a9009948ee 100644
--- a/src/test/blockfilter_index_tests.cpp
+++ b/src/test/blockfilter_index_tests.cpp
@@ -143,7 +143,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
BOOST_REQUIRE(filter_index.StartBackgroundSync());
// Allow filter index to catch up with the block index.
- IndexWaitSynced(filter_index);
+ IndexWaitSynced(filter_index, *Assert(m_node.shutdown));
// Check that filter index has all blocks that were in the chain before it started.
{
diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp
index e1b31c20f4..d7ac0bf823 100644
--- a/src/test/blockmanager_tests.cpp
+++ b/src/test/blockmanager_tests.cpp
@@ -27,13 +27,13 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
{
const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)};
- KernelNotifications notifications{m_node.exit_status};
+ KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status};
const BlockManager::Options blockman_opts{
.chainparams = *params,
.blocks_dir = m_args.GetBlocksDirPath(),
.notifications = notifications,
};
- BlockManager blockman{m_node.kernel->interrupt, blockman_opts};
+ BlockManager blockman{*Assert(m_node.shutdown), blockman_opts};
// simulate adding a genesis block normally
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
// simulate what happens during reindex
@@ -134,13 +134,13 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
{
- KernelNotifications notifications{m_node.exit_status};
+ KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status};
node::BlockManager::Options blockman_opts{
.chainparams = Params(),
.blocks_dir = m_args.GetBlocksDirPath(),
.notifications = notifications,
};
- BlockManager blockman{m_node.kernel->interrupt, blockman_opts};
+ BlockManager blockman{*Assert(m_node.shutdown), blockman_opts};
// Test blocks with no transactions, not even a coinbase
CBlock block1;
diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp
index 50f3f7d833..cc1ec49d41 100644
--- a/src/test/coinstatsindex_tests.cpp
+++ b/src/test/coinstatsindex_tests.cpp
@@ -35,7 +35,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
BOOST_REQUIRE(coin_stats_index.StartBackgroundSync());
- IndexWaitSynced(coin_stats_index);
+ IndexWaitSynced(coin_stats_index, *Assert(m_node.shutdown));
// Check that CoinStatsIndex works for genesis block.
const CBlockIndex* genesis_block_index;
@@ -86,7 +86,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup)
CoinStatsIndex index{interfaces::MakeChain(m_node), 1 << 20};
BOOST_REQUIRE(index.Init());
BOOST_REQUIRE(index.StartBackgroundSync());
- IndexWaitSynced(index);
+ IndexWaitSynced(index, *Assert(m_node.shutdown));
std::shared_ptr<const CBlock> new_block;
CBlockIndex* new_block_index = nullptr;
{
diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp
index 0d25428b33..c237963af3 100644
--- a/src/test/fs_tests.cpp
+++ b/src/test/fs_tests.cpp
@@ -17,9 +17,12 @@ BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(fsbridge_pathtostring)
{
std::string u8_str = "fs_tests_₿_🏃";
+ std::u8string str8{u8"fs_tests_₿_🏃"};
BOOST_CHECK_EQUAL(fs::PathToString(fs::PathFromString(u8_str)), u8_str);
- BOOST_CHECK_EQUAL(fs::u8path(u8_str).u8string(), u8_str);
- BOOST_CHECK_EQUAL(fs::PathFromString(u8_str).u8string(), u8_str);
+ BOOST_CHECK_EQUAL(fs::u8path(u8_str).utf8string(), u8_str);
+ BOOST_CHECK_EQUAL(fs::path(str8).utf8string(), u8_str);
+ BOOST_CHECK(fs::path(str8).u8string() == str8);
+ BOOST_CHECK_EQUAL(fs::PathFromString(u8_str).utf8string(), u8_str);
BOOST_CHECK_EQUAL(fs::PathToString(fs::u8path(u8_str)), u8_str);
#ifndef WIN32
// On non-windows systems, verify that arbitrary byte strings containing
@@ -46,7 +49,7 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream)
fs::path tmpfolder = m_args.GetDataDirBase();
// tmpfile1 should be the same as tmpfile2
fs::path tmpfile1 = tmpfolder / fs::u8path("fs_tests_₿_🏃");
- fs::path tmpfile2 = tmpfolder / fs::u8path("fs_tests_₿_🏃");
+ fs::path tmpfile2 = tmpfolder / fs::path(u8"fs_tests_₿_🏃");
{
std::ofstream file{tmpfile1};
file << "bitcoin";
diff --git a/src/test/fuzz/http_request.cpp b/src/test/fuzz/http_request.cpp
index 9928c4a1ab..f13f1c72a5 100644
--- a/src/test/fuzz/http_request.cpp
+++ b/src/test/fuzz/http_request.cpp
@@ -7,6 +7,7 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
+#include <util/signalinterrupt.h>
#include <util/strencodings.h>
#include <event2/buffer.h>
@@ -47,7 +48,8 @@ FUZZ_TARGET(http_request)
return;
}
- HTTPRequest http_request{evreq, true};
+ util::SignalInterrupt interrupt;
+ HTTPRequest http_request{evreq, interrupt, true};
const HTTPRequest::RequestMethod request_method = http_request.GetRequestMethod();
(void)RequestMethodString(request_method);
(void)http_request.GetURI();
diff --git a/src/test/fuzz/minisketch.cpp b/src/test/fuzz/minisketch.cpp
index a17be73f6c..698cb15fc9 100644
--- a/src/test/fuzz/minisketch.cpp
+++ b/src/test/fuzz/minisketch.cpp
@@ -12,14 +12,27 @@
#include <map>
#include <numeric>
-using node::MakeMinisketch32;
+namespace {
+
+Minisketch MakeFuzzMinisketch32(size_t capacity, uint32_t impl)
+{
+ return Assert(Minisketch(32, impl, capacity));
+}
+
+} // namespace
FUZZ_TARGET(minisketch)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
+
const auto capacity{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 200)};
- Minisketch sketch_a{Assert(MakeMinisketch32(capacity))};
- Minisketch sketch_b{Assert(MakeMinisketch32(capacity))};
+ const uint32_t impl{fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, Minisketch::MaxImplementation())};
+ if (!Minisketch::ImplementationSupported(32, impl)) return;
+
+ Minisketch sketch_a{MakeFuzzMinisketch32(capacity, impl)};
+ Minisketch sketch_b{MakeFuzzMinisketch32(capacity, impl)};
+ sketch_a.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
+ sketch_b.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
// Fill two sets and keep the difference in a map
std::map<uint32_t, bool> diff;
@@ -47,8 +60,11 @@ FUZZ_TARGET(minisketch)
}
const auto num_diff{std::accumulate(diff.begin(), diff.end(), size_t{0}, [](auto n, const auto& e) { return n + e.second; })};
- Minisketch sketch_ar{MakeMinisketch32(capacity)};
- Minisketch sketch_br{MakeMinisketch32(capacity)};
+ Minisketch sketch_ar{MakeFuzzMinisketch32(capacity, impl)};
+ Minisketch sketch_br{MakeFuzzMinisketch32(capacity, impl)};
+ sketch_ar.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
+ sketch_br.SetSeed(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
+
sketch_ar.Deserialize(sketch_a.Serialize());
sketch_br.Deserialize(sketch_b.Serialize());
diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp
index acb03ac5fc..56b391ed5c 100644
--- a/src/test/fuzz/process_message.cpp
+++ b/src/test/fuzz/process_message.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2020-2022 The Bitcoin Core developers
+// Copyright (c) 2020-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -8,9 +8,6 @@
#include <primitives/transaction.h>
#include <protocol.h>
#include <script/script.h>
-#include <serialize.h>
-#include <span.h>
-#include <streams.h>
#include <sync.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
@@ -20,13 +17,10 @@
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <test/util/validation.h>
-#include <util/chaintype.h>
#include <util/check.h>
#include <util/time.h>
-#include <validation.h>
#include <validationinterface.h>
-#include <atomic>
#include <cstdlib>
#include <iostream>
#include <memory>
@@ -81,8 +75,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
CSerializedNetMsg net_msg;
net_msg.m_type = random_message_type;
- // fuzzed_data_provider is fully consumed after this call, don't use it
- net_msg.data = fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>();
+ net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, MAX_PROTOCOL_MESSAGE_LENGTH);
connman.FlushSendBuffer(p2p_node);
(void)connman.ReceiveMsgFrom(p2p_node, std::move(net_msg));
diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp
index 3f722f60ee..6b264907b5 100644
--- a/src/test/fuzz/process_messages.cpp
+++ b/src/test/fuzz/process_messages.cpp
@@ -16,7 +16,6 @@
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <test/util/validation.h>
-#include <util/chaintype.h>
#include <util/time.h>
#include <validationinterface.h>
@@ -72,7 +71,7 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages)
CSerializedNetMsg net_msg;
net_msg.m_type = random_message_type;
- net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
+ net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, MAX_PROTOCOL_MESSAGE_LENGTH);
CNode& random_node = *PickValue(fuzzed_data_provider, peers);
diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp
index 739ab75de3..54dcc218b9 100644
--- a/src/test/script_p2sh_tests.cpp
+++ b/src/test/script_p2sh_tests.cpp
@@ -18,9 +18,15 @@
#include <boost/test/unit_test.hpp>
// Helpers:
+static bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, std::string& reason)
+{
+ return IsStandardTx(tx, std::nullopt, permit_bare_multisig, CFeeRate{DUST_RELAY_TX_FEE}, reason);
+}
+
static bool IsStandardTx(const CTransaction& tx, std::string& reason)
{
- return IsStandardTx(tx, std::nullopt, DEFAULT_PERMIT_BAREMULTISIG, CFeeRate{DUST_RELAY_TX_FEE}, reason);
+ return IsStandardTx(tx, std::nullopt, /*permit_bare_multisig=*/true, CFeeRate{DUST_RELAY_TX_FEE}, reason) &&
+ IsStandardTx(tx, std::nullopt, /*permit_bare_multisig=*/false, CFeeRate{DUST_RELAY_TX_FEE}, reason);
}
static std::vector<unsigned char> Serialize(const CScript& s)
@@ -201,7 +207,9 @@ BOOST_AUTO_TEST_CASE(set)
{
SignatureData empty;
BOOST_CHECK_MESSAGE(SignSignature(keystore, CTransaction(txFrom), txTo[i], 0, SIGHASH_ALL, empty), strprintf("SignSignature %d", i));
- BOOST_CHECK_MESSAGE(IsStandardTx(CTransaction(txTo[i]), reason), strprintf("txTo[%d].IsStandard", i));
+ BOOST_CHECK_MESSAGE(IsStandardTx(CTransaction(txTo[i]), /*permit_bare_multisig=*/true, reason), strprintf("txTo[%d].IsStandard", i));
+ bool no_pbms_is_std = IsStandardTx(CTransaction(txTo[i]), /*permit_bare_multisig=*/false, reason);
+ BOOST_CHECK_MESSAGE((i == 0 ? no_pbms_is_std : !no_pbms_is_std), strprintf("txTo[%d].IsStandard(permbaremulti=false)", i));
}
}
diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp
index 9fa59bab57..e2432a4718 100644
--- a/src/test/txindex_tests.cpp
+++ b/src/test/txindex_tests.cpp
@@ -33,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
BOOST_REQUIRE(txindex.StartBackgroundSync());
// Allow tx index to catch up with the block index.
- IndexWaitSynced(txindex);
+ IndexWaitSynced(txindex, *Assert(m_node.shutdown));
// Check that txindex excludes genesis block transactions.
const CBlock& genesis_block = Params().GenesisBlock();
diff --git a/src/test/util/index.cpp b/src/test/util/index.cpp
index e653d5dbf0..cfeba35756 100644
--- a/src/test/util/index.cpp
+++ b/src/test/util/index.cpp
@@ -5,16 +5,16 @@
#include <test/util/index.h>
#include <index/base.h>
-#include <shutdown.h>
#include <util/check.h>
+#include <util/signalinterrupt.h>
#include <util/time.h>
-void IndexWaitSynced(const BaseIndex& index)
+void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt)
{
while (!index.BlockUntilSyncedToCurrentChain()) {
// Assert shutdown was not requested to abort the test, instead of looping forever, in case
// there was an unexpected error in the index that caused it to stop syncing and request a shutdown.
- Assert(!ShutdownRequested());
+ Assert(!interrupt);
UninterruptibleSleep(100ms);
}
diff --git a/src/test/util/index.h b/src/test/util/index.h
index 95309f6273..a3bd1dddc3 100644
--- a/src/test/util/index.h
+++ b/src/test/util/index.h
@@ -6,8 +6,11 @@
#define BITCOIN_TEST_UTIL_INDEX_H
class BaseIndex;
+namespace util {
+class SignalInterrupt;
+} // namespace util
/** Block until the index is synced to the current chain */
-void IndexWaitSynced(const BaseIndex& index);
+void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt);
#endif // BITCOIN_TEST_UTIL_INDEX_H
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index bc639da4dd..8789e86196 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -40,7 +40,6 @@
#include <rpc/server.h>
#include <scheduler.h>
#include <script/sigcache.h>
-#include <shutdown.h>
#include <streams.h>
#include <test/util/net.h>
#include <test/util/random.h>
@@ -102,6 +101,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
m_args{}
{
+ m_node.shutdown = &m_interrupt;
m_node.args = &gArgs;
std::vector<const char*> arguments = Cat(
{
@@ -179,7 +179,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
m_cache_sizes = CalculateCacheSizes(m_args);
- m_node.notifications = std::make_unique<KernelNotifications>(m_node.exit_status);
+ m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status);
const ChainstateManager::Options chainman_opts{
.chainparams = chainparams,
@@ -194,7 +194,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
.blocks_dir = m_args.GetBlocksDirPath(),
.notifications = chainman_opts.notifications,
};
- m_node.chainman = std::make_unique<ChainstateManager>(m_node.kernel->interrupt, chainman_opts, blockman_opts);
+ m_node.chainman = std::make_unique<ChainstateManager>(*Assert(m_node.shutdown), chainman_opts, blockman_opts);
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<BlockTreeDB>(DBParams{
.path = m_args.GetDataDirNet() / "blocks" / "index",
.cache_bytes = static_cast<size_t>(m_cache_sizes.block_tree_db),
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index c3a4df28bf..9ff4c372a5 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -47,6 +47,7 @@ static constexpr CAmount CENT{1000000};
* This just configures logging, data dir and chain parameters.
*/
struct BasicTestingSetup {
+ util::SignalInterrupt m_interrupt;
node::NodeContext m_node; // keep as first member to be destructed last
explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {});
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index 6969822ad7..368ba8bee4 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -379,7 +379,7 @@ struct SnapshotTestSetup : TestChain100Setup {
LOCK(::cs_main);
chainman.ResetChainstates();
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
- m_node.notifications = std::make_unique<KernelNotifications>(m_node.exit_status);
+ m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status);
const ChainstateManager::Options chainman_opts{
.chainparams = ::Params(),
.datadir = chainman.m_options.datadir,
@@ -394,7 +394,7 @@ struct SnapshotTestSetup : TestChain100Setup {
// For robustness, ensure the old manager is destroyed before creating a
// new one.
m_node.chainman.reset();
- m_node.chainman = std::make_unique<ChainstateManager>(m_node.kernel->interrupt, chainman_opts, blockman_opts);
+ m_node.chainman = std::make_unique<ChainstateManager>(*Assert(m_node.shutdown), chainman_opts, blockman_opts);
}
return *Assert(m_node.chainman);
}