tests: implement new PUSH_TX / PUSH_BLOCK macros for tests
This commit is contained in:
parent
427d1a8977
commit
a219bee55d
3 changed files with 33 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue