Refactoring after review.

This commit is contained in:
Apr Team 2018-07-06 15:29:15 +03:00
parent e6f56af1b6
commit 8094431613
2 changed files with 86 additions and 18 deletions

View file

@ -42,24 +42,26 @@
namespace { namespace {
struct proposed_operations_digest_accumulator struct proposed_operations_digest_accumulator
{ {
typedef void result_type; typedef void result_type;
template<class T> void operator()(const graphene::chain::proposal_create_operation& proposal)
void operator()(const T&) {
{} for (auto& operation: proposal.proposed_ops)
{
void operator()(const graphene::chain::proposal_create_operation& proposal) proposed_operations_digests.push_back(fc::digest(operation.op));
{ }
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<class T>
void operator()(const T&)
std::vector<fc::sha256> proposed_operations_digests; {}
};
std::vector<fc::sha256> proposed_operations_digests;
};
} }
namespace graphene { namespace chain { namespace graphene { namespace chain {

View file

@ -27,6 +27,8 @@
#include <graphene/chain/exceptions.hpp> #include <graphene/chain/exceptions.hpp>
#include <graphene/chain/protocol/proposal.hpp> #include <graphene/chain/protocol/proposal.hpp>
#include <graphene/chain/proposal_object.hpp> #include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/protocol/committee_member.hpp>
#include <fc/crypto/digest.hpp> #include <fc/crypto/digest.hpp>
#include "../common/database_fixture.hpp" #include "../common/database_fixture.hpp"
@ -46,6 +48,16 @@ namespace
return transfer; 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<operation>& operations) void create_proposal(database_fixture& fixture, const std::vector<operation>& operations)
{ {
signed_transaction transaction; 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() BOOST_AUTO_TEST_SUITE_END()