forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On testnet create min diff template after 20 mins
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2025 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 <common/system.h> | ||
#include <interfaces/mining.h> | ||
#include <node/miner.h> | ||
#include <util/time.h> | ||
#include <validation.h> | ||
|
||
#include <test/util/setup_common.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
using interfaces::BlockTemplate; | ||
using interfaces::Mining; | ||
using node::BlockAssembler; | ||
|
||
namespace testnet4_miner_tests { | ||
|
||
struct Testnet4MinerTestingSetup : public Testnet4Setup { | ||
std::unique_ptr<Mining> MakeMining() | ||
{ | ||
return interfaces::MakeMining(m_node); | ||
} | ||
}; | ||
} // namespace testnet4_miner_tests | ||
|
||
BOOST_FIXTURE_TEST_SUITE(testnet4_miner_tests, Testnet4MinerTestingSetup) | ||
|
||
BOOST_AUTO_TEST_CASE(MiningInterface) | ||
{ | ||
auto mining{MakeMining()}; | ||
BOOST_REQUIRE(mining); | ||
|
||
BlockAssembler::Options options; | ||
std::unique_ptr<BlockTemplate> block_template; | ||
|
||
// Set node time a few minutes past the testnet4 genesis block | ||
{ | ||
LOCK(cs_main); | ||
SetMockTime(m_node.chainman->ActiveChain().Tip()->GetBlockTime() + 3 * 60); | ||
} | ||
|
||
block_template = mining->createNewBlock(options); | ||
BOOST_REQUIRE(block_template); | ||
|
||
// The template should use the mocked system time | ||
BOOST_REQUIRE_EQUAL(std::chrono::seconds(block_template->getBlockHeader().nTime), GetMockTime()); | ||
|
||
// waitNext() should return nullptr because there is no better template | ||
auto should_be_nullptr = block_template->waitNext(1, MillisecondsDouble{0}); | ||
BOOST_REQUIRE(should_be_nullptr == nullptr); | ||
|
||
// Except when 20 minutes have gone by (on test networks) | ||
{ | ||
LOCK(cs_main); | ||
SetMockTime(m_node.chainman->ActiveChain().Tip()->GetBlockTime() + 20 * 60 + 1); | ||
} | ||
block_template = block_template->waitNext(1, MillisecondsDouble{0}); | ||
BOOST_REQUIRE(block_template); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters