Skip to content

Commit

Permalink
Use assert_eq and assert_timely_eq (#4372)
Browse files Browse the repository at this point in the history
  • Loading branch information
RickiNano authored Jan 19, 2024
1 parent 5047fc8 commit ef10ef7
Show file tree
Hide file tree
Showing 30 changed files with 332 additions and 329 deletions.
43 changes: 22 additions & 21 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ TEST (active_transactions, confirm_frontier)
// Save election to check request count afterwards
auto election2 = node2.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election2);
ASSERT_TIMELY (5s, node2.ledger.cache.cemented_count == 2 && node2.active.empty ());
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 2);
ASSERT_TIMELY (5s, node2.active.empty ());
ASSERT_GT (election2->confirmation_request_count, 0u);
}
}
Expand Down Expand Up @@ -219,7 +220,7 @@ TEST (active_transactions, keep_local)
node.process_active (receive3);

/// bound elections, should drop after one loop
ASSERT_TIMELY (5s, node.active.size () == node_config.active_elections_size);
ASSERT_TIMELY_EQ (5s, node.active.size (), node_config.active_elections_size);
// ASSERT_EQ (1, node.scheduler.size ());
}

Expand All @@ -238,7 +239,7 @@ TEST (active_transactions, inactive_votes_cache)
.build_shared ();
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, 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.vote_cache.size () == 1);
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);
node.process_active (send);
node.block_processor.flush ();
ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send->hash ()));
Expand All @@ -264,7 +265,7 @@ TEST (active_transactions, inactive_votes_cache_non_final)
// 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.vote_cache.size () == 1);
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);

node.process_active (send);
std::shared_ptr<nano::election> election;
Expand Down Expand Up @@ -301,15 +302,15 @@ TEST (active_transactions, inactive_votes_cache_fork)

auto const vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash> (1, send1->hash ()));
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, node.vote_cache.size () == 1);
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);

node.process_active (send2);

std::shared_ptr<nano::election> election{};
ASSERT_TIMELY (5s, (election = node.active.election (send1->qualified_root ())) != nullptr);

node.process_active (send1);
ASSERT_TIMELY (5s, election->blocks ().size () == 2);
ASSERT_TIMELY_EQ (5s, election->blocks ().size (), 2);
ASSERT_TIMELY (5s, node.block_confirmed (send1->hash ()));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}
Expand Down Expand Up @@ -342,14 +343,14 @@ TEST (active_transactions, inactive_votes_cache_existing_vote)
node.process_active (send);
node.block_processor.add (open);
node.block_processor.flush ();
ASSERT_TIMELY (5s, node.active.size () == 1);
ASSERT_TIMELY_EQ (5s, node.active.size (), 1);
auto election (node.active.election (send->qualified_root ()));
ASSERT_NE (nullptr, election);
ASSERT_GT (node.weight (key.pub), node.minimum_principal_weight ());
// Insert vote
auto vote1 (std::make_shared<nano::vote> (key.pub, key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash> (1, send->hash ())));
node.vote_processor.vote (vote1, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, election->votes ().size () == 2);
ASSERT_TIMELY_EQ (5s, election->votes ().size (), 2);
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_new));
auto last_vote1 (election->votes ()[key.pub]);
ASSERT_EQ (send->hash (), last_vote1.hash);
Expand Down Expand Up @@ -417,7 +418,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
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 (5s, node.vote_cache.find (send1->hash ())->voters ().size () == 2);
ASSERT_TIMELY_EQ (5s, node.vote_cache.find (send1->hash ())->voters ().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 Down Expand Up @@ -475,7 +476,7 @@ TEST (active_transactions, inactive_votes_cache_election_start)
ASSERT_EQ (nano::process_result::progress, node.process (*send2).code);
ASSERT_EQ (nano::process_result::progress, node.process (*open1).code);
ASSERT_EQ (nano::process_result::progress, node.process (*open2).code);
ASSERT_TIMELY (5s, 5 == node.ledger.cache.block_count);
ASSERT_TIMELY_EQ (5s, 5, node.ledger.cache.block_count);
ASSERT_TRUE (node.active.empty ());
ASSERT_EQ (1, node.ledger.cache.cemented_count);
// These blocks will be processed later
Expand All @@ -497,7 +498,7 @@ TEST (active_transactions, inactive_votes_cache_election_start)
// Inactive votes
auto vote1 = nano::test::make_vote (key1, { open1, open2, send4 });
node.vote_processor.vote (vote1, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, node.vote_cache.size () == 3);
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 3);
ASSERT_TRUE (node.active.empty ());
ASSERT_EQ (1, node.ledger.cache.cemented_count);

Expand All @@ -512,7 +513,7 @@ TEST (active_transactions, inactive_votes_cache_election_start)
auto vote0 = nano::test::make_final_vote (nano::dev::genesis_key, { open1, open2, send4 });
node.vote_processor.vote (vote0, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, 0, node.active.size ());
ASSERT_TIMELY (5s, 5 == node.ledger.cache.cemented_count);
ASSERT_TIMELY_EQ (5s, 5, node.ledger.cache.cemented_count);
ASSERT_TRUE (nano::test::confirmed (node, { send1, send2, open1, open2 }));

// A late block arrival also checks the inactive votes cache
Expand All @@ -526,7 +527,7 @@ TEST (active_transactions, inactive_votes_cache_election_start)
// send7 cannot be voted on but an election should be started from inactive votes
ASSERT_FALSE (node.ledger.dependents_confirmed (node.store.tx_begin_read (), *send4));
node.process_active (send4);
ASSERT_TIMELY (5s, 7 == node.ledger.cache.cemented_count);
ASSERT_TIMELY_EQ (5s, 7, node.ledger.cache.cemented_count);
}

namespace nano
Expand Down Expand Up @@ -570,7 +571,7 @@ TEST (active_transactions, vote_replays)
ASSERT_EQ (2, node.active.size ());
ASSERT_EQ (nano::vote_code::replay, node.active.vote (vote_send1));
// Wait until the election is removed, at which point the vote is still a replay since it's been recently confirmed
ASSERT_TIMELY (3s, node.active.size () == 1);
ASSERT_TIMELY_EQ (3s, node.active.size (), 1);
ASSERT_EQ (nano::vote_code::replay, node.active.vote (vote_send1));
// Open new account
auto vote_open1 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash>{ open1->hash () }));
Expand Down Expand Up @@ -700,7 +701,7 @@ TEST (active_transactions, republish_winner)

node1.process_active (send1);
node1.block_processor.flush ();
ASSERT_TIMELY (3s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 1);
ASSERT_TIMELY_EQ (3s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in), 1);

// Several forks
for (auto i (0); i < 5; i++)
Expand Down Expand Up @@ -792,7 +793,7 @@ TEST (active_transactions, fork_filter_cleanup)
// All forks were merged into the same election
std::shared_ptr<nano::election> election{};
ASSERT_TIMELY (5s, (election = node1.active.election (send1->qualified_root ())) != nullptr);
ASSERT_TIMELY (5s, election->blocks ().size () == 10);
ASSERT_TIMELY_EQ (5s, election->blocks ().size (), 10);
ASSERT_EQ (1, node1.active.size ());

// Instantiate a new node
Expand All @@ -809,8 +810,8 @@ TEST (active_transactions, fork_filter_cleanup)
// how about node1 picking up "send1" from node2? we know it does because we assert at
// the end that it is within node1's AEC, but why node1.block_count doesn't increase?
//
ASSERT_TIMELY (5s, node2.ledger.cache.block_count == 2);
ASSERT_TIMELY (5s, node1.ledger.cache.block_count == 2);
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.block_count, 2);
ASSERT_TIMELY_EQ (5s, node1.ledger.cache.block_count, 2);

// Block is erased from the duplicate filter
ASSERT_TIMELY (5s, node1.network.publish_filter.apply (send_block_bytes.data (), send_block_bytes.size ()));
Expand Down Expand Up @@ -1407,7 +1408,7 @@ TEST (active_transactions, fifo)
ASSERT_TIMELY (5s, node.active.election (receive2->qualified_root ()) != nullptr);

// Ensure excess transactions get trimmed
ASSERT_TIMELY (5s, node.active.size () == 1);
ASSERT_TIMELY_EQ (5s, node.active.size (), 1);

// Ensure overflow stats have been incremented
ASSERT_EQ (1, node.stats.count (nano::stat::type::active_dropped, nano::stat::detail::normal));
Expand Down Expand Up @@ -1449,7 +1450,7 @@ TEST (active_transactions, limit_vote_hinted_elections)
auto vote1 = nano::test::make_vote (rep1, { open0, open1 });
node.vote_processor.vote (vote1, nano::test::fake_channel (node));
// Ensure new inactive vote cache entries were created
ASSERT_TIMELY (5s, node.vote_cache.size () == 2);
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 2);
// And no elections are getting started yet
ASSERT_ALWAYS (1s, node.active.empty ());
// And nothing got confirmed yet
Expand All @@ -1459,7 +1460,7 @@ TEST (active_transactions, limit_vote_hinted_elections)
auto vote2 = nano::test::make_vote (rep2, { open0 });
node.vote_processor.vote (vote2, nano::test::fake_channel (node));
// Ensure an election got started for open0 block
ASSERT_TIMELY (5s, node.active.size () == 1);
ASSERT_TIMELY_EQ (5s, node.active.size (), 1);
ASSERT_TIMELY (5s, nano::test::active (node, { open0 }));

// This vote should trigger election hinting but not become active due to limit of active hinted elections
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ TEST (block_builder, zeroed_state_block)
.work (0)
.build_shared ();
auto zero_block_build = builder.state ().zero ().sign (key.prv, key.pub).build ();
ASSERT_TRUE (zero_block_manual->hash () == zero_block_build->hash ());
ASSERT_EQ (zero_block_manual->hash (), zero_block_build->hash ());
ASSERT_FALSE (nano::validate_message (key.pub, zero_block_build->hash (), zero_block_build->signature));
}

Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,6 @@ TEST (rocksdb_block_store, tombstone_count)
ASSERT_EQ (store->tombstone_map.at (nano::tables::accounts).num_since_last_flush.load (), 0);
// Performs a delete operation and checks for the tombstone counter
store->account.del (store->tx_begin_write (), account);
ASSERT_TIMELY (5s, store->tombstone_map.at (nano::tables::accounts).num_since_last_flush.load () == 1);
ASSERT_TIMELY_EQ (5s, store->tombstone_map.at (nano::tables::accounts).num_since_last_flush.load (), 1);
}
}
30 changes: 15 additions & 15 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TEST (bootstrap_processor, process_one)
ASSERT_NE (hash1, hash2);
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY (10s, node1->latest (nano::dev::genesis_key.pub) == node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (10s, node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
node1->stop ();
}

Expand All @@ -342,7 +342,7 @@ TEST (bootstrap_processor, process_two)
ASSERT_FALSE (node1->init_error ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY (10s, node1->latest (nano::dev::genesis_key.pub) == node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (10s, node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
node1->stop ();
}

Expand Down Expand Up @@ -389,7 +389,7 @@ TEST (bootstrap_processor, process_state)
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), block2->hash ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY (10s, node1->latest (nano::dev::genesis_key.pub) == node0->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (10s, node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
node1->stop ();
}

Expand Down Expand Up @@ -418,7 +418,7 @@ TEST (bootstrap_processor, process_new)
auto node3 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
ASSERT_FALSE (node3->init_error ());
node3->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY (10s, node3->balance (key2.pub) == balance2);
ASSERT_TIMELY_EQ (10s, node3->balance (key2.pub), balance2);
ASSERT_EQ (balance1, node3->balance (nano::dev::genesis_key.pub));
node3->stop ();
}
Expand Down Expand Up @@ -471,7 +471,7 @@ TEST (bootstrap_processor, pull_diamond)
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
ASSERT_FALSE (node1->init_error ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY (10s, node1->balance (nano::dev::genesis_key.pub) == 100);
ASSERT_TIMELY_EQ (10s, node1->balance (nano::dev::genesis_key.pub), 100);
ASSERT_EQ (100, node1->balance (nano::dev::genesis_key.pub));
node1->stop ();
}
Expand Down Expand Up @@ -571,7 +571,7 @@ TEST (bootstrap_processor, DISABLED_push_diamond)
.build_shared ();
ASSERT_EQ (nano::process_result::progress, node1->process (*receive).code);
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY (10s, node0->balance (nano::dev::genesis_key.pub) == 100);
ASSERT_TIMELY_EQ (10s, node0->balance (nano::dev::genesis_key.pub), 100);
ASSERT_EQ (100, node0->balance (nano::dev::genesis_key.pub));
node1->stop ();
}
Expand Down Expand Up @@ -615,7 +615,7 @@ TEST (bootstrap_processor, DISABLED_push_diamond_pruning)
ASSERT_EQ (nano::process_result::progress, node1->process (*open).code);
// 1st bootstrap
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY (10s, node0->balance (key.pub) == nano::dev::constants.genesis_amount);
ASSERT_TIMELY_EQ (10s, node0->balance (key.pub), nano::dev::constants.genesis_amount);
// Process more blocks & prune old
auto send2 = builder
.send ()
Expand Down Expand Up @@ -650,7 +650,7 @@ TEST (bootstrap_processor, DISABLED_push_diamond_pruning)
}
// 2nd bootstrap
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY (10s, node0->balance (nano::dev::genesis_key.pub) == 100);
ASSERT_TIMELY_EQ (10s, node0->balance (nano::dev::genesis_key.pub), 100);
ASSERT_EQ (100, node0->balance (nano::dev::genesis_key.pub));
node1->stop ();
}
Expand Down Expand Up @@ -953,7 +953,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (receive3->hash (), true);
// Check processed blocks
ASSERT_TIMELY (5s, node1->ledger.cache.block_count == 9);
ASSERT_TIMELY_EQ (5s, node1->ledger.cache.block_count, 9);
ASSERT_TIMELY (5s, node1->balance (key2.pub) != 0);
ASSERT_TIMELY (5s, !node1->bootstrap_initiator.in_progress ());
node1->stop ();
Expand Down Expand Up @@ -1619,7 +1619,7 @@ TEST (bootstrap_processor, multiple_attempts)
// Check processed blocks
ASSERT_TIMELY (10s, node2->balance (key2.pub) != 0);
// Check attempts finish
ASSERT_TIMELY (5s, node2->bootstrap_initiator.attempts.size () == 0);
ASSERT_TIMELY_EQ (5s, node2->bootstrap_initiator.attempts.size (), 0);
node2->stop ();
}

Expand Down Expand Up @@ -1930,7 +1930,7 @@ TEST (bulk, genesis)
ASSERT_NE (latest1, latest3);

node2->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY (10s, node2->latest (nano::dev::genesis_key.pub) == node1->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (10s, node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
node2->stop ();
}
Expand Down Expand Up @@ -1970,7 +1970,7 @@ TEST (bulk, offline_send)
// Send block arrival via bootstrap
ASSERT_TIMELY (10s, node2->balance (nano::dev::genesis_key.pub) != std::numeric_limits<nano::uint256_t>::max ());
// Receiving send block
ASSERT_TIMELY (20s, node2->balance (key2.pub) == node1->config.receive_minimum.number ());
ASSERT_TIMELY_EQ (20s, node2->balance (key2.pub), node1->config.receive_minimum.number ());
node2->stop ();
}

Expand Down Expand Up @@ -2053,9 +2053,9 @@ TEST (bulk, DISABLED_genesis_pruning)
node2->block_processor.flush ();
ASSERT_EQ (3, node2->ledger.cache.block_count);
// New bootstrap
ASSERT_TIMELY (5s, node2->bootstrap_initiator.connections->connections_count == 0);
ASSERT_TIMELY_EQ (5s, node2->bootstrap_initiator.connections->connections_count, 0);
node2->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY (10s, node2->latest (nano::dev::genesis_key.pub) == node1->latest (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (10s, node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
node2->stop ();
}
Expand All @@ -2070,7 +2070,7 @@ TEST (bulk_pull_account, basics)
auto send1 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 25));
auto send2 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 10));
auto send3 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 2));
ASSERT_TIMELY (5s, system.nodes[0]->balance (key1.pub) == 25);
ASSERT_TIMELY_EQ (5s, system.nodes[0]->balance (key1.pub), 25);
auto connection (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0]));

{
Expand Down
Loading

0 comments on commit ef10ef7

Please sign in to comment.