Skip to content

Commit

Permalink
fix plugin test where witness is being disabled in the middle of sche…
Browse files Browse the repository at this point in the history
…dule which prevents it from generating further blocks

The test needed more changes because the situation is highly unusual and not realistic, so it made more sense to adjust the test then to
change debug plugin to work around the problem.
  • Loading branch information
ABW authored and vogel76 committed Dec 12, 2024
1 parent b186f02 commit bc40a76
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
41 changes: 20 additions & 21 deletions tests/unit/plugin_tests/condenser_api_account_history_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ BOOST_AUTO_TEST_CASE( get_account_history_hf19 )

auto check_point_tester = [ this ]( uint32_t generate_no_further_than )
{
// Make witness operations irreversible.
generate_until_irreversible_block( 4 );
// Artificially generate missing blocks.
generate_blocks( db->head_block_time() + fc::seconds(9) );
// Make the block with desired vops irreversible.
generate_until_irreversible_block( 27 );
BOOST_REQUIRE( db->head_block_num() <= generate_no_further_than );
Expand All @@ -373,28 +369,31 @@ BOOST_AUTO_TEST_CASE( get_account_history_hf19 )
R"~([4,{"trx_id":"2c670b301475c656d736c135dcbe67255ed4073a","block":4,"trx_in_block":0,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":{"type":"witness_update_operation","value":{"owner":"alice19ah","url":"foo.bar","block_signing_key":"STM89H9erzoVqMMEsqN9MqeFdBTdquzeYeXUL2anQVmBdHz55iedM","props":{"account_creation_fee":{"amount":"0","precision":3,"nai":"@@000000021"},"maximum_block_size":131072,"hbd_interest_rate":1000},"fee":{"amount":"1000","precision":3,"nai":"@@000000021"}}},"operation_id":0}])~",
R"~([4,{"trx_id":"2c670b301475c656d736c135dcbe67255ed4073a","block":4,"trx_in_block":0,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":["witness_update",{"owner":"alice19ah","url":"foo.bar","block_signing_key":"STM89H9erzoVqMMEsqN9MqeFdBTdquzeYeXUL2anQVmBdHz55iedM","props":{"account_creation_fee":"0.000 TESTS","maximum_block_size":131072,"hbd_interest_rate":1000},"fee":"1.000 TESTS"}]}])~"
}, {
R"~([5,{"trx_id":"c20acb0f4623121ea391d468edd6c1c8647eb0eb","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":{"type":"account_witness_vote_operation","value":{"account":"ben19ah","witness":"alice19ah","approve":true}},"operation_id":0}])~",
R"~([5,{"trx_id":"c20acb0f4623121ea391d468edd6c1c8647eb0eb","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":["account_witness_vote",{"account":"ben19ah","witness":"alice19ah","approve":true}]}])~"
}, {
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":23,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:09","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"93998697157","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":23,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:09","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"93998.697157 VESTS"}]}])~"
}, {
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":25,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:15","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"92825712045","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":25,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:15","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"92825.712045 VESTS"}]}])~"
}, {
R"~([8,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"shutdown_witness_operation","value":{"owner":"alice19ah"}},"operation_id":0}])~",
R"~([8,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["shutdown_witness",{"owner":"alice19ah"}]}])~"
R"~([5,{"trx_id":"0000000000000000000000000000000000000000","block":23,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:09","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"62909591605","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([5,{"trx_id":"0000000000000000000000000000000000000000","block":23,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:09","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"62909.591605 VESTS"}]}])~"
}, {
R"~([9,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_missed_operation","value":{"producer":"alice19ah"}},"operation_id":0}])~",
R"~([9,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_missed",{"producer":"alice19ah"}]}])~"
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":26,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:18","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"61683672175","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":26,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:18","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"61683.672175 VESTS"}]}])~"
}, {
R"~([10,{"trx_id":"0000000000000000000000000000000000000000","block":28,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:27","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"91321979235","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([10,{"trx_id":"0000000000000000000000000000000000000000","block":28,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:27","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"91321.979235 VESTS"}]}])~"
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":28,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:27","op":{"type":"producer_reward_operation","value":{"producer":"alice19ah","vesting_shares":{"amount":"60961771931","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":28,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:27","op":["producer_reward",{"producer":"alice19ah","vesting_shares":"60961.771931 VESTS"}]}])~"
} };

expected_t expected_ben19ah_history = { {
R"~([4,{"trx_id":"c20acb0f4623121ea391d468edd6c1c8647eb0eb","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":{"type":"account_witness_vote_operation","value":{"account":"ben19ah","witness":"alice19ah","approve":true}},"operation_id":0}])~",
R"~([4,{"trx_id":"c20acb0f4623121ea391d468edd6c1c8647eb0eb","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":["account_witness_vote",{"account":"ben19ah","witness":"alice19ah","approve":true}]}])~"
R"~([4,{"trx_id":"643d618db0f503cb8f1d10706c7ca4cf0ff7a122","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":{"type":"witness_update_operation","value":{"owner":"ben19ah","url":"foo.bar","block_signing_key":"STM7pZMDSW8KdZTt1YzmqkfuRZx45yTsNx2v8nXvu7YmKCsxSuQha","props":{"account_creation_fee":{"amount":"0","precision":3,"nai":"@@000000021"},"maximum_block_size":131072,"hbd_interest_rate":1000},"fee":{"amount":"1000","precision":3,"nai":"@@000000021"}}},"operation_id":0}])~",
R"~([4,{"trx_id":"643d618db0f503cb8f1d10706c7ca4cf0ff7a122","block":4,"trx_in_block":1,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:00:12","op":["witness_update",{"owner":"ben19ah","url":"foo.bar","block_signing_key":"STM7pZMDSW8KdZTt1YzmqkfuRZx45yTsNx2v8nXvu7YmKCsxSuQha","props":{"account_creation_fee":"0.000 TESTS","maximum_block_size":131072,"hbd_interest_rate":1000},"fee":"1.000 TESTS"}]}])~",
}, {
R"~([5,{"trx_id":"0000000000000000000000000000000000000000","block":24,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:12","op":{"type":"producer_reward_operation","value":{"producer":"ben19ah","vesting_shares":{"amount":"62479383982","precision":6,"nai":"@@000000037"}}},"operation_id":0}])~",
R"~([5,{"trx_id":"0000000000000000000000000000000000000000","block":24,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:12","op":["producer_reward",{"producer":"ben19ah","vesting_shares":"62479.383982 VESTS"}]}])~"
}, {
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"shutdown_witness_operation","value":{"owner":"ben19ah"}},"operation_id":0}])~",
R"~([6,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["shutdown_witness",{"owner":"ben19ah"}]}])~"
}, {
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_missed_operation","value":{"producer":"ben19ah"}},"operation_id":0}])~",
R"~([7,{"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_missed",{"producer":"ben19ah"}]}])~"
}, {
R"~([8,{"trx_id":"e2a7536d726e28d8bc4dba82af7850e628b2c161","block":28,"trx_in_block":0,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:01:27","op":{"type":"witness_update_operation","value":{"owner":"ben19ah","url":"foo.bar","block_signing_key":"STM7pZMDSW8KdZTt1YzmqkfuRZx45yTsNx2v8nXvu7YmKCsxSuQha","props":{"account_creation_fee":{"amount":"0","precision":3,"nai":"@@000000021"},"maximum_block_size":131072,"hbd_interest_rate":1000},"fee":{"amount":"1000","precision":3,"nai":"@@000000021"}}},"operation_id":0}])~",
R"~([8,{"trx_id":"e2a7536d726e28d8bc4dba82af7850e628b2c161","block":28,"trx_in_block":0,"op_in_trx":0,"virtual_op":false,"timestamp":"2016-01-01T00:01:27","op":["witness_update",{"owner":"ben19ah","url":"foo.bar","block_signing_key":"STM7pZMDSW8KdZTt1YzmqkfuRZx45yTsNx2v8nXvu7YmKCsxSuQha","props":{"account_creation_fee":"0.000 TESTS","maximum_block_size":131072,"hbd_interest_rate":1000},"fee":"1.000 TESTS"}]}])~",
} };

// Filter out usual account_create(d) and transfer to vesting (completed)_operations checked in other tests.
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/plugin_tests/condenser_api_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <hive/plugins/database_api/database_api_plugin.hpp>
#include <hive/plugins/condenser_api/condenser_api_plugin.hpp>
#include <hive/plugins/condenser_api/condenser_api.hpp>
#include <hive/plugins/witness/witness_plugin.hpp>

#include <boost/test/unit_test.hpp>

Expand Down Expand Up @@ -164,7 +165,20 @@ void condenser_api_fixture::hf19_scenario( check_point_tester_t check_point_test
generate_block();

witness_create( "alice19ah", alice19ah_private_key, "foo.bar", alice19ah_private_key.get_public_key(), 1000 );
witness_vote( "ben19ah", "alice19ah", ben19ah_private_key );
witness_plugin->add_signing_key( alice19ah_private_key );
witness_create( "ben19ah", ben19ah_private_key, "foo.bar", ben19ah_private_key.get_public_key(), 1000 );
witness_plugin->add_signing_key( ben19ah_private_key );

// Make witness operations irreversible.
generate_until_irreversible_block( 4 );
// Artificially generate missing blocks.
generate_blocks( db->head_block_time() + fc::seconds( 9 ) );
// reenable ben19ah or it won't be possible to sign block for him when the time comes (he is going to produce more
// blocks in the same schedule despite being disabled, because there are only three witnesses - he would be tossed out
// only in next schedule, but then we'd fail in witness update anyway, because it is expected that all witnesses are
// active if there is less than 21); we need at least 3 by the way, because witness next to his missed block will disable
// him and one more is needed to accept transaction that reenables him before its his time to produce again
witness_create( "ben19ah", ben19ah_private_key, "foo.bar", ben19ah_private_key.get_public_key(), 1000 );

// Now all the operations mentioned above can be checked. They can appear as early as 27th block, depending on configuration.
check_point_tester( std::numeric_limits<uint32_t>::max() ); // <- no limit to max number of block generated inside.
Expand Down
16 changes: 6 additions & 10 deletions tests/unit/plugin_tests/condenser_api_ops_in_block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,19 @@ BOOST_AUTO_TEST_CASE( get_ops_in_block_hf19 )

auto check_point_tester = [ this ]( uint32_t generate_no_further_than )
{
// Make witness operations irreversible.
generate_until_irreversible_block( 4 );
// Artificially generate missing blocks.
generate_blocks( db->head_block_time() + fc::seconds(9) );
// Make the block with desired vops irreversible.
generate_until_irreversible_block( 27 );
BOOST_REQUIRE( db->head_block_num() <= generate_no_further_than );

expected_t expected_operations = { { // shutdown_witness_operation
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"shutdown_witness_operation","value":{"owner":"alice19ah"}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["shutdown_witness",{"owner":"alice19ah"}]})~"
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"shutdown_witness_operation","value":{"owner":"ben19ah"}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":1,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["shutdown_witness",{"owner":"ben19ah"}]})~"
}, { // producer_missed_operation
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_missed_operation","value":{"producer":"alice19ah"}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_missed",{"producer":"alice19ah"}]})~"
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_missed_operation","value":{"producer":"ben19ah"}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":2,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_missed",{"producer":"ben19ah"}]})~"
}, { // producer_reward_operation
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":3,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_reward_operation","value":{"producer":"initminer","vesting_shares":{"amount":"91794209040","precision":6,"nai":"@@000000037"}}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":3,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_reward",{"producer":"initminer","vesting_shares":"91794.209040 VESTS"}]})~"
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":3,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":{"type":"producer_reward_operation","value":{"producer":"initminer","vesting_shares":{"amount":"61314308868","precision":6,"nai":"@@000000037"}}},"operation_id":0})~",
R"~({"trx_id":"0000000000000000000000000000000000000000","block":27,"trx_in_block":4294967295,"op_in_trx":3,"virtual_op":true,"timestamp":"2016-01-01T00:01:24","op":["producer_reward",{"producer":"initminer","vesting_shares":"61314.308868 VESTS"}]})~"
} };
// Note that all operations of this block are virtual, hence we can reuse the same expected container here.
test_get_ops_in_block( *this, expected_operations, expected_operations, 27 );
Expand Down

0 comments on commit bc40a76

Please sign in to comment.