From 95393ed7d3349db7386678b992173a03c86b74fd Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 17 Oct 2019 08:21:32 -0400 Subject: [PATCH] Merge #17140: test: Fix bug in blockfilter_index_tests. f59bbb61af5055844c16939a4f8e58c4f73843c1 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](https://github.com/bitcoin/bitcoin/pull/14121#discussion_r334282663) by MarcoFalke. ACKs for top commit: MarcoFalke: Thanks! ACK f59bbb61af5055844c16939a4f8e58c4f73843c1 (looked at the diff on GitHub, didn't compile, nor run tests) Tree-SHA512: a2f063ae9312051ffc2a3fcc1116a6a8ac09beeef261bc40aa3ff7270ff4de22a790eb19fec6b15ba1eb46e78f1f317bfd91472d8581b95bb9441a56b102554e --- src/test/blockfilter_index_tests.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index e93ebad60d4987..7a3c96b2bd4099 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -151,17 +151,23 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup) LOCK(cs_main); tip = ::ChainActive().Tip(); } - CScript coinbase_script_pub_key = GetScriptForDestination(coinbaseKey.GetPubKey().GetID()); + CKey coinbase_key_A, coinbase_key_B; + coinbase_key_A.MakeNewKey(true); + coinbase_key_B.MakeNewKey(true); + CScript coinbase_script_pub_key_A = GetScriptForDestination(coinbase_key_A.GetPubKey().GetID()); + CScript coinbase_script_pub_key_B = GetScriptForDestination(coinbase_key_B.GetPubKey().GetID()); std::vector> chainA, chainB; - BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainA)); - BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainB)); + BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_A, 10, chainA)); + BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_B, 10, chainB)); // Check that new blocks on chain A get indexed. uint256 chainA_last_header = last_header; for (size_t i = 0; i < 2; i++) { const auto& block = chainA[i]; BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr)); - + } + for (size_t i = 0; i < 2; i++) { + const auto& block = chainA[i]; const CBlockIndex* block_index; { LOCK(cs_main); @@ -177,7 +183,9 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup) for (size_t i = 0; i < 3; i++) { const auto& block = chainB[i]; BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr)); - + } + for (size_t i = 0; i < 3; i++) { + const auto& block = chainB[i]; const CBlockIndex* block_index; { LOCK(cs_main); @@ -205,7 +213,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup) // Reorg back to chain A. for (size_t i = 2; i < 4; i++) { const auto& block = chainA[i]; - BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr)); + BOOST_REQUIRE(ProcessNewBlock(Params(), block, true, nullptr)); } // Check that chain A and B blocks can be retrieved.