From 9fd4fe6713e0ba027b32dd0013cebdf16f6b8794 Mon Sep 17 00:00:00 2001 From: Apr Team Date: Wed, 4 Jul 2018 19:49:05 +0300 Subject: [PATCH] Added couple of tests. --- tests/tests/network_broadcast_api_tests.cpp | 96 +++++++++++---------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/tests/tests/network_broadcast_api_tests.cpp b/tests/tests/network_broadcast_api_tests.cpp index 5b87c3ab..d29f2ac8 100644 --- a/tests/tests/network_broadcast_api_tests.cpp +++ b/tests/tests/network_broadcast_api_tests.cpp @@ -24,56 +24,18 @@ * THE SOFTWARE. */ -#include +#include #include -#include - +#include +#include #include -#include - #include "../common/database_fixture.hpp" using namespace graphene::chain; using namespace graphene::chain::test; -//void database_fixture::transfer( -// account_id_type from, -// account_id_type to, -// const asset& amount, -// const asset& fee /* = asset() */ -//) -//{ -// transfer(from(db), to(db), amount, fee); -//} -// -//void database_fixture::transfer( -// const account_object& from, -// const account_object& to, -// const asset& amount, -// const asset& fee /* = asset() */ ) -//{ -// try -// { -// set_expiration( db, trx ); -// transfer_operation trans; -// trans.from = from.id; -// trans.to = to.id; -// trans.amount = amount; -// trx.operations.push_back(trans); -// -// if( fee == asset() ) -// { -// for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); -// } -// trx.validate(); -// db.push_transaction(trx, ~0); -// verify_asset_supplies(db); -// trx.operations.clear(); -// } FC_CAPTURE_AND_RETHROW( (from.id)(to.id)(amount)(fee) ) -//} - namespace { transfer_operation make_transfer_operation(const account_id_type& from, const account_id_type& to, const asset& amount) @@ -139,18 +101,18 @@ namespace for (auto& digest: digest_accumulator.proposed_operations_digests) { - FC_ASSERT(existed_operations_digests.count(digest) == 0, "Proposed operation already pending for approval."); + FC_ASSERT(existed_operations_digests.count(digest) == 0, "Proposed operation is already pending for approval."); } } } -BOOST_FIXTURE_TEST_SUITE( check_transactions_duplicates, database_fixture ) +BOOST_FIXTURE_TEST_SUITE( check_transactions_duplicates_tests, database_fixture ) BOOST_AUTO_TEST_CASE( test_exception_throwing_for_the_same_operation_proposed_twice ) { try { - ACTORS((alice)(bob)) + ACTORS((alice)) ::propose_operation(*this, make_transfer_operation(account_id_type(), alice_id, asset(500))); @@ -170,4 +132,50 @@ BOOST_AUTO_TEST_CASE( test_exception_throwing_for_the_same_operation_proposed_tw } } +BOOST_AUTO_TEST_CASE( test_check_passes_without_duplication ) +{ + try + { + ACTORS((alice)) + + proposal_create_operation operation_proposal; + operation_proposal.proposed_ops = {op_wrapper(make_transfer_operation(account_id_type(), alice_id, asset(500)))}; + + signed_transaction trx; + set_expiration( db, trx ); + trx.operations = {operation_proposal}; + + BOOST_CHECK_NO_THROW(check_transactions_duplicates(db, trx)); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( test_exception_throwing_for_the_same_operation_with_different_assets ) +{ + try + { + ACTORS((alice)) + + ::propose_operation(*this, make_transfer_operation(account_id_type(), alice_id, asset(500))); + + proposal_create_operation operation_proposal; + operation_proposal.proposed_ops = {op_wrapper(make_transfer_operation(account_id_type(), alice_id, asset(501)))}; + + signed_transaction trx; + set_expiration( db, trx ); + trx.operations = {operation_proposal}; + + BOOST_CHECK_NO_THROW(check_transactions_duplicates(db, trx)); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END()