From a219bee55d1ff8685ecd51ca27160a767d44cca0 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 17 Jun 2015 16:07:50 -0400 Subject: [PATCH] tests: implement new PUSH_TX / PUSH_BLOCK macros for tests --- tests/common/database_fixture.cpp | 19 ++++++++++++++----- tests/common/database_fixture.hpp | 15 +++++++++++---- tests/tests/authority_tests.cpp | 16 ++++++++-------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index fcecaa43..dd48a508 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -92,11 +92,6 @@ string database_fixture::generate_anon_acct_name() return "anon-acct-x" + std::to_string( anon_acct_count++ ); } -void database_fixture::_push_transaction( const signed_transaction& tx, uint32_t skip_flags, const char* file, int line ) -{ - db.push_transaction( tx, skip_flags ); -} - void database_fixture::verify_asset_supplies( )const { wlog("*** Begin asset supply verification ***"); @@ -882,4 +877,18 @@ int64_t database_fixture::get_balance( const account_object& account, const asse return db.get_balance(account.get_id(), a.get_id()).amount.value; } +namespace test { + +bool _push_block( database& db, const signed_block& b, uint32_t skip_flags /* = 0 */ ) +{ + return db.push_block( b, skip_flags); +} + +processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags /* = 0 */ ) +{ + return db.push_transaction( tx, skip_flags ); +} + +} // graphene::chain::test + } } // graphene::chain diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 649df558..8ca1e1b6 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -24,6 +24,12 @@ using namespace graphene::db; +#define PUSH_TX \ + graphene::chain::test::_push_transaction + +#define PUSH_BLOCK \ + graphene::chain::test::_push_block + // See below #define REQUIRE_OP_VALIDATION_SUCCESS( op, field, value ) \ { \ @@ -65,9 +71,6 @@ using namespace graphene::db; /// i.e. This allows a test on update_account to begin with the database at the end state of create_account. #define INVOKE(test) ((struct test*)this)->test_method(); trx.clear() -#define PUSH_TX( tx, skip_flags ) \ - _push_transaction( tx, skip_flags, __FILE__, __LINE__ ) - #define PREP_ACTOR(name) \ fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name)); \ key_id_type name ## _key_id = register_key(name ## _private_key.get_public_key()).get_id(); @@ -108,7 +111,6 @@ struct database_fixture { static fc::ecc::private_key generate_private_key(string seed); string generate_anon_acct_name(); - void _push_transaction( const signed_transaction& tx, uint32_t skip_flags, const char* file, int line ); void verify_asset_supplies( )const; void verify_account_history_plugin_index( )const; void open_database(); @@ -220,4 +222,9 @@ struct database_fixture { int64_t get_balance( const account_object& account, const asset_object& a )const; }; +namespace test { +bool _push_block( database& db, const signed_block& b, uint32_t skip_flags = 0 ); +processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags = 0 ); +} + } } diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index 4ce9740d..f6bee06f 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -943,38 +943,38 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) wdump( (active_set)(owner_set)(alice_key_id) (alice_account_object) ); - PUSH_TX( trx, skip ); + db.push_transaction( trx, skip ); trx.operations.push_back( xfer_op ); // Alice's signature is now invalid edump((trx)); - BOOST_REQUIRE_THROW( PUSH_TX( trx, skip ), fc::exception ); + BOOST_REQUIRE_THROW( db.push_transaction( trx, skip ), fc::exception ); // Re-sign, now OK (sig is replaced) trx.sign( alice_key_id, alice_key ); - PUSH_TX( trx, skip ); + db.push_transaction( trx, skip ); trx.signatures.clear(); trx.sign( charlie_key_id, alice_key ); // Sign with Alice's key (valid) claiming to be Charlie - BOOST_REQUIRE_THROW( PUSH_TX( trx, skip ), fc::exception ); + BOOST_REQUIRE_THROW( db.push_transaction( trx, skip ), fc::exception ); // and with Charlie's key (invalid) claiming to be Alice trx.sign( charlie_key_id, alice_key ); - BOOST_REQUIRE_THROW( PUSH_TX( trx, skip ), fc::exception ); + BOOST_REQUIRE_THROW( db.push_transaction( trx, skip ), fc::exception ); trx.signatures.clear(); // okay, now sign ONLY with Charlie's key claiming to be Alice trx.sign( charlie_key_id, alice_key ); - BOOST_REQUIRE_THROW( PUSH_TX( trx, skip ), fc::exception ); + BOOST_REQUIRE_THROW( db.push_transaction( trx, skip ), fc::exception ); trx.signatures.clear(); trx.operations.pop_back(); trx.sign( alice_key_id, alice_key ); trx.sign( charlie_key_id, charlie_key ); // Signed by third-party Charlie (irrelevant key, not in authority) - PUSH_TX( trx, skip ); + db.push_transaction( trx, skip ); trx.operations.push_back( xfer_op ); trx.sign( alice_key_id, alice_key ); // Alice's sig is valid but Charlie's is invalid - BOOST_REQUIRE_THROW( PUSH_TX( trx, skip ), fc::exception ); + BOOST_REQUIRE_THROW( db.push_transaction( trx, skip ), fc::exception ); } FC_LOG_AND_RETHROW() }