From a164fbe8fab47b4085aeb12fac82064bd6c7ee06 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 9 Jul 2015 15:14:44 -0400 Subject: [PATCH] fix proposal authority --- .../graphene/chain/protocol/proposal.hpp | 3 +++ libraries/chain/protocol/proposal.cpp | 22 +++++++++++++++++++ tests/tests/block_tests.cpp | 8 +++++++ 3 files changed, 33 insertions(+) diff --git a/libraries/chain/include/graphene/chain/protocol/proposal.hpp b/libraries/chain/include/graphene/chain/protocol/proposal.hpp index cb3ef24f..97d0219d 100644 --- a/libraries/chain/include/graphene/chain/protocol/proposal.hpp +++ b/libraries/chain/include/graphene/chain/protocol/proposal.hpp @@ -105,6 +105,9 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return fee_paying_account; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; + void get_required_authorities( vector& )const; + void get_required_active_authorities( flat_set& )const; + void get_required_owner_authorities( flat_set& )const; }; /** diff --git a/libraries/chain/protocol/proposal.cpp b/libraries/chain/protocol/proposal.cpp index 6f866929..beb1b8a9 100644 --- a/libraries/chain/protocol/proposal.cpp +++ b/libraries/chain/protocol/proposal.cpp @@ -63,4 +63,26 @@ void proposal_create_operation::get_impacted_accounts( flat_set for( auto& o : other ) add_authority_accounts( i, o ); } + +void proposal_update_operation::get_required_authorities( vector& o )const +{ + authority auth; + for( const auto& k : key_approvals_to_add ) + auth.key_auths[k] = 1; + for( const auto& k : key_approvals_to_remove ) + auth.key_auths[k] = 1; + auth.weight_threshold = auth.key_auths.size(); + + o.emplace_back( std::move(auth) ); +} +void proposal_update_operation::get_required_active_authorities( flat_set& a )const +{ + for( const auto& i : active_approvals_to_add ) a.insert(i); + for( const auto& i : active_approvals_to_remove ) a.insert(i); +} +void proposal_update_operation::get_required_owner_authorities( flat_set& a )const +{ + for( const auto& i : owner_approvals_to_add ) a.insert(i); + for( const auto& i : owner_approvals_to_remove ) a.insert(i); +} } } // graphene::chain diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 74b51eae..03b243e2 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -642,6 +642,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) p.parameters.committee_proposal_review_period = fc::hours(1).to_seconds(); }); + BOOST_TEST_MESSAGE( "Creating a proposal to change the block_interval to 1 second" ); { proposal_create_operation cop = proposal_create_operation::genesis_proposal(db.get_global_properties().parameters, db.head_block_time()); cop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; @@ -652,6 +653,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) trx.operations.push_back(cop); db.push_transaction(trx); } + BOOST_TEST_MESSAGE( "Updating proposal by signing with the delegate private key" ); { proposal_update_operation uop; uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; @@ -673,6 +675,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) db.push_transaction(trx); BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(db)); } + BOOST_TEST_MESSAGE( "Verifying that the interval didn't change immediately" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 5); auto past_time = db.head_block_time().sec_since_epoch(); @@ -681,10 +684,15 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) generate_block(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 10); + BOOST_TEST_MESSAGE( "Generating blocks until proposal expires" ); generate_blocks(proposal_id_type()(db).expiration_time + 5); + BOOST_TEST_MESSAGE( "Verify that the block interval is still 5 seconds" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 5); + + BOOST_TEST_MESSAGE( "Generating blocks until next maintenance interval" ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + BOOST_TEST_MESSAGE( "Verify that the new block interval is 1 second" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 1); past_time = db.head_block_time().sec_since_epoch(); generate_block();