diff --git a/unittests/producer_schedule_if_tests.cpp b/unittests/producer_schedule_if_tests.cpp index ab7afc1dc1..1252b3014e 100644 --- a/unittests/producer_schedule_if_tests.cpp +++ b/unittests/producer_schedule_if_tests.cpp @@ -398,4 +398,36 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_misc_tests, validating_tester ) try { } FC_LOG_AND_RETHROW() +BOOST_AUTO_TEST_CASE( switch_producers_test ) try { + validating_tester chain; + + const std::vector accounts = { "aliceaccount"_n, "bobbyaccount"_n, "carolaccount"_n, "emilyaccount"_n }; + chain.create_accounts( accounts ); + chain.produce_block(); + + // activate instant_finality + chain.set_finalizers(accounts); + chain.set_producers( accounts ); + chain.produce_block(); + + // looping less than 20 did not reproduce the `producer_double_confirm: Producer is double confirming known range` error + for (size_t i = 0; i < 20; ++i) { + chain.set_producers( { "aliceaccount"_n, "bobbyaccount"_n } ); + chain.produce_block(); + + chain.set_producers( { "bobbyaccount"_n, "aliceaccount"_n } ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + + chain.set_producers( accounts ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + + chain.set_producers( { "carolaccount"_n } ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + } + +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_SUITE_END() diff --git a/unittests/producer_schedule_tests.cpp b/unittests/producer_schedule_tests.cpp index 19149225e8..ce8d7ec5c0 100644 --- a/unittests/producer_schedule_tests.cpp +++ b/unittests/producer_schedule_tests.cpp @@ -348,6 +348,36 @@ BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { BOOST_REQUIRE_EQUAL( c.validate(), true ); } FC_LOG_AND_RETHROW() +BOOST_AUTO_TEST_CASE( switch_producers_test ) try { + validating_tester chain; + + const std::vector accounts = { "aliceaccount"_n, "bobbyaccount"_n, "carolaccount"_n, "emilyaccount"_n }; + chain.create_accounts( accounts ); + chain.produce_block(); + + chain.set_producers( accounts ); + chain.produce_block(); + + // looping less than 20 did not reproduce the `producer_double_confirm: Producer is double confirming known range` error + for (size_t i = 0; i < 20; ++i) { + chain.set_producers( { "aliceaccount"_n, "bobbyaccount"_n } ); + chain.produce_block(); + + chain.set_producers( { "bobbyaccount"_n, "aliceaccount"_n } ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + + chain.set_producers( accounts ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + + chain.set_producers( { "carolaccount"_n } ); + chain.produce_block(); + chain.produce_block( fc::hours(1) ); + } + +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_CASE( producer_watermark_test ) try { tester c;