Skip to content

Commit

Permalink
Add assert check for hash in block_database::unindex
Browse files Browse the repository at this point in the history
Closes #238
  • Loading branch information
kulpreet committed Nov 18, 2018
1 parent d6aa833 commit 9ec99dc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/databases/block_database.cpp
Expand Up @@ -455,6 +455,8 @@ bool block_database::unindex(const hash_digest& hash, size_t height,
if (!element)
return false;

BITCOIN_ASSERT(hash == element.key());

const auto original = index(element, false, candidate);
pop_index(height, manager);
return true;
Expand Down
6 changes: 0 additions & 6 deletions test/databases/block_database.cpp
Expand Up @@ -58,7 +58,6 @@ BOOST_FIXTURE_TEST_SUITE(block_database_tests, block_database_directory_setup_fi

BOOST_AUTO_TEST_CASE(block_database__test)
{
// TODO: replace.
static const auto settings = bc::settings(bc::config::settings::mainnet);
chain::block block0 = settings.genesis_block;
block0.set_transactions(
Expand Down Expand Up @@ -166,11 +165,6 @@ BOOST_AUTO_TEST_CASE(block_database__test)
// get 4a without indexing it should fail
BOOST_REQUIRE(!instance.get(h4a));

// TODO: The test fails because the hash of element at height 3 is
// not compared to h4a in the unindex method
// // unindex block 4a without indexing it should fail
// BOOST_REQUIRE(!instance.unindex(h4a, 3, true));

// unindex block 0 - 4 from candidate index
instance.unindex(h3, 3, true);
instance.unindex(h2, 2, true);
Expand Down

0 comments on commit 9ec99dc

Please sign in to comment.