diff options
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | contrib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 2 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 14 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 10 | ||||
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 4 | ||||
-rw-r--r-- | tests/unit_tests/main.cpp | 31 | ||||
-rw-r--r-- | tests/unit_tests/serialization.cpp | 8 |
10 files changed, 63 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dadd528db..3eddfca0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) enable_testing() option(BUILD_DOCUMENTATION "Build the Doxygen documentation." ON) +option(BUILD_TESTS "Build tests." OFF) # Check whether we're on a 32-bit or 64-bit system if(CMAKE_SIZEOF_VOID_P EQUAL "8") @@ -713,20 +714,13 @@ if(SODIUM_LIBRARY) set(ZMQ_LIB "${ZMQ_LIB};${SODIUM_LIBRARY}") endif() -option(BUILD_TESTS "Build tests." OFF) +add_subdirectory(contrib) +add_subdirectory(src) if(BUILD_TESTS) add_subdirectory(tests) endif() -# warnings are cleared only for GCC on Linux -if (NOT (MINGW OR APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY)) -add_compile_options("${WARNINGS_AS_ERRORS_FLAG}") # applies only to targets that follow -endif() - -add_subdirectory(contrib) -add_subdirectory(src) - if(BUILD_DOCUMENTATION) set(DOC_GRAPHS "YES" CACHE STRING "Create dependency graphs (needs graphviz)") set(DOC_FULLGRAPHS "NO" CACHE STRING "Create call/callee graphs (large)") diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 7bd411aed..e7c501ed2 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -26,5 +26,10 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# warnings are cleared only for GCC on Linux +if (NOT (MINGW OR APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY)) + add_compile_options("${WARNINGS_AS_ERRORS_FLAG}") # applies only to targets that follow +endif() + add_subdirectory(epee) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 57ff28bfc..6fb08b645 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,6 +34,11 @@ if (WIN32 OR STATIC) add_definitions(-DMINIUPNP_STATICLIB) endif () +# warnings are cleared only for GCC on Linux +if (NOT (MINGW OR APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY)) + add_compile_options("${WARNINGS_AS_ERRORS_FLAG}") # applies only to targets that follow +endif() + function (monero_private_headers group) source_group("${group}\\Private" FILES diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 949d95ade..3979a5edf 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2933,7 +2933,7 @@ void BlockchainLMDB::get_output_key(const uint64_t &amount, const std::vector<ui MDEBUG("Partial result: " << outputs.size() << "/" << offsets.size()); break; } - throw1(OUTPUT_DNE((std::string("Attempting to get output pubkey by global index (amount ") + boost::lexical_cast<std::string>(amount) + ", index " + boost::lexical_cast<std::string>(index) + ", count " + boost::lexical_cast<std::string>(get_num_outputs(amount)) + "), but key does not exist").c_str())); + throw1(OUTPUT_DNE((std::string("Attempting to get output pubkey by global index (amount ") + boost::lexical_cast<std::string>(amount) + ", index " + boost::lexical_cast<std::string>(index) + ", count " + boost::lexical_cast<std::string>(get_num_outputs(amount)) + "), but key does not exist (current height " + boost::lexical_cast<std::string>(height()) + ")").c_str())); } else if (get_result) throw0(DB_ERROR(lmdb_error("Error attempting to retrieve an output pubkey from the db", get_result).c_str())); diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 53dfc175f..933914363 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -188,7 +188,12 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke { try { - m_db->get_output_key(tx_in_to_key.amount, absolute_offsets, outputs); + m_db->get_output_key(tx_in_to_key.amount, absolute_offsets, outputs, true); + if (absolute_offsets.size() != outputs.size()) + { + MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount); + return false; + } } catch (...) { @@ -208,7 +213,12 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke add_offsets.push_back(absolute_offsets[i]); try { - m_db->get_output_key(tx_in_to_key.amount, add_offsets, add_outputs); + m_db->get_output_key(tx_in_to_key.amount, add_offsets, add_outputs, true); + if (add_offsets.size() != add_outputs.size()) + { + MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount); + return false; + } } catch (...) { diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index cec3f7225..61f844612 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1029,7 +1029,15 @@ namespace cryptonote block_verification_context bvc = boost::value_initialized<block_verification_context>(); m_miner.pause(); std::list<block_complete_entry> blocks; - blocks.push_back(get_block_complete_entry(b, m_mempool)); + try + { + blocks.push_back(get_block_complete_entry(b, m_mempool)); + } + catch (const std::exception &e) + { + m_miner.resume(); + return false; + } prepare_handle_incoming_blocks(blocks); m_blockchain_storage.add_new_block(b, bvc); cleanup_handle_incoming_blocks(true); diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index d5f090700..c7efcf074 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -101,4 +101,4 @@ endif () add_test( NAME unit_tests - COMMAND unit_tests "${TEST_DATA_DIR}") + COMMAND unit_tests --data-dir "${TEST_DATA_DIR}") diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index f6cb0c163..a13081491 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -37,9 +37,7 @@ #include <sstream> #include <vector> -#ifdef _WIN32 -# include <winsock.h> -#else +#ifndef _WIN32 # include <arpa/inet.h> #endif diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index b2abad942..1706c43c9 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -31,31 +31,44 @@ #include "gtest/gtest.h" #include <boost/filesystem.hpp> +#include <boost/program_options.hpp> #include "include_base_utils.h" +#include "common/command_line.h" #include "unit_tests_utils.h" +namespace po = boost::program_options; + boost::filesystem::path unit_test::data_dir; int main(int argc, char** argv) { + epee::string_tools::set_module_name_and_folder(argv[0]); mlog_configure(mlog_get_default_log_path("unit_tests.log"), true); epee::debug::get_set_enable_assert(true, false); ::testing::InitGoogleTest(&argc, argv); - // Process remaining arguments - if (argc == 2 && argv[1] != NULL) { // one arg: path to dir with test data - unit_test::data_dir = argv[1]; - } else if (argc == 1) { // legacy: assume test binaries in 'build/release' - epee::string_tools::set_module_name_and_folder(argv[0]); + po::options_description desc_options("Command line options"); + const command_line::arg_descriptor<std::string> arg_data_dir = {"data-dir", "Data files directory", "", true}; + command_line::add_arg(desc_options, command_line::arg_data_dir, ""); + + po::variables_map vm; + bool r = command_line::handle_error_helper(desc_options, [&]() + { + po::store(po::parse_command_line(argc, argv, desc_options), vm); + po::notify(vm); + return true; + }); + if (! r) + return 1; + + if (vm["data-dir"].defaulted()) unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder()) .parent_path().parent_path().parent_path().parent_path() .append("tests").append("data"); - } else { - std::cerr << "Usage: " << argv[0] << " [<path-to-test-data-dir>]" << std::endl; - return 1; - } + else + unit_test::data_dir = command_line::get_arg(vm, arg_data_dir); return RUN_ALL_TESTS(); } diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 202c8718f..011082d1c 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -677,7 +677,7 @@ TEST(Serialization, portability_wallet) bool r = false; try { - w.load(wallet_file.native(), password); + w.load(wallet_file.string(), password); r = true; } catch (const exception& e) @@ -794,7 +794,7 @@ TEST(Serialization, portability_outputs) // read file const boost::filesystem::path filename = unit_test::data_dir / "outputs"; std::string data; - bool r = epee::file_io_utils::load_file_to_string(filename.native(), data); + bool r = epee::file_io_utils::load_file_to_string(filename.string(), data); ASSERT_TRUE(r); const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC); ASSERT_FALSE(data.size() < magiclen || memcmp(data.data(), OUTPUT_EXPORT_FILE_MAGIC, magiclen)); @@ -910,7 +910,7 @@ TEST(Serialization, portability_unsigned_tx) const boost::filesystem::path filename = unit_test::data_dir / "unsigned_monero_tx"; std::string s; const bool testnet = true; - bool r = epee::file_io_utils::load_file_to_string(filename.native(), s); + bool r = epee::file_io_utils::load_file_to_string(filename.string(), s); ASSERT_TRUE(r); const size_t magiclen = strlen(UNSIGNED_TX_PREFIX); ASSERT_FALSE(strncmp(s.c_str(), UNSIGNED_TX_PREFIX, magiclen)); @@ -1058,7 +1058,7 @@ TEST(Serialization, portability_signed_tx) const boost::filesystem::path filename = unit_test::data_dir / "signed_monero_tx"; const bool testnet = true; std::string s; - bool r = epee::file_io_utils::load_file_to_string(filename.native(), s); + bool r = epee::file_io_utils::load_file_to_string(filename.string(), s); ASSERT_TRUE(r); const size_t magiclen = strlen(SIGNED_TX_PREFIX); ASSERT_FALSE(strncmp(s.c_str(), SIGNED_TX_PREFIX, magiclen)); |