From 3061d0009d58271631caa6087ab5781a2bde8d03 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 5 Sep 2023 11:43:14 +0100 Subject: [PATCH] Return error code from nano::test::start_election --- nano/core_test/active_transactions.cpp | 6 +++--- nano/core_test/bootstrap.cpp | 8 ++++---- nano/core_test/ledger.cpp | 4 ++-- nano/core_test/node.cpp | 2 +- nano/rpc_test/rpc.cpp | 2 +- nano/slow_test/node.cpp | 4 ++-- nano/test_common/testutil.cpp | 12 ++++++++---- nano/test_common/testutil.hpp | 10 ++++++---- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 99f3abd228..9842f8bf28 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -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::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector{ send1->hash () })); @@ -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::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector{ send2->hash () })); auto vote2_send2 (std::make_shared (key.pub, key.prv, 0, 0, std::vector{ send2->hash () })); @@ -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 ()); diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 4c20ea7f02..c5536c34a5 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -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); @@ -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); @@ -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 (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); auto req6 = std::make_unique (nano::dev::network_params.network); @@ -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 (std::make_shared (*node1, nano::transport::socket::endpoint_type_t::server), node1)); auto req7 = std::make_unique (nano::dev::network_params.network); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 43fe65c314..09b57b05ad 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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 ()); @@ -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 ()); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 20f5ae3188..9a83f5c1ff 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -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 vote_blocks; vote_blocks.push_back (send2->hash ()); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index e60bb70d3a..55deb1d94a 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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); diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 280ce6dff1..60e3fae6cc 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -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] () { diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 0232f61671..6ba8ef1694 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -254,20 +254,24 @@ std::shared_ptr 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 const & hashes_a, bool const forced_a) +bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector const & hashes_a, bool const forced_a) { for (auto const & hash_l : hashes_a) { auto election = nano::test::start_election (system_a, node_a, hash_l); - release_assert (election); + if (!election) + { + return false; + } if (forced_a) { election->force_confirm (); } } + return true; } -void nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector> const & blocks_a, bool const forced_a) +bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector> 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); } diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 82ff0fdc41..32579aff1c 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -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 const &, bool const forced_a = false); + [[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector 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> const &, bool const forced_a = false); + [[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector> const &, bool const forced_a = false); } }