From b39c8ea0de210c586f2a3a6eccf1c7ea1b1ad5e0 Mon Sep 17 00:00:00 2001 From: timemarkovqtum Date: Wed, 3 Apr 2024 15:36:39 +0200 Subject: [PATCH] Fix unit tests --- src/kernel/chainparams.cpp | 12 +++-------- .../validation_chainstatemanager_tests.cpp | 20 +++++++++---------- src/test/validation_flush_tests.cpp | 4 ++-- src/test/validation_tests.cpp | 10 +++++----- src/wallet/scriptpubkeyman.cpp | 2 +- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp index 5dfad02b53..f39c3a2af7 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -705,15 +705,9 @@ class CUnitTestParams : public CRegTestParams m_assumeutxo_data = { { .height = 2010, - .hash_serialized = AssumeutxoHash{uint256S("0xf3ad83776715ee9b09a7a43421b6fe17701fb2247370a4ea9fcf0b073639cac9")}, - .nChainTx = 2010, - .blockhash = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000") - }, - { - .height = 2100, - .hash_serialized = AssumeutxoHash{uint256S("0x677f8902ca481677862d19fbe8c6214f596c8b475aabfe4273361485fc4e6fb4")}, - .nChainTx = 2100, - .blockhash = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000") + .hash_serialized = AssumeutxoHash{uint256S("0x62528c92991cbedf47bdf3f0f5a0ad1e07bce4b2a35500beabe3f87fa5cca44f")}, + .nChainTx = 2011, + .blockhash = uint256S("0x292911929ab59409569a86bae416da0ba697fd7086b107ddd0a8eeaddba91b4d") } }; } diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 34565d41f7..1847d9c888 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -57,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup) // Get to a valid assumeutxo tip (per chainparams); mineBlocks(10); - BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 110); + BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 2010); auto active_tip = WITH_LOCK(manager.GetMutex(), return manager.ActiveTip()); auto exp_tip = c1.m_chain.Tip(); BOOST_CHECK_EQUAL(active_tip, exp_tip); @@ -92,10 +92,10 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager, TestChain100Setup) auto& active_chain2 = WITH_LOCK(manager.GetMutex(), return manager.ActiveChain()); BOOST_CHECK_EQUAL(&active_chain2, &c2.m_chain); - BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 110); + BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 2010); mineBlocks(1); - BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 111); - BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return c1.m_chain.Height()), 110); + BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 2011); + BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return c1.m_chain.Height()), 2010); auto active_tip2 = WITH_LOCK(manager.GetMutex(), return manager.ActiveTip()); BOOST_CHECK_EQUAL(active_tip, active_tip2->pprev); @@ -426,7 +426,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup) // Blocks in range [assumed_valid_start_idx, last_assumed_valid_idx) will be // marked as assumed-valid and not having data. const int expected_assumed_valid{20}; - const int last_assumed_valid_idx{111}; + const int last_assumed_valid_idx{2011}; const int assumed_valid_start_idx = last_assumed_valid_idx - expected_assumed_valid; // Mine to height 120, past the hardcoded regtest assumeutxo snapshot at @@ -436,7 +436,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup) CBlockIndex* validated_tip{nullptr}; CBlockIndex* assumed_base{nullptr}; CBlockIndex* assumed_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; - BOOST_CHECK_EQUAL(assumed_tip->nHeight, 120); + BOOST_CHECK_EQUAL(assumed_tip->nHeight, 2020); auto reload_all_block_indexes = [&]() { // For completeness, we also reset the block sequence counters to @@ -497,10 +497,10 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup) cs2.m_chain.SetTip(*assumed_base); // Sanity check test variables. - BOOST_CHECK_EQUAL(num_indexes, 121); // 121 total blocks, including genesis - BOOST_CHECK_EQUAL(assumed_tip->nHeight, 120); // original chain has height 120 - BOOST_CHECK_EQUAL(validated_tip->nHeight, 90); // current cs1 chain has height 90 - BOOST_CHECK_EQUAL(assumed_base->nHeight, 110); // current cs2 chain has height 110 + BOOST_CHECK_EQUAL(num_indexes, 2021); // 121 total blocks, including genesis + BOOST_CHECK_EQUAL(assumed_tip->nHeight, 2020); // original chain has height 120 + BOOST_CHECK_EQUAL(validated_tip->nHeight, 1990); // current cs1 chain has height 90 + BOOST_CHECK_EQUAL(assumed_base->nHeight, 2010); // current cs2 chain has height 110 // Regenerate cs1.setBlockIndexCandidates and cs2.setBlockIndexCandidate and // check contents below. diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp index 7398091215..6d1a66fc57 100644 --- a/src/test/validation_flush_tests.cpp +++ b/src/test/validation_flush_tests.cpp @@ -36,8 +36,8 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate) BOOST_TEST_MESSAGE("CCoinsViewCache memory usage: " << view.DynamicMemoryUsage()); }; - // PoolResource defaults to 256 KiB that will be allocated, so we'll take that and make it a bit larger. - constexpr size_t MAX_COINS_CACHE_BYTES = 262144 + 512; + // PoolResource defaults to 512 KiB that will be allocated, so we'll take that and make it a bit larger. + constexpr size_t MAX_COINS_CACHE_BYTES = 524288 + 512; // Without any coins in the cache, we shouldn't need to flush. BOOST_TEST( diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp index e404aca288..af16132e30 100644 --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -173,12 +173,12 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo) } const auto out110 = *params->AssumeutxoForHeight(2010); - BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "f3ad83776715ee9b09a7a43421b6fe17701fb2247370a4ea9fcf0b073639cac9"); - BOOST_CHECK_EQUAL(out110.nChainTx, 2010U); + BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "62528c92991cbedf47bdf3f0f5a0ad1e07bce4b2a35500beabe3f87fa5cca44f"); + BOOST_CHECK_EQUAL(out110.nChainTx, 2011U); - const auto out110_2 = *params->AssumeutxoForBlockhash(uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")); - BOOST_CHECK_EQUAL(out110_2.hash_serialized.ToString(), "f3ad83776715ee9b09a7a43421b6fe17701fb2247370a4ea9fcf0b073639cac9"); - BOOST_CHECK_EQUAL(out110_2.nChainTx, 2010U); + const auto out110_2 = *params->AssumeutxoForBlockhash(uint256S("292911929ab59409569a86bae416da0ba697fd7086b107ddd0a8eeaddba91b4d")); + BOOST_CHECK_EQUAL(out110_2.hash_serialized.ToString(), "62528c92991cbedf47bdf3f0f5a0ad1e07bce4b2a35500beabe3f87fa5cca44f"); + BOOST_CHECK_EQUAL(out110_2.nChainTx, 2011U); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 101d60ac1b..e0468a67df 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -2033,7 +2033,7 @@ util::Result DescriptorScriptPubKeyMan::GetNewDestination(const } CTxDestination dest; - if (!ExtractDestination(scripts_temp[0], dest)) { + if (!ExtractDestination(scripts_temp[0], dest, nullptr, true)) { return util::Error{_("Error: Cannot extract destination from the generated scriptpubkey")}; // shouldn't happen } m_wallet_descriptor.next_index++;