Skip to content

Commit 4f42284

Browse files
author
MarcoFalke
committed
Merge #17140: test: Fix bug in blockfilter_index_tests.
f59bbb6 test: Fix bug in blockfilter_index_tests. (Jim Posen) Pull request description: The test case tests a chain reorganization, however the two chains were generated in the same manner and thus produced the same blocks. This issue was [pointed out](bitcoin/bitcoin#14121 (comment)) by MarcoFalke. ACKs for top commit: MarcoFalke: Thanks! ACK f59bbb6 (looked at the diff on GitHub, didn't compile, nor run tests) Tree-SHA512: a2f063ae9312051ffc2a3fcc1116a6a8ac09beeef261bc40aa3ff7270ff4de22a790eb19fec6b15ba1eb46e78f1f317bfd91472d8581b95bb9441a56b102554e
2 parents 46d6930 + f59bbb6 commit 4f42284

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/test/blockfilter_index_tests.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,23 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
167167
LOCK(cs_main);
168168
tip = ::ChainActive().Tip();
169169
}
170-
CScript coinbase_script_pub_key = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
170+
CKey coinbase_key_A, coinbase_key_B;
171+
coinbase_key_A.MakeNewKey(true);
172+
coinbase_key_B.MakeNewKey(true);
173+
CScript coinbase_script_pub_key_A = GetScriptForDestination(PKHash(coinbase_key_A.GetPubKey()));
174+
CScript coinbase_script_pub_key_B = GetScriptForDestination(PKHash(coinbase_key_B.GetPubKey()));
171175
std::vector<std::shared_ptr<CBlock>> chainA, chainB;
172-
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainA));
173-
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainB));
176+
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_A, 10, chainA));
177+
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_B, 10, chainB));
174178

175179
// Check that new blocks on chain A get indexed.
176180
uint256 chainA_last_header = last_header;
177181
for (size_t i = 0; i < 2; i++) {
178182
const auto& block = chainA[i];
179183
BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr));
180-
184+
}
185+
for (size_t i = 0; i < 2; i++) {
186+
const auto& block = chainA[i];
181187
const CBlockIndex* block_index;
182188
{
183189
LOCK(cs_main);
@@ -193,7 +199,9 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
193199
for (size_t i = 0; i < 3; i++) {
194200
const auto& block = chainB[i];
195201
BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr));
196-
202+
}
203+
for (size_t i = 0; i < 3; i++) {
204+
const auto& block = chainB[i];
197205
const CBlockIndex* block_index;
198206
{
199207
LOCK(cs_main);
@@ -221,7 +229,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
221229
// Reorg back to chain A.
222230
for (size_t i = 2; i < 4; i++) {
223231
const auto& block = chainA[i];
224-
BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr));
232+
BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr));
225233
}
226234

227235
// Check that chain A and B blocks can be retrieved.

0 commit comments

Comments
 (0)