diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index cd2d642ed6..472014544e 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -157,6 +158,43 @@ TEST (election_scheduler, activate_one_flush) ASSERT_TIMELY (5s, node.active.election (send1->qualified_root ())); } + +TEST (election_scheduler, transition_optimistic_to_priority) +{ + nano::test::system system; + nano::node_config config = system.default_config (); + config.optimistic_scheduler.gap_threshold = 1; + auto & node = *system.add_node (config); + + // Create a chain of blocks + const int howmany_blocks = 2; + auto chains = nano::test::setup_chains (system, node, /* single chain */ 1, howmany_blocks, nano::dev::genesis_key, /* do not confirm */ false); + auto & [account, blocks] = chains.front (); + + // Priority election is created for the first block in chain + ASSERT_TIMELY (1s, node.active.size () == 1); + + // Wait for the optimistic election to start + auto const & block = blocks.back (); + ASSERT_TIMELY (5s, node.vote_router.active (block->hash ())); + auto election = node.active.election (block->qualified_root ()); + ASSERT_EQ (election->behavior (), nano::election_behavior::optimistic); + ASSERT_EQ (node.active.size (), 2); + + // Confirm block prior to the optimitic election + nano::test::confirm (node.ledger, blocks.at (howmany_blocks - 1)); + + // Now activate a priority election for the same block + auto secure_transaction (node.ledger.tx_begin_read ()); + node.scheduler.priority.activate (secure_transaction, nano::dev::genesis_key.pub); + + // Verify the election was upgraded to priority + ASSERT_TIMELY (5s, election->behavior () == nano::election_behavior::priority); + + // Verify the election is still active and properly transitioned + ASSERT_TRUE (node.active.active (*block)); +} + /** * Tests that the election scheduler and the active transactions container (AEC) * work in sync with regards to the node configuration value "active_elections.size".