|
| 1 | +#ifdef IS_TEST_NET |
| 2 | + |
| 3 | +#include <boost/test/unit_test.hpp> |
| 4 | + |
| 5 | +#include <hive/chain/database_exceptions.hpp> |
| 6 | +#include <hive/chain/detail/state/account_object.hpp> |
| 7 | +#include <hive/chain/detail/state/account_object_multiindex.hpp> |
| 8 | + |
| 9 | +#include <hive/plugins/debug_node/debug_node_plugin.hpp> |
| 10 | + |
| 11 | +#include "../db_fixture/clean_database_fixture.hpp" |
| 12 | + |
| 13 | +using namespace hive::chain; |
| 14 | +using namespace hive::protocol; |
| 15 | + |
| 16 | +BOOST_FIXTURE_TEST_SUITE( hf29_tests, cluster_database_fixture ) |
| 17 | + |
| 18 | +BOOST_AUTO_TEST_CASE( recovery_request_oversized_authority ) |
| 19 | +{ |
| 20 | + try |
| 21 | + { |
| 22 | + bool is_hf29 = false; |
| 23 | + |
| 24 | + auto _content = [ &is_hf29 ]( ptr_hardfork_database_fixture& executor ) |
| 25 | + { |
| 26 | + BOOST_TEST_MESSAGE( "Testing: oversized authority in recovery request edit/cancel" ); |
| 27 | + BOOST_REQUIRE_EQUAL( (bool)executor, true ); |
| 28 | + |
| 29 | + ACTORS_EXT( (*executor), (alice)(bob) ) |
| 30 | + executor->fund( "alice", HIVE_asset( 1'000'000 ) ); |
| 31 | + executor->db_plugin->debug_update( []( database& db ) |
| 32 | + { |
| 33 | + const auto& alice = db.get_account( "alice" ); |
| 34 | + db.modify( db.get_account( "bob" ), [&]( account_object& a ) |
| 35 | + { |
| 36 | + a.set_recovery_account( alice ); |
| 37 | + } ); |
| 38 | + } ); |
| 39 | + executor->generate_block(); |
| 40 | + |
| 41 | + request_account_recovery_operation initial_request; |
| 42 | + initial_request.recovery_account = "alice"; |
| 43 | + initial_request.account_to_recover = "bob"; |
| 44 | + initial_request.new_owner_authority = authority( |
| 45 | + 1, executor->generate_private_key( "k0" ).get_public_key(), 1 ); |
| 46 | + executor->push_transaction( initial_request, alice_private_key ); |
| 47 | + executor->generate_block(); |
| 48 | + |
| 49 | + const auto& idx = executor->db->get_index< account_recovery_request_index, by_account >(); |
| 50 | + BOOST_REQUIRE( idx.find( "bob" ) != idx.end() ); |
| 51 | + BOOST_REQUIRE_EQUAL( idx.find( "bob" )->get_new_owner_authority().key_auths.size(), 1u ); |
| 52 | + |
| 53 | + authority oversized; |
| 54 | + oversized.weight_threshold = 1; |
| 55 | + for( int i = 0; i <= HIVE_MAX_AUTHORITY_MEMBERSHIP; ++i ) |
| 56 | + oversized.add_authority( executor->generate_private_key( "extra_" + std::to_string( i ) ).get_public_key(), 1 ); |
| 57 | + |
| 58 | + request_account_recovery_operation oversized_edit; |
| 59 | + oversized_edit.recovery_account = "alice"; |
| 60 | + oversized_edit.account_to_recover = "bob"; |
| 61 | + oversized_edit.new_owner_authority = oversized; |
| 62 | + |
| 63 | + // regular push_transaction is stopped on check due to "is_in_control" |
| 64 | + HIVE_REQUIRE_ASSERT( executor->push_transaction( oversized_edit, alice_private_key ), |
| 65 | + "size <= HIVE_MAX_AUTHORITY_MEMBERSHIP" ); |
| 66 | + |
| 67 | + // work around "is_in_control" by not actually executing transaction |
| 68 | + executor->db_plugin->debug_push_pending_transaction( |
| 69 | + executor->build_transaction( oversized_edit, alice_private_key ) ); |
| 70 | + |
| 71 | + if( is_hf29 ) |
| 72 | + { |
| 73 | + // "p2p" block is stopped on faulty transaction after HF29 |
| 74 | + HIVE_REQUIRE_ASSERT( executor->generate_block_from_pending(), |
| 75 | + "size <= HIVE_MAX_AUTHORITY_MEMBERSHIP" ); |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + // "p2p" block is ok before HF28, even with faulty transaction |
| 80 | + executor->generate_block_from_pending(); |
| 81 | + // oversized authority is included in edited request |
| 82 | + BOOST_REQUIRE_EQUAL( idx.find( "bob" )->get_new_owner_authority().key_auths.size(), |
| 83 | + size_t( HIVE_MAX_AUTHORITY_MEMBERSHIP + 1 ) ); |
| 84 | + } |
| 85 | + |
| 86 | + // weight_threshold == 0 marks cancellation |
| 87 | + oversized.weight_threshold = 0; |
| 88 | + |
| 89 | + request_account_recovery_operation oversized_cancel; |
| 90 | + oversized_cancel.recovery_account = "alice"; |
| 91 | + oversized_cancel.account_to_recover = "bob"; |
| 92 | + oversized_cancel.new_owner_authority = oversized; |
| 93 | + |
| 94 | + HIVE_REQUIRE_ASSERT( executor->push_transaction( oversized_cancel, alice_private_key ), |
| 95 | + "size <= HIVE_MAX_AUTHORITY_MEMBERSHIP" ); |
| 96 | + |
| 97 | + executor->db->clear_pending(); |
| 98 | + executor->db_plugin->debug_push_pending_transaction( |
| 99 | + executor->build_transaction( oversized_cancel, alice_private_key ) ); |
| 100 | + |
| 101 | + if( is_hf29 ) |
| 102 | + { |
| 103 | + HIVE_REQUIRE_ASSERT( executor->generate_block_from_pending(), |
| 104 | + "size <= HIVE_MAX_AUTHORITY_MEMBERSHIP" ); |
| 105 | + // request not cancelled - still in the index with the original small authority |
| 106 | + BOOST_REQUIRE( idx.find( "bob" ) != idx.end() ); |
| 107 | + BOOST_REQUIRE_EQUAL( idx.find( "bob" )->get_new_owner_authority().key_auths.size(), 1u ); |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + executor->generate_block_from_pending(); |
| 112 | + // oversized cancellation went through - request removed |
| 113 | + BOOST_REQUIRE( idx.find( "bob" ) == idx.end() ); |
| 114 | + } |
| 115 | + }; |
| 116 | + |
| 117 | + BOOST_TEST_MESSAGE( "*****HF-28*****" ); |
| 118 | + execute_hardfork<28>( _content ); |
| 119 | + |
| 120 | + is_hf29 = true; |
| 121 | + |
| 122 | + BOOST_TEST_MESSAGE( "*****HF-29*****" ); |
| 123 | + execute_hardfork<29>( _content ); |
| 124 | + } |
| 125 | + FC_LOG_AND_RETHROW() |
| 126 | +} |
| 127 | + |
| 128 | +BOOST_AUTO_TEST_SUITE_END() |
| 129 | + |
| 130 | +#endif |
0 commit comments