Skip to content

Commit bc40a76

Browse files
ABWvogel76
ABW
authored andcommitted
fix plugin test where witness is being disabled in the middle of schedule 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.
1 parent b186f02 commit bc40a76

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

tests/unit/plugin_tests/condenser_api_account_history_tests.cpp

+20-21
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ BOOST_AUTO_TEST_CASE( get_account_history_hf19 )
361361

362362
auto check_point_tester = [ this ]( uint32_t generate_no_further_than )
363363
{
364-
// Make witness operations irreversible.
365-
generate_until_irreversible_block( 4 );
366-
// Artificially generate missing blocks.
367-
generate_blocks( db->head_block_time() + fc::seconds(9) );
368364
// Make the block with desired vops irreversible.
369365
generate_until_irreversible_block( 27 );
370366
BOOST_REQUIRE( db->head_block_num() <= generate_no_further_than );
@@ -373,28 +369,31 @@ BOOST_AUTO_TEST_CASE( get_account_history_hf19 )
373369
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}])~",
374370
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"}]}])~"
375371
}, {
376-
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}])~",
377-
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}]}])~"
378-
}, {
379-
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}])~",
380-
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"}]}])~"
381-
}, {
382-
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}])~",
383-
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"}]}])~"
384-
}, {
385-
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}])~",
386-
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"}]}])~"
372+
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}])~",
373+
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"}]}])~"
387374
}, {
388-
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}])~",
389-
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"}]}])~"
375+
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}])~",
376+
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"}]}])~"
390377
}, {
391-
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}])~",
392-
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"}]}])~"
378+
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}])~",
379+
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"}]}])~"
393380
} };
394381

395382
expected_t expected_ben19ah_history = { {
396-
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}])~",
397-
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}]}])~"
383+
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}])~",
384+
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"}]}])~",
385+
}, {
386+
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}])~",
387+
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"}]}])~"
388+
}, {
389+
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}])~",
390+
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"}]}])~"
391+
}, {
392+
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}])~",
393+
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"}]}])~"
394+
}, {
395+
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}])~",
396+
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"}]}])~",
398397
} };
399398

400399
// Filter out usual account_create(d) and transfer to vesting (completed)_operations checked in other tests.

tests/unit/plugin_tests/condenser_api_fixture.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <hive/plugins/database_api/database_api_plugin.hpp>
99
#include <hive/plugins/condenser_api/condenser_api_plugin.hpp>
1010
#include <hive/plugins/condenser_api/condenser_api.hpp>
11+
#include <hive/plugins/witness/witness_plugin.hpp>
1112

1213
#include <boost/test/unit_test.hpp>
1314

@@ -164,7 +165,20 @@ void condenser_api_fixture::hf19_scenario( check_point_tester_t check_point_test
164165
generate_block();
165166

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

169183
// Now all the operations mentioned above can be checked. They can appear as early as 27th block, depending on configuration.
170184
check_point_tester( std::numeric_limits<uint32_t>::max() ); // <- no limit to max number of block generated inside.

tests/unit/plugin_tests/condenser_api_ops_in_block_tests.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -294,23 +294,19 @@ BOOST_AUTO_TEST_CASE( get_ops_in_block_hf19 )
294294

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

305301
expected_t expected_operations = { { // shutdown_witness_operation
306-
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})~",
307-
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"}]})~"
302+
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})~",
303+
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"}]})~"
308304
}, { // producer_missed_operation
309-
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})~",
310-
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"}]})~"
305+
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})~",
306+
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"}]})~"
311307
}, { // producer_reward_operation
312-
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})~",
313-
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"}]})~"
308+
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})~",
309+
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"}]})~"
314310
} };
315311
// Note that all operations of this block are virtual, hence we can reuse the same expected container here.
316312
test_get_ops_in_block( *this, expected_operations, expected_operations, 27 );

0 commit comments

Comments
 (0)