Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Apr 3, 2024
1 parent 11fe439 commit b39c8ea
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
12 changes: 3 additions & 9 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
};
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/test/validation_flush_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/test/validation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ util::Result<CTxDestination> 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++;
Expand Down

0 comments on commit b39c8ea

Please sign in to comment.