aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/fuzz.cpp9
-rw-r--r--src/test/miner_tests.cpp2
-rw-r--r--src/test/net_tests.cpp19
-rw-r--r--src/test/pow_tests.cpp32
-rw-r--r--src/test/txvalidation_tests.cpp3
-rw-r--r--src/test/txvalidationcache_tests.cpp2
-rw-r--r--src/test/validation_block_tests.cpp3
-rw-r--r--src/test/validation_tests.cpp79
-rw-r--r--src/test/versionbits_tests.cpp4
9 files changed, 103 insertions, 50 deletions
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp
index 1e1807d734..753cfffdcb 100644
--- a/src/test/fuzz/fuzz.cpp
+++ b/src/test/fuzz/fuzz.cpp
@@ -12,15 +12,6 @@
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
-// Decide if main(...) should be provided:
-// * AFL needs main(...) regardless of platform.
-// * macOS handles __attribute__((weak)) main(...) poorly when linking
-// against libFuzzer. See https://github.com/bitcoin/bitcoin/pull/18008
-// for details.
-#if defined(__AFL_COMPILER) || !defined(MAC_OSX)
-#define PROVIDE_MAIN_FUNCTION
-#endif
-
#if defined(PROVIDE_MAIN_FUNCTION)
static bool read_stdin(std::vector<uint8_t>& data)
{
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 8686012af7..3de79a9f45 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -198,7 +198,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
{
// Note that by default, these tests run with size accounting enabled.
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const CChainParams& chainparams = *chainParams;
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
std::unique_ptr<CBlockTemplate> pblocktemplate;
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index fe03c1ece4..121a16e548 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -251,6 +251,25 @@ BOOST_AUTO_TEST_CASE(cnetaddr_basic)
BOOST_CHECK(addr.IsAddrV1Compatible());
BOOST_CHECK_EQUAL(addr.ToString(), "1122:3344:5566:7788:9900:aabb:ccdd:eeff");
+ // IPv6, scoped/link-local. See https://tools.ietf.org/html/rfc4007
+ // We support non-negative decimal integers (uint32_t) as zone id indices.
+ // Test with a fairly-high value, e.g. 32, to avoid locally reserved ids.
+ const std::string link_local{"fe80::1"};
+ const std::string scoped_addr{link_local + "%32"};
+ BOOST_REQUIRE(LookupHost(scoped_addr, addr, false));
+ BOOST_REQUIRE(addr.IsValid());
+ BOOST_REQUIRE(addr.IsIPv6());
+ BOOST_CHECK(!addr.IsBindAny());
+ const std::string addr_str{addr.ToString()};
+ BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1");
+ // The fallback case "fe80:0:0:0:0:0:0:1" is needed for macOS 10.14/10.15 and (probably) later.
+ // Test that the delimiter "%" and default zone id of 0 can be omitted for the default scope.
+ BOOST_REQUIRE(LookupHost(link_local + "%0", addr, false));
+ BOOST_REQUIRE(addr.IsValid());
+ BOOST_REQUIRE(addr.IsIPv6());
+ BOOST_CHECK(!addr.IsBindAny());
+ BOOST_CHECK_EQUAL(addr.ToString(), link_local);
+
// TORv2
BOOST_REQUIRE(addr.SetSpecial("6hzph5hv6337r6p2.onion"));
BOOST_REQUIRE(addr.IsValid());
diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp
index ca49b89ad8..1d7f4861fb 100644
--- a/src/test/pow_tests.cpp
+++ b/src/test/pow_tests.cpp
@@ -14,7 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
/* Test calculation of next difficulty target with no constraints applying */
BOOST_AUTO_TEST_CASE(get_next_work)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
int64_t nLastRetargetTime = 1261130161; // Block #30240
CBlockIndex pindexLast;
pindexLast.nHeight = 32255;
@@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
/* Test the constraint on the upper bound for next work */
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
int64_t nLastRetargetTime = 1231006505; // Block #0
CBlockIndex pindexLast;
pindexLast.nHeight = 2015;
@@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
/* Test the constraint on the lower bound for actual time taken */
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
int64_t nLastRetargetTime = 1279008237; // Block #66528
CBlockIndex pindexLast;
pindexLast.nHeight = 68543;
@@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
/* Test the constraint on the upper bound for actual time taken */
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 46367;
@@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
{
- const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
nBits = UintToArith256(consensus.powLimit).GetCompact(true);
@@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
{
- const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits = ~0x00800000;
hash.SetHex("0x1");
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
{
- const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 nBits_arith = UintToArith256(consensus.powLimit);
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
{
- const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 hash_arith = UintToArith256(consensus.powLimit);
@@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
{
- const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 hash_arith{0};
@@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
std::vector<CBlockIndex> blocks(10000);
for (int i = 0; i < 10000; i++) {
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
@@ -135,9 +135,9 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
}
}
-void sanity_check_chainparams(std::string chainName)
+void sanity_check_chainparams(const ArgsManager& args, std::string chainName)
{
- const auto chainParams = CreateChainParams(chainName);
+ const auto chainParams = CreateChainParams(args, chainName);
const auto consensus = chainParams->GetConsensus();
// hash genesis is correct
@@ -164,22 +164,22 @@ void sanity_check_chainparams(std::string chainName)
BOOST_AUTO_TEST_CASE(ChainParams_MAIN_sanity)
{
- sanity_check_chainparams(CBaseChainParams::MAIN);
+ sanity_check_chainparams(*m_node.args, CBaseChainParams::MAIN);
}
BOOST_AUTO_TEST_CASE(ChainParams_REGTEST_sanity)
{
- sanity_check_chainparams(CBaseChainParams::REGTEST);
+ sanity_check_chainparams(*m_node.args, CBaseChainParams::REGTEST);
}
BOOST_AUTO_TEST_CASE(ChainParams_TESTNET_sanity)
{
- sanity_check_chainparams(CBaseChainParams::TESTNET);
+ sanity_check_chainparams(*m_node.args, CBaseChainParams::TESTNET);
}
BOOST_AUTO_TEST_CASE(ChainParams_SIGNET_sanity)
{
- sanity_check_chainparams(CBaseChainParams::SIGNET);
+ sanity_check_chainparams(*m_node.args, CBaseChainParams::SIGNET);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp
index c3d7af8323..7e6246d68f 100644
--- a/src/test/txvalidation_tests.cpp
+++ b/src/test/txvalidation_tests.cpp
@@ -40,8 +40,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
false,
AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(coinbaseTx),
nullptr /* plTxnReplaced */,
- true /* bypass_limits */,
- 0 /* nAbsurdFee */));
+ true /* bypass_limits */));
// Check that the transaction hasn't been added to mempool.
BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize);
diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp
index 034577aa2c..bed2ba3608 100644
--- a/src/test/txvalidationcache_tests.cpp
+++ b/src/test/txvalidationcache_tests.cpp
@@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
TxValidationState state;
return AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(tx),
- nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
+ nullptr /* plTxnReplaced */, true /* bypass_limits */);
};
// Create a double-spend of mature coinbase txn:
diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp
index 8e85b7df3e..ea17cb50f1 100644
--- a/src/test/validation_block_tests.cpp
+++ b/src/test/validation_block_tests.cpp
@@ -291,8 +291,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
state,
tx,
&plTxnReplaced,
- /* bypass_limits */ false,
- /* nAbsurdFee */ 0));
+ /* bypass_limits */ false));
}
}
diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp
index 3b961db52d..c3816af0cd 100644
--- a/src/test/validation_tests.cpp
+++ b/src/test/validation_tests.cpp
@@ -4,11 +4,11 @@
#include <chainparams.h>
#include <net.h>
+#include <signet.h>
#include <validation.h>
#include <test/util/setup_common.h>
-#include <boost/signals2/signal.hpp>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup)
@@ -39,7 +39,7 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
BOOST_AUTO_TEST_CASE(block_subsidy_test)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
TestBlockSubsidyHalvings(150); // As in regtest
TestBlockSubsidyHalvings(1000); // Just another interval
@@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test)
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
{
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
CAmount nSum = 0;
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
@@ -58,20 +58,65 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000});
}
-static bool ReturnFalse() { return false; }
-static bool ReturnTrue() { return true; }
-
-BOOST_AUTO_TEST_CASE(test_combiner_all)
+BOOST_AUTO_TEST_CASE(signet_parse_tests)
{
- boost::signals2::signal<bool (), CombinerAll> Test;
- BOOST_CHECK(Test());
- Test.connect(&ReturnFalse);
- BOOST_CHECK(!Test());
- Test.connect(&ReturnTrue);
- BOOST_CHECK(!Test());
- Test.disconnect(&ReturnFalse);
- BOOST_CHECK(Test());
- Test.disconnect(&ReturnTrue);
- BOOST_CHECK(Test());
+ ArgsManager signet_argsman;
+ signet_argsman.ForceSetArg("-signetchallenge", "51"); // set challenge to OP_TRUE
+ const auto signet_params = CreateChainParams(signet_argsman, CBaseChainParams::SIGNET);
+ CBlock block;
+ BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{OP_TRUE});
+ CScript challenge{OP_TRUE};
+
+ // empty block is invalid
+ BOOST_CHECK(!SignetTxs::Create(block, challenge));
+ BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // no witness commitment
+ CMutableTransaction cb;
+ cb.vout.emplace_back(0, CScript{});
+ block.vtx.push_back(MakeTransactionRef(cb));
+ block.vtx.push_back(MakeTransactionRef(cb)); // Add dummy tx to excercise merkle root code
+ BOOST_CHECK(!SignetTxs::Create(block, challenge));
+ BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // no header is treated valid
+ std::vector<uint8_t> witness_commitment_section_141{0xaa, 0x21, 0xa9, 0xed};
+ for (int i = 0; i < 32; ++i) {
+ witness_commitment_section_141.push_back(0xff);
+ }
+ cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141;
+ block.vtx.at(0) = MakeTransactionRef(cb);
+ BOOST_CHECK(SignetTxs::Create(block, challenge));
+ BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // no data after header, valid
+ std::vector<uint8_t> witness_commitment_section_325{0xec, 0xc7, 0xda, 0xa2};
+ cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
+ block.vtx.at(0) = MakeTransactionRef(cb);
+ BOOST_CHECK(SignetTxs::Create(block, challenge));
+ BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // Premature end of data, invalid
+ witness_commitment_section_325.push_back(0x01);
+ witness_commitment_section_325.push_back(0x51);
+ cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
+ block.vtx.at(0) = MakeTransactionRef(cb);
+ BOOST_CHECK(!SignetTxs::Create(block, challenge));
+ BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // has data, valid
+ witness_commitment_section_325.push_back(0x00);
+ cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
+ block.vtx.at(0) = MakeTransactionRef(cb);
+ BOOST_CHECK(SignetTxs::Create(block, challenge));
+ BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));
+
+ // Extraneous data, invalid
+ witness_commitment_section_325.push_back(0x00);
+ cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
+ block.vtx.at(0) = MakeTransactionRef(cb);
+ BOOST_CHECK(!SignetTxs::Create(block, challenge));
+ BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));
}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp
index 11c6bdad91..50444f7bbe 100644
--- a/src/test/versionbits_tests.cpp
+++ b/src/test/versionbits_tests.cpp
@@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
}
// Sanity checks of version bit deployments
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
uint32_t bitmask = VersionBitsMask(mainnetParams, static_cast<Consensus::DeploymentPos>(i));
@@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
{
// Check that ComputeBlockVersion will set the appropriate bit correctly
// on mainnet.
- const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
+ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
// Use the TESTDUMMY deployment for testing purposes.