aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/versionbits.cpp27
-rw-r--r--src/test/versionbits_tests.cpp24
2 files changed, 25 insertions, 26 deletions
diff --git a/src/test/fuzz/versionbits.cpp b/src/test/fuzz/versionbits.cpp
index 220e29ab04..5d859c911c 100644
--- a/src/test/fuzz/versionbits.cpp
+++ b/src/test/fuzz/versionbits.cpp
@@ -160,13 +160,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
} else {
if (fuzzed_data_provider.ConsumeBool()) {
start_time = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
- timeout = Consensus::BIP9Deployment::NO_TIMEOUT;
always_active_test = true;
} else {
- start_time = 1199145601; // January 1, 2008
- timeout = 1230767999; // December 31, 2008
+ start_time = Consensus::BIP9Deployment::NEVER_ACTIVE;
never_active_test = true;
}
+ timeout = fuzzed_data_provider.ConsumeBool() ? Consensus::BIP9Deployment::NO_TIMEOUT : fuzzed_data_provider.ConsumeIntegral<int64_t>();
}
int min_activation = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, period * max_periods);
@@ -318,7 +317,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
assert(exp_state == ThresholdState::ACTIVE || exp_state == ThresholdState::LOCKED_IN);
break;
case ThresholdState::FAILED:
- assert(current_block->GetMedianTimePast() >= checker.m_end);
+ assert(never_active_test || current_block->GetMedianTimePast() >= checker.m_end);
assert(exp_state != ThresholdState::LOCKED_IN && exp_state != ThresholdState::ACTIVE);
break;
default:
@@ -330,25 +329,19 @@ void test_one_input(const std::vector<uint8_t>& buffer)
assert(state == ThresholdState::ACTIVE || state == ThresholdState::FAILED);
}
- // "always active" has additional restrictions
if (always_active_test) {
+ // "always active" has additional restrictions
assert(state == ThresholdState::ACTIVE);
assert(exp_state == ThresholdState::ACTIVE);
assert(since == 0);
+ } else if (never_active_test) {
+ // "never active" does too
+ assert(state == ThresholdState::FAILED);
+ assert(exp_state == ThresholdState::FAILED);
+ assert(since == 0);
} else {
- // except for always active, the initial state is always DEFINED
+ // for signalled deployments, the initial state is always DEFINED
assert(since > 0 || state == ThresholdState::DEFINED);
assert(exp_since > 0 || exp_state == ThresholdState::DEFINED);
}
-
- // "never active" does too
- if (never_active_test) {
- assert(state == ThresholdState::FAILED);
- assert(since == period);
- if (exp_since == 0) {
- assert(exp_state == ThresholdState::DEFINED);
- } else {
- assert(exp_state == ThresholdState::FAILED);
- }
- }
}
diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp
index f1b131b498..0bf5bce27f 100644
--- a/src/test/versionbits_tests.cpp
+++ b/src/test/versionbits_tests.cpp
@@ -59,8 +59,7 @@ public:
class TestNeverActiveConditionChecker : public TestConditionChecker
{
public:
- int64_t BeginTime(const Consensus::Params& params) const override { return 0; }
- int64_t EndTime(const Consensus::Params& params) const override { return 1230768000; }
+ int64_t BeginTime(const Consensus::Params& params) const override { return Consensus::BIP9Deployment::NEVER_ACTIVE; }
};
#define CHECKERS 6
@@ -134,10 +133,7 @@ public:
BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(tip) == height, strprintf("Test %i for StateSinceHeight", num));
BOOST_CHECK_MESSAGE(checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed, strprintf("Test %i for StateSinceHeight (delayed)", num));
BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (always active)", num));
-
- // never active may go from DEFINED -> FAILED at the first period
- const auto never_height = checker_never[i].GetStateSinceHeightFor(tip);
- BOOST_CHECK_MESSAGE(never_height == 0 || never_height == checker_never[i].Period(paramsDummy), strprintf("Test %i for StateSinceHeight (never active)", num));
+ BOOST_CHECK_MESSAGE(checker_never[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (never active)", num));
}
}
num++;
@@ -170,7 +166,7 @@ public:
BOOST_CHECK_MESSAGE(got == exp, strprintf("Test %i for %s height %d (got %s)", num, StateName(exp), height, StateName(got)));
BOOST_CHECK_MESSAGE(got_delayed == exp_delayed, strprintf("Test %i for %s height %d (got %s; delayed case)", num, StateName(exp_delayed), height, StateName(got_delayed)));
BOOST_CHECK_MESSAGE(got_always == ThresholdState::ACTIVE, strprintf("Test %i for ACTIVE height %d (got %s; always active case)", num, height, StateName(got_always)));
- BOOST_CHECK_MESSAGE(got_never == ThresholdState::DEFINED|| got_never == ThresholdState::FAILED, strprintf("Test %i for DEFINED/FAILED height %d (got %s; never active case)", num, height, StateName(got_never)));
+ BOOST_CHECK_MESSAGE(got_never == ThresholdState::FAILED, strprintf("Test %i for FAILED height %d (got %s; never active case)", num, height, StateName(got_never)));
}
}
num++;
@@ -270,7 +266,7 @@ BOOST_AUTO_TEST_CASE(versionbits_sanity)
// Check min_activation_height is on a retarget boundary
BOOST_CHECK_EQUAL(mainnetParams.vDeployments[i].min_activation_height % mainnetParams.nMinerConfirmationWindow, 0U);
// Check min_activation_height is 0 for ALWAYS_ACTIVE and never active deployments
- if (mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || mainnetParams.vDeployments[i].nTimeout <= 1230768000) {
+ if (mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) {
BOOST_CHECK_EQUAL(mainnetParams.vDeployments[i].min_activation_height, 0);
}
@@ -304,8 +300,9 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
// should not be any signalling for first block
BOOST_CHECK_EQUAL(ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
- // always active deployments shouldn't need to be tested further
+ // always/never active deployments shouldn't need to be tested further
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) return;
+ if (nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) return;
BOOST_REQUIRE(nStartTime < nTimeout);
BOOST_REQUIRE(nStartTime >= 0);
@@ -448,6 +445,15 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
}
{
+ // Use regtest/testdummy to ensure we always exercise some
+ // deployment that's not always/never active
+ ArgsManager args;
+ args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999"); // January 1, 2008 - December 31, 2008
+ const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST);
+ check_computeblockversion(chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY);
+ }
+
+ {
// Use regtest/testdummy to ensure we always exercise the
// min_activation_height test, even if we're not using that in a
// live deployment