Skip to content

Commit

Permalink
GH-185 Add test that verifies no double producing error
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed May 29, 2024
1 parent 7a9e795 commit 190d0e1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
32 changes: 32 additions & 0 deletions unittests/producer_schedule_if_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<account_name> 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()
30 changes: 30 additions & 0 deletions unittests/producer_schedule_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<account_name> 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;

Expand Down

0 comments on commit 190d0e1

Please sign in to comment.