Fix all outstanding unexpected test failures

This commit is contained in:
Nathan Hourt 2015-07-01 13:53:04 -04:00
parent e336691e59
commit f29eaa92e2
4 changed files with 56 additions and 45 deletions

View file

@ -454,9 +454,10 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
for( const auto& sig : trx.signatures ) for( const auto& sig : trx.signatures )
{ {
FC_ASSERT( eval_state._sigs.insert( std::make_pair( public_key_type(fc::ecc::public_key( sig, trx.digest() )), false) ).second, "Multiple signatures by same key detected" ) ; FC_ASSERT( eval_state._sigs.insert(std::make_pair(public_key_type(fc::ecc::public_key(sig, trx.digest())),
false)).second,
"Multiple signatures by same key detected" );
} }
} }
//If we're skipping tapos check, but not dupe check, assume all transactions have maximum expiration time. //If we're skipping tapos check, but not dupe check, assume all transactions have maximum expiration time.
@ -522,8 +523,8 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
ref_block_height = uint32_t( x0 ); ref_block_height = uint32_t( x0 );
} }
const block_summary_object& tapos_block_summary const block_summary_object& tapos_block_summary =
= static_cast<const block_summary_object&>( static_cast<const block_summary_object&>(
get_index<block_summary_object>() get_index<block_summary_object>()
.get(block_summary_id_type(ref_block_height)) .get(block_summary_id_type(ref_block_height))
); );
@ -535,9 +536,12 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
for( const auto& sig : trx.signatures ) for( const auto& sig : trx.signatures )
{ {
FC_ASSERT(eval_state._sigs.insert( FC_ASSERT(eval_state._sigs.insert(std::make_pair(
std::make_pair(public_key_type(fc::ecc::public_key(sig, trx.digest(tapos_block_summary.block_id) )), public_key_type(
false)).second, "Multiple signatures by same key detected"); fc::ecc::public_key(sig,
trx.digest(tapos_block_summary.block_id))),
false)).second,
"Multiple signatures by same key detected");
} }
} }
@ -581,6 +585,7 @@ processed_transaction database::_apply_transaction( const signed_transaction& tr
auto range = index.equal_range(GRAPHENE_TEMP_ACCOUNT); auto range = index.equal_range(GRAPHENE_TEMP_ACCOUNT);
std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); }); std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); });
//Make sure all signatures were needed to validate the transaction
if( !(skip & (skip_transaction_signatures|skip_authority_check)) ) if( !(skip & (skip_transaction_signatures|skip_authority_check)) )
{ {
for( const auto& item : eval_state._sigs ) for( const auto& item : eval_state._sigs )

View file

@ -36,7 +36,6 @@ digest_type processed_transaction::merkle_digest()const
digest_type transaction::digest()const digest_type transaction::digest()const
{ {
//Only use this digest() for transactions with absolute expiration times. //Only use this digest() for transactions with absolute expiration times.
if( relative_expiration != 0 ) edump((*this));
assert(relative_expiration == 0); assert(relative_expiration == 0);
digest_type::encoder enc; digest_type::encoder enc;
fc::raw::pack( enc, *this ); fc::raw::pack( enc, *this );
@ -64,7 +63,7 @@ void graphene::chain::signed_transaction::sign( const private_key_type& key )
{ {
if( relative_expiration != 0 ) if( relative_expiration != 0 )
{ {
if( !block_id_cache.valid() ) edump((*this)); // Relative expiration is set, meaning we must include the block ID in the signature
assert(block_id_cache.valid()); assert(block_id_cache.valid());
signatures.push_back(key.sign_compact(digest(*block_id_cache))); signatures.push_back(key.sign_compact(digest(*block_id_cache)));
} else { } else {

View file

@ -599,9 +599,10 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
BOOST_TEST_MESSAGE( "Verify that not-signing causes an exception" ); BOOST_TEST_MESSAGE( "Verify that not-signing causes an exception" );
BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception );
trx.sign( to_private_key );
BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" ); BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" );
trx.sign(to_private_key);
trx.sign(to_private_key);
BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception );
BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" ); BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" );
@ -610,6 +611,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception );
BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" ); BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" );
trx.signatures.pop_back();
db.push_transaction(trx, 0); db.push_transaction(trx, 0);
trx.sign(to_private_key); trx.sign(to_private_key);

View file

@ -124,16 +124,19 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test )
REQUIRE_THROW_WITH_VALUE(op, amount_to_withdraw, asset(6)); REQUIRE_THROW_WITH_VALUE(op, amount_to_withdraw, asset(6));
trx.clear(); trx.clear();
trx.operations.push_back(op); trx.operations.push_back(op);
trx.sign(dan_key_id, dan_private_key); trx.sign(dan_private_key);
PUSH_TX( db, trx ); PUSH_TX( db, trx );
// would be legal on its own, but doesn't work because trx already withdrew // would be legal on its own, but doesn't work because trx already withdrew
REQUIRE_THROW_WITH_VALUE(op, amount_to_withdraw, asset(5)); REQUIRE_THROW_WITH_VALUE(op, amount_to_withdraw, asset(5));
// Make sure we can withdraw again this period, as long as we're not exceeding the periodic limit // Make sure we can withdraw again this period, as long as we're not exceeding the periodic limit
trx.operations.back() = op; // withdraw 1 trx.clear();
trx.ref_block_prefix++; // make it different from previous trx so it's non-duplicate // withdraw 1
trx.sign(dan_key_id, dan_private_key); trx.operations = {op};
// make it different from previous trx so it's non-duplicate
trx.ref_block_prefix++;
trx.sign(dan_private_key);
PUSH_TX( db, trx ); PUSH_TX( db, trx );
trx.clear(); trx.clear();
} }
@ -163,11 +166,12 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test )
op.withdraw_to_account = dan_id; op.withdraw_to_account = dan_id;
op.amount_to_withdraw = asset(5); op.amount_to_withdraw = asset(5);
trx.operations.push_back(op); trx.operations.push_back(op);
trx.sign(dan_key_id, dan_private_key); trx.sign(dan_private_key);
//Throws because nathan doesn't have the money //Throws because nathan doesn't have the money
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
op.amount_to_withdraw = asset(1); op.amount_to_withdraw = asset(1);
trx.operations.back() = op; trx.clear();
trx.operations = {op};
trx.sign(dan_key_id, dan_private_key); trx.sign(dan_key_id, dan_private_key);
PUSH_TX( db, trx ); PUSH_TX( db, trx );
} }
@ -197,7 +201,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test )
op.withdraw_to_account = dan_id; op.withdraw_to_account = dan_id;
op.amount_to_withdraw = asset(5); op.amount_to_withdraw = asset(5);
trx.operations.push_back(op); trx.operations.push_back(op);
trx.sign(dan_key_id, dan_private_key); trx.sign(dan_private_key);
//Throws because the permission has expired //Throws because the permission has expired
BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); BOOST_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
} }
@ -388,7 +392,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_test )
op.asset_to_update = bit_usd.get_id(); op.asset_to_update = bit_usd.get_id();
op.issuer = bit_usd.issuer; op.issuer = bit_usd.issuer;
trx.operations = {op}; trx.operations = {op};
trx.sign(nathan_key_id, nathan_private_key); trx.sign(nathan_private_key);
db.push_transaction(trx); db.push_transaction(trx);
BOOST_TEST_MESSAGE("Checking current_feed is null"); BOOST_TEST_MESSAGE("Checking current_feed is null");
@ -396,8 +400,9 @@ BOOST_AUTO_TEST_CASE( feed_limit_test )
BOOST_TEST_MESSAGE("Setting minimum feeds to 3"); BOOST_TEST_MESSAGE("Setting minimum feeds to 3");
op.new_options.minimum_feeds = 3; op.new_options.minimum_feeds = 3;
trx.clear();
trx.operations = {op}; trx.operations = {op};
trx.sign(nathan_key_id, nathan_private_key); trx.sign(nathan_private_key);
db.push_transaction(trx); db.push_transaction(trx);
BOOST_TEST_MESSAGE("Checking current_feed is not null"); BOOST_TEST_MESSAGE("Checking current_feed is not null");