diff options
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/unit_tests/block_reward.cpp | 18 | ||||
-rw-r--r-- | tests/unit_tests/levin.cpp | 109 |
3 files changed, 111 insertions, 20 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index a5984b2c9..33ef93288 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -101,7 +101,7 @@ set(unit_tests_sources set(unit_tests_headers unit_tests_utils.h) -add_executable(unit_tests +monero_add_minimal_executable(unit_tests ${unit_tests_sources} ${unit_tests_headers}) target_link_libraries(unit_tests @@ -144,6 +144,6 @@ add_test( NAME unit_tests COMMAND unit_tests --data-dir "${TEST_DATA_DIR}") -add_executable(test_notifier test_notifier.cpp) +monero_add_minimal_executable(test_notifier test_notifier.cpp) target_link_libraries(test_notifier ${EXTRA_LIBRARIES}) set_property(TARGET test_notifier PROPERTY FOLDER "tests") diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp index 5f3335981..2f0ea92f3 100644 --- a/tests/unit_tests/block_reward.cpp +++ b/tests/unit_tests/block_reward.cpp @@ -138,24 +138,6 @@ namespace ASSERT_FALSE(m_block_not_too_big); } -#ifdef __x86_64__ // For 64-bit systems only, because block size is limited to size_t. - TEST_F(block_reward_and_current_block_weight, fails_on_huge_median_size) - { -#if !defined(NDEBUG) - size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2); - ASSERT_DEATH(do_test(huge_size, huge_size + 1), ""); -#endif - } - - TEST_F(block_reward_and_current_block_weight, fails_on_huge_block_weight) - { -#if !defined(NDEBUG) - size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2); - ASSERT_DEATH(do_test(huge_size - 2, huge_size), ""); -#endif - } -#endif // __x86_64__ - //-------------------------------------------------------------------------------------------------------------------- class block_reward_and_last_block_weights : public ::testing::Test { diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp index e7f9e126f..22638942d 100644 --- a/tests/unit_tests/levin.cpp +++ b/tests/unit_tests/levin.cpp @@ -619,6 +619,61 @@ TEST_F(levin_notify, stem_without_padding) } } +TEST_F(levin_notify, stem_no_outs_without_padding) +{ + cryptonote::levin::notify notifier = make_notifier(0, true, false); + + for (unsigned count = 0; count < 10; ++count) + add_connection(true); + + { + const auto status = notifier.get_status(); + EXPECT_FALSE(status.has_noise); + EXPECT_FALSE(status.connections_filled); + } + notifier.new_out_connection(); + io_service_.poll(); + + std::vector<cryptonote::blobdata> txs(2); + txs[0].resize(100, 'f'); + txs[1].resize(200, 'e'); + + std::vector<cryptonote::blobdata> sorted_txs = txs; + std::sort(sorted_txs.begin(), sorted_txs.end()); + + ASSERT_EQ(10u, contexts_.size()); + + auto context = contexts_.begin(); + EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); + + io_service_.reset(); + ASSERT_LT(0u, io_service_.poll()); + EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); + if (events_.has_stem_txes()) + EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); + + + notifier.run_fluff(); + ASSERT_LT(0u, io_service_.poll()); + + std::size_t send_count = 0; + EXPECT_EQ(0u, context->process_send_queue()); + for (++context; context != contexts_.end(); ++context) + { + send_count += context->process_send_queue(); + } + + EXPECT_EQ(9u, send_count); + ASSERT_EQ(9u, receiver_.notified_size()); + for (unsigned count = 0; count < 9u; ++count) + { + auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second; + EXPECT_EQ(sorted_txs, notification.txs); + EXPECT_TRUE(notification._.empty()); + EXPECT_TRUE(notification.dandelionpp_fluff); + } +} + TEST_F(levin_notify, local_without_padding) { cryptonote::levin::notify notifier = make_notifier(0, true, false); @@ -934,6 +989,60 @@ TEST_F(levin_notify, stem_with_padding) } } +TEST_F(levin_notify, stem_no_outs_with_padding) +{ + cryptonote::levin::notify notifier = make_notifier(0, true, true); + + for (unsigned count = 0; count < 10; ++count) + add_connection(true); + + { + const auto status = notifier.get_status(); + EXPECT_FALSE(status.has_noise); + EXPECT_FALSE(status.connections_filled); + } + notifier.new_out_connection(); + io_service_.poll(); + + std::vector<cryptonote::blobdata> txs(2); + txs[0].resize(100, 'f'); + txs[1].resize(200, 'e'); + + std::vector<cryptonote::blobdata> sorted_txs = txs; + std::sort(sorted_txs.begin(), sorted_txs.end()); + + ASSERT_EQ(10u, contexts_.size()); + + auto context = contexts_.begin(); + EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); + + io_service_.reset(); + ASSERT_LT(0u, io_service_.poll()); + EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); + if (events_.has_stem_txes()) + EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); + + notifier.run_fluff(); + ASSERT_LT(0u, io_service_.poll()); + + std::size_t send_count = 0; + EXPECT_EQ(0u, context->process_send_queue()); + for (++context; context != contexts_.end(); ++context) + { + send_count += context->process_send_queue(); + } + + EXPECT_EQ(9u, send_count); + ASSERT_EQ(9u, receiver_.notified_size()); + for (unsigned count = 0; count < 9u; ++count) + { + auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second; + EXPECT_EQ(sorted_txs, notification.txs); + EXPECT_FALSE(notification._.empty()); + EXPECT_TRUE(notification.dandelionpp_fluff); + } +} + TEST_F(levin_notify, local_with_padding) { cryptonote::levin::notify notifier = make_notifier(0, true, true); |