Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent 0a89050 commit cc7630a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 18 additions & 20 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ TEST (active_transactions, keep_local)
// ASSERT_EQ (1, node.scheduler.size ());
}

TEST (active_transactions, inactive_votes_cache)
TEST (inactive_votes_cache, basic)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
Expand All @@ -258,7 +258,7 @@ TEST (active_transactions, inactive_votes_cache)
/**
* This test case confirms that a non final vote cannot cause an election to become confirmed
*/
TEST (active_transactions, inactive_votes_cache_non_final)
TEST (inactive_votes_cache, non_final)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
Expand All @@ -284,7 +284,7 @@ TEST (active_transactions, inactive_votes_cache_non_final)
ASSERT_FALSE (election->confirmed ());
}

TEST (active_transactions, inactive_votes_cache_fork)
TEST (inactive_votes_cache, fork)
{
nano::test::system system{ 1 };
auto & node = *system.nodes[0];
Expand Down Expand Up @@ -324,7 +324,7 @@ TEST (active_transactions, inactive_votes_cache_fork)
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

TEST (active_transactions, inactive_votes_cache_existing_vote)
TEST (inactive_votes_cache, existing_vote)
{
nano::test::system system;
nano::node_config node_config = system.default_config ();
Expand Down Expand Up @@ -364,12 +364,13 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
ASSERT_EQ (send->hash (), last_vote1.hash);
ASSERT_EQ (nano::vote::timestamp_min * 1, last_vote1.timestamp);
// Attempt to change vote with inactive_votes_cache
nano::unique_lock<nano::mutex> active_lock (node.active.mutex);
node.vote_cache.vote (send->hash (), vote1);
auto cache = node.vote_cache.find (send->hash ());
ASSERT_TRUE (cache);
ASSERT_EQ (1, cache->voters ().size ());
cache->fill (election);
node.vote_cache.vote (vote1);
auto cached = node.vote_cache.find (send->hash ());
ASSERT_EQ (1, cached.size ());
for (auto const & cached_vote : cached)
{
node.active.vote (cached_vote);
}
// Check that election data is not changed
ASSERT_EQ (2, election->votes ().size ());
auto last_vote2 (election->votes ()[key.pub]);
Expand All @@ -379,7 +380,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
ASSERT_EQ (0, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

TEST (active_transactions, inactive_votes_cache_multiple_votes)
TEST (inactive_votes_cache, multiple_votes)
{
nano::test::system system;
nano::node_config node_config = system.default_config ();
Expand Down Expand Up @@ -425,8 +426,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
auto vote2 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, 0, 0);
node.vote_processor.vote (vote2, std::make_shared<nano::transport::inproc::channel> (node, node));

ASSERT_TIMELY (5s, node.vote_cache.find (send1->hash ()));
ASSERT_TIMELY_EQ (5s, node.vote_cache.find (send1->hash ())->voters ().size (), 2);
ASSERT_TIMELY_EQ (5s, node.vote_cache.find (send1->hash ()).size (), 2);
ASSERT_EQ (1, node.vote_cache.size ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
std::shared_ptr<nano::election> election;
Expand All @@ -435,7 +435,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
ASSERT_EQ (2, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

TEST (active_transactions, inactive_votes_cache_election_start)
TEST (inactive_votes_cache, election_start)
{
nano::test::system system;
nano::node_config node_config = system.default_config ();
Expand Down Expand Up @@ -527,8 +527,7 @@ TEST (active_transactions, inactive_votes_cache_election_start)
// A late block arrival also checks the inactive votes cache
ASSERT_TRUE (node.active.empty ());
auto send4_cache (node.vote_cache.find (send4->hash ()));
ASSERT_TRUE (send4_cache);
ASSERT_EQ (3, send4_cache->voters ().size ());
ASSERT_EQ (3, send4_cache.size ());
node.process_active (send3);
// An election is started for send6 but does not
ASSERT_FALSE (node.block_confirmed_or_being_confirmed (send3->hash ()));
Expand Down Expand Up @@ -981,8 +980,7 @@ TEST (active_transactions, fork_replacement_tally)
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.flush ();
// ensure vote arrives before the block
ASSERT_TIMELY (5s, node1.vote_cache.find (send_last->hash ()));
ASSERT_TIMELY_EQ (5s, 1, node1.vote_cache.find (send_last->hash ())->size ());
ASSERT_TIMELY_EQ (5s, 1, node1.vote_cache.find (send_last->hash ()).size ());
node1.network.publish_filter.clear ();
node2.network.flood_block (send_last);
ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) > 1);
Expand Down Expand Up @@ -1536,7 +1534,7 @@ TEST (active_transactions, allow_limited_overflow)
{
// Non-final vote, so it stays in the AEC without getting confirmed
auto vote = nano::test::make_vote (nano::dev::genesis_key, { block });
node.vote_cache.vote (block->hash (), vote);
node.vote_cache.vote (vote);
}

// Ensure active elections overfill AEC only up to normal + hinted limit
Expand Down Expand Up @@ -1574,7 +1572,7 @@ TEST (active_transactions, allow_limited_overflow_adapt)
{
// Non-final vote, so it stays in the AEC without getting confirmed
auto vote = nano::test::make_vote (nano::dev::genesis_key, { block });
node.vote_cache.vote (block->hash (), vote);
node.vote_cache.vote (vote);
}

// Ensure hinted election amount is bounded by hinted limit
Expand Down
4 changes: 3 additions & 1 deletion nano/node/vote_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class vote_cache final
/**
* Adds a new vote to cache
*/
void vote (std::shared_ptr<nano::vote> const & vote, std::function<bool (nano::block_hash const &)> const & filter);
void vote (
std::shared_ptr<nano::vote> const & vote,
std::function<bool (nano::block_hash const &)> const & filter = [] (nano::block_hash const &) { return true; });

/**
* Tries to find an entry associated with block hash
Expand Down

0 comments on commit cc7630a

Please sign in to comment.