diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index 71300974..e8778b66 100644 --- a/src/wallet/wallet_chain_shortener.cpp +++ b/src/wallet/wallet_chain_shortener.cpp @@ -134,7 +134,7 @@ void wallet_chain_shortener::get_short_chain_history(std::list& id uint64_t current_back_offset = ids.size()+1; //self check - THROW_IF_FALSE_WALLET_INT_ERR_EX(current_back_offset == sz - i + 1, "Inernal error: current_back_offset{" << current_back_offset << "} == sz-i{" << sz << " - " << i << "} is not equal"); + THROW_IF_FALSE_WALLET_INT_ERR_EX(current_back_offset == sz - i + 1 || !count, "Inernal error: current_back_offset{" << current_back_offset << "} == sz-i{" << sz << " - " << i << "} is not equal"); uint64_t current_offset_distance = 1; while (current_back_offset < sz) diff --git a/tests/unit_tests/wallet_chain_shortener_test.cpp b/tests/unit_tests/wallet_chain_shortener_test.cpp index 0a228579..6b2c0f0a 100644 --- a/tests/unit_tests/wallet_chain_shortener_test.cpp +++ b/tests/unit_tests/wallet_chain_shortener_test.cpp @@ -25,6 +25,31 @@ TEST(wallet_chain_shortener, wallet_chain_shortener) { LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL); } + + + ws.detach(counter - 10000); + short_chain.clear(); + ws.get_short_chain_history(short_chain); + for (auto& id : short_chain) + { + LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL); + } + + for (counter = counter - 10000 + 1; counter != 1000000; counter++) + { + crypto::hash id_ = AUTO_VAL_INIT(id_); + *((uint64_t*)&id_) = counter; + + ws.push_new_block_id(id_, counter); + } + + short_chain.clear(); + ws.get_short_chain_history(short_chain); + for (auto& id : short_chain) + { + LOG_PRINT_L0("{" << *((uint64_t*)&id) << "}{" << counter - *((uint64_t*)&id) << "}" << ENDL); + } + LOG_PRINT_L0("Finished"); }