Skip to content

Commit fa6183d

Browse files
author
MarcoFalke
committed
test: Remove option to make TestChain100Setup non-deterministic
Seems odd to have an option for non-deterministic tests when the goal should be for all tests to be deterministic. Can be reviewed with `--ignore-all-space`.
1 parent fa732bc commit fa6183d

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

src/test/util/setup_common.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,17 @@ 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(), true);
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() ==
@@ -232,13 +223,10 @@ TestChain100Setup::TestChain100Setup(bool deterministic)
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

0 commit comments

Comments
 (0)