Skip to content

Commit

Permalink
Remove block processor flush from unit test and cleanup (#4095)
Browse files Browse the repository at this point in the history
* Remove block processor flush from unit test and cleanup

Tidy up and cleanup of a test case that uses block processor flush.
Removed the flush.
The test case was possibly not broken because the flush was possibly
needless due to the assert timely waiting for the vote_cached counter
increment.
  • Loading branch information
dsiganos committed Feb 1, 2023
1 parent 89f1022 commit 4a14086
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,33 @@ TEST (active_transactions, inactive_votes_cache)
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

/**
* This test case confirms that a non final vote cannot cause an election to become confirmed
*/
TEST (active_transactions, inactive_votes_cache_non_final)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::block_hash latest (node.latest (nano::dev::genesis_key.pub));
nano::keypair key;

auto send = nano::send_block_builder ()
.previous (latest)
.destination (key.pub)
.previous (nano::dev::genesis->hash ())
.destination (nano::keypair{}.pub)
.balance (nano::dev::constants.genesis_amount - 100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send->hash ()))); // Non-final vote

// Non-final vote
auto vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send->hash ()));
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, node.inactive_vote_cache.cache_size () == 1);

node.process_active (send);
node.block_processor.flush ();
ASSERT_TIMELY (5s, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached) == 1);
auto election = node.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election);
std::shared_ptr<nano::election> election;
ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ()));
ASSERT_TIMELY_EQ (5s, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached), 1);
ASSERT_TIMELY_EQ (5s, nano::dev::constants.genesis_amount - 100, election->tally ().begin ()->first);
ASSERT_FALSE (election->confirmed ());
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, election->tally ().begin ()->first);
}

TEST (active_transactions, inactive_votes_cache_fork)
Expand Down

0 comments on commit 4a14086

Please sign in to comment.