Convert nano::test::start_election to take a hash rather than a block (#4116)
nano::test::start_election does need to take the block, a hash suffices and makes the function more flexible and reusable
This commit is contained in:
parent
8b6821625d
commit
303c9ea5c3
7 changed files with 28 additions and 24 deletions
|
|
@ -630,7 +630,7 @@ TEST (active_transactions, dropped_cleanup)
|
||||||
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
||||||
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, node, nano::dev::genesis);
|
auto election = nano::test::start_election (system, node, nano::dev::genesis->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
|
|
||||||
// Not yet removed
|
// Not yet removed
|
||||||
|
|
@ -653,7 +653,7 @@ TEST (active_transactions, dropped_cleanup)
|
||||||
// Repeat test for a confirmed election
|
// Repeat test for a confirmed election
|
||||||
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
|
||||||
|
|
||||||
election = nano::test::start_election (system, node, nano::dev::genesis);
|
election = nano::test::start_election (system, node, nano::dev::genesis->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
ASSERT_TRUE (election->confirmed ());
|
ASSERT_TRUE (election->confirmed ());
|
||||||
|
|
@ -1219,7 +1219,7 @@ TEST (active_transactions, activate_inactive)
|
||||||
ASSERT_EQ (nano::process_result::progress, node.process (*send2).code);
|
ASSERT_EQ (nano::process_result::progress, node.process (*send2).code);
|
||||||
ASSERT_EQ (nano::process_result::progress, node.process (*open).code);
|
ASSERT_EQ (nano::process_result::progress, node.process (*open).code);
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, node, send2);
|
auto election = nano::test::start_election (system, node, send2->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ TEST (confirmation_height, multiple_accounts)
|
||||||
.work (*system.work.generate (open3->hash ()))
|
.work (*system.work.generate (open3->hash ()))
|
||||||
.build_shared ();
|
.build_shared ();
|
||||||
node->process_active (receive3);
|
node->process_active (receive3);
|
||||||
auto election = nano::test::start_election (system, *node, receive3);
|
auto election = nano::test::start_election (system, *node, receive3->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
@ -533,7 +533,7 @@ TEST (confirmation_height, gap_live)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vote and confirm all existing blocks
|
// Vote and confirm all existing blocks
|
||||||
nano::test::start_election (system, *node, send1);
|
nano::test::start_election (system, *node, send1->hash ());
|
||||||
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3);
|
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3);
|
||||||
|
|
||||||
// Now complete the chain where the block comes in on the live network
|
// Now complete the chain where the block comes in on the live network
|
||||||
|
|
@ -688,7 +688,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
|
|
||||||
node->process_active (receive4);
|
node->process_active (receive4);
|
||||||
auto election = nano::test::start_election (system, *node, receive4);
|
auto election = nano::test::start_election (system, *node, receive4->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
@ -805,7 +805,7 @@ TEST (confirmation_height, send_receive_self)
|
||||||
|
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, *node, receive3);
|
auto election = nano::test::start_election (system, *node, receive3->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
@ -1050,7 +1050,7 @@ TEST (confirmation_height, all_block_types)
|
||||||
}
|
}
|
||||||
|
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
auto election = nano::test::start_election (system, *node, state_send2);
|
auto election = nano::test::start_election (system, *node, state_send2->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
@ -1546,7 +1546,7 @@ TEST (confirmation_height, callback_confirmed_history)
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
|
|
||||||
node->process_active (send1);
|
node->process_active (send1);
|
||||||
ASSERT_NE (nano::test::start_election (system, *node, send1), nullptr);
|
ASSERT_NE (nano::test::start_election (system, *node, send1->hash ()), nullptr);
|
||||||
{
|
{
|
||||||
node->process_active (send);
|
node->process_active (send);
|
||||||
node->block_processor.flush ();
|
node->block_processor.flush ();
|
||||||
|
|
@ -1647,9 +1647,9 @@ TEST (confirmation_height, dependent_election)
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
|
|
||||||
// This election should be confirmed as active_conf_height
|
// This election should be confirmed as active_conf_height
|
||||||
ASSERT_TRUE (nano::test::start_election (system, *node, send1));
|
ASSERT_TRUE (nano::test::start_election (system, *node, send1->hash ()));
|
||||||
// Start an election and confirm it
|
// Start an election and confirm it
|
||||||
auto election = nano::test::start_election (system, *node, send2);
|
auto election = nano::test::start_election (system, *node, send2->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
|
|
||||||
|
|
@ -1803,7 +1803,7 @@ TEST (confirmation_height, cemented_gap_below_receive)
|
||||||
nano::mutex mutex;
|
nano::mutex mutex;
|
||||||
add_callback_stats (*node, &observer_order, &mutex);
|
add_callback_stats (*node, &observer_order, &mutex);
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, *node, open1);
|
auto election = nano::test::start_election (system, *node, open1->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10);
|
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10);
|
||||||
|
|
@ -1968,7 +1968,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache)
|
||||||
|
|
||||||
add_callback_stats (*node);
|
add_callback_stats (*node);
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, *node, open1);
|
auto election = nano::test::start_election (system, *node, open1->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);
|
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ TEST (gap_cache, gap_bootstrap)
|
||||||
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, node1.balance (nano::dev::genesis->account ()));
|
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, node1.balance (nano::dev::genesis->account ()));
|
||||||
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
|
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
|
||||||
// Confirm send block, allowing voting on the upcoming block
|
// Confirm send block, allowing voting on the upcoming block
|
||||||
auto election = nano::test::start_election (system, node1, send);
|
auto election = nano::test::start_election (system, node1, send->hash ());
|
||||||
ASSERT_NE (nullptr, election);
|
ASSERT_NE (nullptr, election);
|
||||||
election->force_confirm ();
|
election->force_confirm ();
|
||||||
ASSERT_TIMELY (5s, node1.block_confirmed (send->hash ()));
|
ASSERT_TIMELY (5s, node1.block_confirmed (send->hash ()));
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ TEST (vote_processor, invalid_signature)
|
||||||
vote_invalid->signature.bytes[0] ^= 1;
|
vote_invalid->signature.bytes[0] ^= 1;
|
||||||
auto channel = std::make_shared<nano::transport::inproc::channel> (node, node);
|
auto channel = std::make_shared<nano::transport::inproc::channel> (node, node);
|
||||||
|
|
||||||
auto election = nano::test::start_election (system, node, nano::dev::genesis);
|
auto election = nano::test::start_election (system, node, nano::dev::genesis->hash ());
|
||||||
ASSERT_NE (election, nullptr);
|
ASSERT_NE (election, nullptr);
|
||||||
ASSERT_EQ (1, election->votes ().size ());
|
ASSERT_EQ (1, election->votes ().size ());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5874,7 +5874,7 @@ TEST (rpc, confirmation_height_currently_processing)
|
||||||
{
|
{
|
||||||
// Write guard prevents the confirmation height processor writing the blocks, so that we can inspect contents during the response
|
// Write guard prevents the confirmation height processor writing the blocks, so that we can inspect contents during the response
|
||||||
auto write_guard = node->write_database_queue.wait (nano::writer::testing);
|
auto write_guard = node->write_database_queue.wait (nano::writer::testing);
|
||||||
nano::test::start_election (system, *node, frontier);
|
nano::test::start_election (system, *node, frontier->hash ());
|
||||||
|
|
||||||
ASSERT_TIMELY (5s, node->confirmation_height_processor.current () == frontier->hash ());
|
ASSERT_TIMELY (5s, node->confirmation_height_processor.current () == frontier->hash ());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,30 +220,32 @@ std::shared_ptr<nano::transport::channel> nano::test::fake_channel (nano::node &
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<nano::election> nano::test::start_election (nano::test::system & system_a, nano::node & node_a, const std::shared_ptr<nano::block> & block_a)
|
std::shared_ptr<nano::election> nano::test::start_election (nano::test::system & system_a, nano::node & node_a, const nano::block_hash & hash_a)
|
||||||
{
|
{
|
||||||
system_a.deadline_set (5s);
|
system_a.deadline_set (5s);
|
||||||
|
|
||||||
// wait until and ensure that the block is in the ledger
|
// wait until and ensure that the block is in the ledger
|
||||||
while (!node_a.block (block_a->hash ()))
|
auto block_l = node_a.block (hash_a);
|
||||||
|
while (!block_l)
|
||||||
{
|
{
|
||||||
if (system_a.poll ())
|
if (system_a.poll ())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
block_l = node_a.block (hash_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
node_a.scheduler.manual (block_a);
|
node_a.scheduler.manual (block_l);
|
||||||
|
|
||||||
// wait for the election to appear
|
// wait for the election to appear
|
||||||
std::shared_ptr<nano::election> election = node_a.active.election (block_a->qualified_root ());
|
std::shared_ptr<nano::election> election = node_a.active.election (block_l->qualified_root ());
|
||||||
while (!election)
|
while (!election)
|
||||||
{
|
{
|
||||||
if (system_a.poll ())
|
if (system_a.poll ())
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
election = node_a.active.election (block_a->qualified_root ());
|
election = node_a.active.election (block_l->qualified_root ());
|
||||||
}
|
}
|
||||||
|
|
||||||
election->transition_active ();
|
election->transition_active ();
|
||||||
|
|
|
||||||
|
|
@ -408,10 +408,12 @@ namespace test
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<nano::transport::channel> fake_channel (nano::node & node, nano::account node_id = { 0 });
|
std::shared_ptr<nano::transport::channel> fake_channel (nano::node & node, nano::account node_id = { 0 });
|
||||||
/*
|
/*
|
||||||
* Start an election on system system_a, node node_a and block block_a by adding the block to the manual election scheduler queue.
|
* Start an election on system system_a, node node_a and hash hash_a by reading the block
|
||||||
* It waits up to 5 seconds for the election to start and calls the system poll function while waiting.
|
* out of the ledger and adding it to the manual election scheduler queue.
|
||||||
|
* It waits up to 5 seconds for the block to appear in the ledger and the election to start
|
||||||
|
* and calls the system poll function while waiting.
|
||||||
* Returns nullptr if the election did not start within the timeframe.
|
* Returns nullptr if the election did not start within the timeframe.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<nano::election> start_election (nano::test::system & system_a, nano::node & node_a, const std::shared_ptr<nano::block> & block_a);
|
std::shared_ptr<nano::election> start_election (nano::test::system & system_a, nano::node & node_a, const nano::block_hash & hash_a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue