diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 15c95378..29b0eeaf 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -42,24 +42,26 @@ namespace { - struct proposed_operations_digest_accumulator - { - typedef void result_type; - - template - void operator()(const T&) - {} - - void operator()(const graphene::chain::proposal_create_operation& proposal) - { - for (auto& operation: proposal.proposed_ops) - { - proposed_operations_digests.push_back(fc::digest(operation.op)); - } - } - - std::vector proposed_operations_digests; - }; + struct proposed_operations_digest_accumulator + { + typedef void result_type; + + void operator()(const graphene::chain::proposal_create_operation& proposal) + { + for (auto& operation: proposal.proposed_ops) + { + proposed_operations_digests.push_back(fc::digest(operation.op)); + } + } + + //empty template method is needed for all other operation types + //we can ignore them, we are interested in only proposal_create_operation + template + void operator()(const T&) + {} + + std::vector proposed_operations_digests; + }; } namespace graphene { namespace chain { diff --git a/tests/tests/network_broadcast_api_tests.cpp b/tests/tests/network_broadcast_api_tests.cpp index f50b61e5..e438e76b 100644 --- a/tests/tests/network_broadcast_api_tests.cpp +++ b/tests/tests/network_broadcast_api_tests.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include "../common/database_fixture.hpp" @@ -46,6 +48,16 @@ namespace return transfer; } + committee_member_create_operation make_committee_member_create_operation(const asset& fee, const account_id_type& member, const string& url) + { + committee_member_create_operation member_create_operation; + member_create_operation.fee = fee; + member_create_operation.committee_member_account = member; + member_create_operation.url = url; + + return member_create_operation; + } + void create_proposal(database_fixture& fixture, const std::vector& operations) { signed_transaction transaction; @@ -188,4 +200,58 @@ BOOST_AUTO_TEST_CASE( check_fails_for_duplicated_operation_in_existed_proposal_w } } +BOOST_AUTO_TEST_CASE( check_passes_for_different_operations_types ) +{ + try + { + ACTORS((alice)) + + create_proposal(*this, {make_transfer_operation(account_id_type(), alice_id, asset(500))}); + + auto trx = make_signed_transaction_with_proposed_operation(*this, {make_committee_member_create_operation(asset(1000), account_id_type(), "test url")}); + BOOST_CHECK_NO_THROW(db.check_tansaction_for_duplicated_operations(trx)); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( check_fails_for_same_member_create_operations ) +{ + try + { + ACTORS((alice)) + + create_proposal(*this, {make_committee_member_create_operation(asset(1000), account_id_type(), "test url")}); + + auto trx = make_signed_transaction_with_proposed_operation(*this, {make_committee_member_create_operation(asset(1000), account_id_type(), "test url")}); + BOOST_CHECK_THROW(db.check_tansaction_for_duplicated_operations(trx), fc::exception); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( check_passes_for_different_member_create_operations ) +{ + try + { + ACTORS((alice)) + + create_proposal(*this, {make_committee_member_create_operation(asset(1000), account_id_type(), "test url")}); + + auto trx = make_signed_transaction_with_proposed_operation(*this, {make_committee_member_create_operation(asset(1001), account_id_type(), "test url")}); + BOOST_CHECK_NO_THROW(db.check_tansaction_for_duplicated_operations(trx)); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END()