Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 7, 2023
1 parent 6c643f0 commit 4a71cb4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion nano/core_test/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,25 @@ TEST (vote_cache, overfill_entry)
ASSERT_EQ (1, vote_cache.size ());
}

TEST (vote_cache,
TEST (vote_cache, age_cutoff)
{
nano::test::system system;
nano::vote_cache_config cfg;
cfg.age_cutoff = std::chrono::seconds{ 1 };
nano::vote_cache vote_cache{ cfg, system.stats };
vote_cache.rep_weight_query = rep_weight_query ();

auto hash1 = nano::test::random_hash ();
auto rep1 = create_rep (9);
auto vote1 = nano::test::make_vote (rep1, { hash1 }, 3);
vote_cache.vote (vote1->hashes.front (), vote1);
ASSERT_EQ (1, vote_cache.size ());
ASSERT_TRUE (vote_cache.find (hash1));

auto tops1 = vote_cache.top (0);
ASSERT_EQ (tops1.size (), 1);
ASSERT_EQ (tops1[0].hash, hash1);

// Cleanup is performed periodically when calling `top ()`
ASSERT_TIMELY (5s, vote_cache.top (0).empty ());
}
3 changes: 3 additions & 0 deletions nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ nano::vote_cache::vote_cache (vote_cache_config const & config_a, nano::stats &

void nano::vote_cache::vote (const nano::block_hash & hash, const std::shared_ptr<nano::vote> vote)
{
// Assert that supplied hash corresponds to a one of the hashes stored in vote
debug_assert (std::find (vote->hashes.begin (), vote->hashes.end (), hash) != vote->hashes.end ());

auto const representative = vote->account;
auto const timestamp = vote->timestamp ();
auto const rep_weight = rep_weight_query (representative);
Expand Down

0 comments on commit 4a71cb4

Please sign in to comment.