Skip to content

Commit 4ad83a9

Browse files
author
MarcoFalke
committed
Merge #21592: test: Remove option to make TestChain100Setup non-deterministic
fa6183d test: Remove option to make TestChain100Setup non-deterministic (MarcoFalke) fa732bc test: Use compressed keys in TestChain100Setup (MarcoFalke) Pull request description: Seems odd to have an option for non-deterministic tests when the goal should be for all tests to be deterministic. ACKs for top commit: jamesob: ACK bitcoin/bitcoin@fa6183d practicalswift: cr ACK fa6183d: patch looks deterministic! Tree-SHA512: 6897a9f36e0dfb7d63b25dd6984414b3ee8a62458ad232cb21ed5077184fdb0bc626996e4ac84ef0bdd452b9f17c54aac75a71575b8e723b84cac07c9f9d5611
2 parents 265a3a7 + fa6183d commit 4ad83a9

File tree

5 files changed

+14
-34
lines changed

5 files changed

+14
-34
lines changed

src/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class CRegTestParams : public CChainParams {
441441
m_assumeutxo_data = MapAssumeutxo{
442442
{
443443
110,
444-
{uint256S("0x76fd7334ac7c1baf57ddc0c626f073a655a35d98a4258cd1382c8cc2b8392e10"), 110},
444+
{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618"), 110},
445445
},
446446
{
447447
210,

src/test/util/setup_common.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,31 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
202202
}
203203
}
204204

205-
TestChain100Setup::TestChain100Setup(bool deterministic)
205+
TestChain100Setup::TestChain100Setup()
206206
{
207-
m_deterministic = deterministic;
208-
209-
if (m_deterministic) {
210-
SetMockTime(1598887952);
211-
constexpr std::array<unsigned char, 32> vchKey = {
212-
{
213-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
214-
}
215-
};
216-
coinbaseKey.Set(vchKey.begin(), vchKey.end(), false);
217-
} else {
218-
coinbaseKey.MakeNewKey(true);
219-
}
207+
SetMockTime(1598887952);
208+
constexpr std::array<unsigned char, 32> vchKey = {
209+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}};
210+
coinbaseKey.Set(vchKey.begin(), vchKey.end(), true);
220211

221212
// Generate a 100-block chain:
222213
this->mineBlocks(COINBASE_MATURITY);
223214

224-
if (m_deterministic) {
215+
{
225216
LOCK(::cs_main);
226217
assert(
227218
m_node.chainman->ActiveChain().Tip()->GetBlockHash().ToString() ==
228-
"49c95db1e470fed04496d801c9d8fbb78155d2c7f855232c918823d2c17d0cf6");
219+
"571d80a9967ae599cec0448b0b0ba1cfb606f584d8069bd7166b86854ba7a191");
229220
}
230221
}
231222

232223
void TestChain100Setup::mineBlocks(int num_blocks)
233224
{
234225
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
235-
for (int i = 0; i < num_blocks; i++)
236-
{
226+
for (int i = 0; i < num_blocks; i++) {
237227
std::vector<CMutableTransaction> noTxns;
238228
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
239-
if (m_deterministic) {
240-
SetMockTime(GetTime() + 1);
241-
}
229+
SetMockTime(GetTime() + 1);
242230
m_coinbase_txns.push_back(b.vtx[0]);
243231
}
244232
}
@@ -315,9 +303,7 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
315303
TestChain100Setup::~TestChain100Setup()
316304
{
317305
gArgs.ForceSetArg("-segwitheight", "0");
318-
if (m_deterministic) {
319-
SetMockTime(0);
320-
}
306+
SetMockTime(0);
321307
}
322308

323309
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const

src/test/util/setup_common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CScript;
112112
* Testing fixture that pre-creates a 100-block REGTEST-mode block chain
113113
*/
114114
struct TestChain100Setup : public RegTestingSetup {
115-
TestChain100Setup(bool deterministic = false);
115+
TestChain100Setup();
116116

117117
/**
118118
* Create a new block with just given transactions, coinbase paying to
@@ -143,16 +143,10 @@ struct TestChain100Setup : public RegTestingSetup {
143143

144144
~TestChain100Setup();
145145

146-
bool m_deterministic;
147146
std::vector<CTransactionRef> m_coinbase_txns; // For convenience, coinbase transactions
148147
CKey coinbaseKey; // private/public key needed to spend coinbase transactions
149148
};
150149

151-
152-
struct TestChain100DeterministicSetup : public TestChain100Setup {
153-
TestChain100DeterministicSetup() : TestChain100Setup(true) { }
154-
};
155-
156150
/**
157151
* Make a test setup that has disk access to the debug.log file disabled. Can
158152
* be used in "hot loops", for example fuzzing or benchmarking.

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleati
200200
}
201201

202202
//! Test basic snapshot activation.
203-
BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100DeterministicSetup)
203+
BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
204204
{
205205
ChainstateManager& chainman = *Assert(m_node.chainman);
206206

src/test/validation_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)
135135
}
136136

137137
const auto out110 = *ExpectedAssumeutxo(110, *params);
138-
BOOST_CHECK_EQUAL(out110.hash_serialized, uint256S("76fd7334ac7c1baf57ddc0c626f073a655a35d98a4258cd1382c8cc2b8392e10"));
138+
BOOST_CHECK_EQUAL(out110.hash_serialized, uint256S("1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618"));
139139
BOOST_CHECK_EQUAL(out110.nChainTx, (unsigned int)110);
140140

141141
const auto out210 = *ExpectedAssumeutxo(210, *params);

0 commit comments

Comments
 (0)