Skip to content

Commit

Permalink
Return error code from nano::test::start_election
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 5, 2023
1 parent f74ebde commit 2b72761
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
6 changes: 3 additions & 3 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ TEST (active_transactions, vote_replays)
ASSERT_NE (nullptr, open1);
node.process_active (send1);
node.process_active (open1);
nano::test::start_elections (system, node, { send1, open1 });
ASSERT_TRUE (nano::test::start_elections (system, node, { send1, open1 }));
ASSERT_EQ (2, node.active.size ());
// First vote is not a replay and confirms the election, second vote should be a replay since the election has confirmed but not yet removed
auto vote_send1 (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>{ send1->hash () }));
Expand Down Expand Up @@ -585,7 +585,7 @@ TEST (active_transactions, vote_replays)
.build_shared ();
ASSERT_NE (nullptr, send2);
node.process_active (send2);
nano::test::start_elections (system, node, { send2 });
ASSERT_TRUE (nano::test::start_elections (system, node, { send2 }));
ASSERT_EQ (1, node.active.size ());
auto vote1_send2 (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>{ send2->hash () }));
auto vote2_send2 (std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, std::vector<nano::block_hash>{ send2->hash () }));
Expand Down Expand Up @@ -1280,7 +1280,7 @@ TEST (active_transactions, list_active)

ASSERT_EQ (nano::process_result::progress, node.process (*open).code);

nano::test::start_elections (system, node, { send, send2, open });
ASSERT_TRUE (nano::test::start_elections (system, node, { send, send2, open }));
ASSERT_EQ (3, node.active.size ());
ASSERT_EQ (1, node.active.list_active (1).size ());
ASSERT_EQ (2, node.active.list_active (2).size ());
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
node1->process_active (change2);
ASSERT_TIMELY (5s, node1->block (change2->hash ()) != nullptr);
// Confirm last block to prune previous
nano::test::start_elections (system, *node1, { send1, receive1, change1, change2 }, true);
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1, change1, change2 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()) && node1->block_confirmed (change1->hash ()) && node1->block_confirmed (change2->hash ()) && node1->active.empty ());
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
Expand Down Expand Up @@ -1321,7 +1321,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
node1->process_active (state_open);
ASSERT_TIMELY (5s, node1->block (state_open->hash ()) != nullptr);
// Confirm last block to prune previous
nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true);
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (open->hash ()) && node1->block_confirmed (state_open->hash ()));
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
Expand Down Expand Up @@ -1878,7 +1878,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (receive2->hash (), request5->frontier);

// Confirm account before genesis (confirmed only)
nano::test::start_elections (system, *node1, { send1, receive1 }, true);
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()));
auto connection6 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket::endpoint_type_t::server), node1));
auto req6 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
Expand All @@ -1893,7 +1893,7 @@ TEST (frontier_req, confirmed_frontier)
ASSERT_EQ (receive1->hash (), request6->frontier);

// Confirm account after genesis (confirmed only)
nano::test::start_elections (system, *node1, { send2, receive2 }, true);
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send2, receive2 }, true));
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (receive2->hash ()));
auto connection7 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket::endpoint_type_t::server), node1));
auto req7 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ TEST (votes, DISABLED_add_old_different_account)
node1.work_generate_blocking (*send2);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
ASSERT_EQ (nano::process_result::progress, node1.process (*send2).code);
nano::test::start_elections (system, node1, { send1, send2 });
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1, send2 }));
auto election1 = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election1);
auto election2 = node1.active.election (send2->qualified_root ());
Expand Down Expand Up @@ -4092,7 +4092,7 @@ TEST (ledger, block_hash_account_conflict)
ASSERT_EQ (nano::process_result::progress, node1.process (*receive1).code);
ASSERT_EQ (nano::process_result::progress, node1.process (*send2).code);
ASSERT_EQ (nano::process_result::progress, node1.process (*open_epoch1).code);
nano::test::start_elections (system, node1, { send1, receive1, send2, open_epoch1 });
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1, receive1, send2, open_epoch1 }));
auto election1 = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election1);
auto election2 = node1.active.election (receive1->qualified_root ());
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,7 @@ TEST (node, confirm_back)
node.process_active (open);
node.process_active (send2);
ASSERT_TIMELY (5s, node.block (send2->hash ()) != nullptr);
nano::test::start_elections (system, node, { send1, open, send2 });
ASSERT_TRUE (nano::test::start_elections (system, node, { send1, open, send2 }));
ASSERT_EQ (3, node.active.size ());
std::vector<nano::block_hash> vote_blocks;
vote_blocks.push_back (send2->hash ());
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6882,7 +6882,7 @@ TEST (rpc, confirmation_active)
.build_shared ();
node1->process_active (send1);
node1->process_active (send2);
nano::test::start_elections (system, *node1, { send1, send2 });
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2 }));
ASSERT_EQ (2, node1->active.size ());
auto election (node1->active.election (send1->qualified_root ()));
ASSERT_NE (nullptr, election);
Expand Down
4 changes: 2 additions & 2 deletions nano/slow_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2110,9 +2110,9 @@ TEST (node, aggressive_flooding)
ASSERT_EQ (node1.latest (nano::dev::genesis_key.pub), node_wallet.first->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (genesis_blocks.back ()->hash (), node_wallet.first->latest (nano::dev::genesis_key.pub));
// Confirm blocks for rep crawler & receiving
nano::test::start_elections (system, *node_wallet.first, { genesis_blocks.back () }, true);
ASSERT_TRUE (nano::test::start_elections (system, *node_wallet.first, { genesis_blocks.back () }, true));
}
nano::test::start_elections (system, node1, { genesis_blocks.back () }, true);
ASSERT_TRUE (nano::test::start_elections (system, node1, { genesis_blocks.back () }, true));

// Wait until all genesis blocks are received
auto all_received = [&nodes_wallets] () {
Expand Down
13 changes: 9 additions & 4 deletions nano/test_common/testutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,25 @@ std::shared_ptr<nano::election> nano::test::start_election (nano::test::system &
return election;
}

void nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<nano::block_hash> const & hashes_a, bool const forced_a)
bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<nano::block_hash> const & hashes_a, bool const forced_a)
{
auto result = true;
for (auto const & hash_l : hashes_a)
{
auto election = nano::test::start_election (system_a, node_a, hash_l);
release_assert (election);
if (!election)
{
result = false;
}
if (forced_a)
{
election->force_confirm ();
}
}
return result;
}

void nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<std::shared_ptr<nano::block>> const & blocks_a, bool const forced_a)
bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<std::shared_ptr<nano::block>> const & blocks_a, bool const forced_a)
{
nano::test::start_elections (system_a, node_a, blocks_to_hashes (blocks_a), forced_a);
return nano::test::start_elections (system_a, node_a, blocks_to_hashes (blocks_a), forced_a);
}
10 changes: 6 additions & 4 deletions nano/test_common/testutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,16 @@ namespace test
/*
* Call start_election for every block identified in the hash vector.
* Optionally, force confirm the election if forced_a is set.
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will assert.
* @return true if all elections were successfully started
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will return an error
*/
void start_elections (nano::test::system &, nano::node &, std::vector<nano::block_hash> const &, bool const forced_a = false);
[[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector<nano::block_hash> const &, bool const forced_a = false);
/*
* Call start_election for every block in the vector.
* Optionally, force confirm the election if forced_a is set.
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will assert.
* @return true if all elections were successfully started
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will return an error.
*/
void start_elections (nano::test::system &, nano::node &, std::vector<std::shared_ptr<nano::block>> const &, bool const forced_a = false);
[[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector<std::shared_ptr<nano::block>> const &, bool const forced_a = false);
}
}

0 comments on commit 2b72761

Please sign in to comment.