Progress #52: The tests pass again.

This commit is contained in:
Nathan Hourt 2015-06-18 15:02:42 -04:00
parent 9291250214
commit d47c2ee2a2
8 changed files with 121 additions and 61 deletions

View file

@ -152,16 +152,47 @@ void database::init_genesis(const genesis_state_type& genesis_state)
n.active = n.owner;
n.statistics = create<account_statistics_object>( [&](account_statistics_object& b){}).id;
});
create<account_object>([this](account_object& a) {
a.name = "null-account";
FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT);
FC_ASSERT(create<account_object>([this](account_object& a) {
a.name = "witness-account";
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
a.owner = authority(1, key_id_type(), 1);
a.active = a.owner;
a.registrar = a.lifetime_referrer = a.referrer = account_id_type(1);
a.owner.weight_threshold = 1;
a.active.weight_threshold = 1;
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_WITNESS_ACCOUNT;
a.membership_expiration_date = time_point_sec::maximum();
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
});
}).get_id() == GRAPHENE_WITNESS_ACCOUNT);
FC_ASSERT(create<account_object>([this](account_object& a) {
a.name = "relaxed-committee-account";
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
a.owner.weight_threshold = 1;
a.active.weight_threshold = 1;
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_RELAXED_COMMITTEE_ACCOUNT;
a.membership_expiration_date = time_point_sec::maximum();
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
}).get_id() == GRAPHENE_RELAXED_COMMITTEE_ACCOUNT);
FC_ASSERT(create<account_object>([this](account_object& a) {
a.name = "null-account";
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
a.owner.weight_threshold = 0;
a.active.weight_threshold = 0;
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT;
a.membership_expiration_date = time_point_sec::maximum();
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
}).get_id() == GRAPHENE_NULL_ACCOUNT);
FC_ASSERT(create<account_object>([this](account_object& a) {
a.name = "temp-account";
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
a.owner.weight_threshold = 0;
a.active.weight_threshold = 0;
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_TEMP_ACCOUNT;
a.membership_expiration_date = time_point_sec::maximum();
a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
}).get_id() == GRAPHENE_TEMP_ACCOUNT);
// Create core asset
const asset_dynamic_data_object& dyn_asset =

View file

@ -117,9 +117,9 @@
* Reserved Account IDs with special meaning
*/
///@{
#define GRAPHENE_GENESIS_ACCOUNT (graphene::chain::account_id_type(0))
#define GRAPHENE_COMMITTEE_ACCOUNT (graphene::chain::account_id_type(0))
#define GRAPHENE_WITNESS_ACCOUNT (graphene::chain::account_id_type(1))
#define GRAPHENE_DELEGATE_ACCOUNT (graphene::chain::account_id_type(2))
#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT (graphene::chain::account_id_type(2))
#define GRAPHENE_NULL_ACCOUNT (graphene::chain::account_id_type(3))
#define GRAPHENE_TEMP_ACCOUNT (graphene::chain::account_id_type(4))
///@}

View file

@ -25,7 +25,9 @@
namespace graphene { namespace chain {
bool transaction_evaluation_state::check_authority( const account_object& account, authority::classification auth_class, int depth )
{
if( _skip_authority_check || approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() )
if( _skip_authority_check ||
account.get_id() == GRAPHENE_TEMP_ACCOUNT ||
approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() )
return true;
FC_ASSERT( account.id.instance() != 0 || _is_proposed_trx );

View file

@ -50,20 +50,20 @@ database_fixture::database_fixture()
boost::program_options::variables_map options;
// app.initialize();
ahplugin->plugin_set_app( &app );
ahplugin->plugin_initialize( options );
ahplugin->plugin_set_app(&app);
ahplugin->plugin_initialize(options);
secret_hash_type::encoder enc;
fc::raw::pack(enc, delegate_priv_key);
fc::raw::pack(enc, secret_hash_type());
auto secret = secret_hash_type::hash(enc.result());
for( int i = 0; i < 10; ++i )
{
genesis_state.allocation_targets.emplace_back("init"+fc::to_string(i), delegate_priv_key.get_public_key(), 0, true);
genesis_state.initial_committee.push_back({"init"+fc::to_string(i)});
auto name = "init"+fc::to_string(i);
genesis_state.allocation_targets.emplace_back(name, delegate_priv_key.get_public_key(), 0, true);
genesis_state.initial_committee.push_back({name});
genesis_state.initial_witnesses.push_back({name, delegate_priv_key.get_public_key(), secret});
}
genesis_state.initial_witnesses = vector<genesis_state_type::initial_witness_type>(10, {"committee-account",
delegate_priv_key.get_public_key(),
secret_hash_type::hash(enc.result())});
db.init_genesis(genesis_state);
ahplugin->plugin_startup();
@ -182,7 +182,7 @@ void database_fixture::verify_account_history_plugin_index( )const
return;
const std::shared_ptr<graphene::account_history::account_history_plugin> pin =
app.get_plugin<graphene::account_history::account_history_plugin>( "account_history" );
app.get_plugin<graphene::account_history::account_history_plugin>("account_history");
if( pin->tracked_accounts().size() == 0 )
{
vector< pair< account_id_type, address > > tuples_from_db;

View file

@ -274,14 +274,15 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3"));
const account_object& moneyman = create_account("moneyman");
const account_object& nathan = get_account("nathan");
const asset_object& core = asset_id_type()(db);
transfer(account_id_type()(db), account_id_type(1)(db), core.amount(1000000));
transfer(account_id_type()(db), moneyman, core.amount(1000000));
//Following any_two_of_three, nathan's active authority is satisfied by any two of {key1,key2,key3}
proposal_create_operation op = {account_id_type(1), asset(),
{{transfer_operation{asset(),nathan.id, account_id_type(1), core.amount(100)}}},
proposal_create_operation op = {moneyman.get_id(), asset(),
{{transfer_operation{asset(),nathan.id, moneyman.get_id(), core.amount(100)}}},
db.head_block_time() + fc::days(1)};
asset nathan_start_balance = db.get_balance(nathan.get_id(), core.get_id());
{
@ -289,7 +290,7 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
op.get_required_auth(active_set, owner_set);
BOOST_CHECK_EQUAL(active_set.size(), 1);
BOOST_CHECK_EQUAL(owner_set.size(), 0);
BOOST_CHECK(*active_set.begin() == account_id_type(1));
BOOST_CHECK(*active_set.begin() == moneyman.get_id());
active_set.clear();
op.proposed_ops.front().get_required_auth(active_set, owner_set);
@ -391,20 +392,29 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
trx.operations.clear();
trx.signatures.clear();
proposal_update_operation uop;
uop.fee_paying_account = account_id_type(1);
uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
uop.proposal = prop.id;
uop.key_approvals_to_add.emplace();
uop.key_approvals_to_add.emplace(1);
uop.key_approvals_to_add.emplace(2);
uop.key_approvals_to_add.emplace(3);
uop.key_approvals_to_add.emplace(4);
uop.key_approvals_to_add.emplace(5);
uop.key_approvals_to_add.emplace(6);
trx.operations.push_back(uop);
trx.sign(key_id_type(), genesis_key);
trx.sign(key_id_type(1), genesis_key);
trx.signatures[key_id_type(2)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(3)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(4)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(5)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(6)] = trx.signatures[key_id_type(1)];
db.push_transaction(trx);
BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 0);
BOOST_CHECK(db.get<proposal_object>(prop.id).is_authorized_to_execute(&db));
generate_blocks(*prop.review_period_time);
uop.key_approvals_to_add.clear();
uop.active_approvals_to_add.insert(account_id_type(1));
uop.key_approvals_to_add = {key_id_type(7)};
trx.operations.back() = uop;
trx.sign(key_id_type(), genesis_key);
trx.sign(key_id_type(7), genesis_key);
// Should throw because the transaction is now in review.
BOOST_CHECK_THROW(db.push_transaction(trx), fc::exception);
@ -440,7 +450,7 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
//A proposal is created to give nathan lots more money.
proposal_create_operation pop = proposal_create_operation::genesis_proposal(db);
pop.fee_paying_account = account_id_type(1);
pop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
pop.expiration_time = db.head_block_time() + *pop.review_period_seconds * 3;
pop.proposed_ops.emplace_back(transfer_operation({asset(),account_id_type(), nathan->id, asset(100000)}));
trx.operations.push_back(pop);
@ -451,10 +461,21 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
//Genesis key approves of the proposal.
proposal_update_operation uop;
uop.fee_paying_account = account_id_type(1);
uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
uop.proposal = prop.id;
uop.key_approvals_to_add.emplace();
uop.key_approvals_to_add.emplace(1);
uop.key_approvals_to_add.emplace(2);
uop.key_approvals_to_add.emplace(3);
uop.key_approvals_to_add.emplace(4);
uop.key_approvals_to_add.emplace(5);
uop.key_approvals_to_add.emplace(6);
trx.operations.back() = uop;
trx.sign(key_id_type(1), genesis_key);
trx.signatures[key_id_type(2)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(3)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(4)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(5)] = trx.signatures[key_id_type(1)];
trx.signatures[key_id_type(6)] = trx.signatures[key_id_type(1)];
trx.sign(key_id_type(), genesis_key);
db.push_transaction(trx);
BOOST_CHECK(prop.is_authorized_to_execute(&db));

View file

@ -55,7 +55,7 @@ genesis_state_type make_genesis() {
BOOST_AUTO_TEST_SUITE(block_tests)
BOOST_AUTO_TEST_CASE( block_database_test )
{
{
try {
fc::temp_directory data_dir;
@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE( block_database_test )
for( uint32_t i = 0; i < 5; ++i )
{
if( i > 0 ) b.previous = b.id();
b.witness = witness_id_type(i+1);
b.witness = witness_id_type(i+1);
edump((b));
bdb.store( b.id(), b );
@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( block_database_test )
idump((blk)(i));
FC_ASSERT( blk->witness == witness_id_type(blk->block_num()) );
}
auto last = bdb.last();
FC_ASSERT( last );
FC_ASSERT( last->id() == b.id() );
@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE( undo_pending )
database db;
db.open(data_dir.path(), make_genesis());
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
const graphene::db::index& account_idx = db.get_index(protocol_ids, account_object_type);
{
@ -298,14 +298,14 @@ BOOST_AUTO_TEST_CASE( undo_pending )
db.push_transaction(trx, ~0);
now += db.block_interval();
auto b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key, ~0 );
auto b = db.generate_block(now, db.get_scheduled_witness(1).first, delegate_priv_key, ~0);
}
signed_transaction trx;
trx.set_expiration( now + db.get_global_properties().parameters.maximum_time_until_expiration );
account_id_type nathan_id = account_idx.get_next_id();
account_create_operation cop;
cop.registrar = account_id_type(1);
cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
trx.operations.push_back(cop);
@ -313,20 +313,18 @@ BOOST_AUTO_TEST_CASE( undo_pending )
db.push_transaction(trx);
now += db.block_interval();
auto b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key );
auto b = db.generate_block(now, db.get_scheduled_witness(1).first, delegate_priv_key);
BOOST_CHECK(nathan_id(db).name == "nathan");
trx.clear();
trx.set_expiration(db.head_block_time() + db.get_global_properties().parameters.maximum_time_until_expiration-1);
trx.operations.push_back(transfer_operation({asset(1),account_id_type(1), nathan_id, asset(5000)}));
trx.sign( key_id_type(), delegate_priv_key );
db.push_transaction(trx);
db.push_transaction(trx, ~0);
trx.clear();
trx.set_expiration(db.head_block_time() + db.get_global_properties().parameters.maximum_time_until_expiration-2);
trx.operations.push_back(transfer_operation({asset(1),account_id_type(1), nathan_id, asset(5000)}));
trx.sign( key_id_type(), delegate_priv_key );
db.push_transaction(trx);
db.push_transaction(trx, ~0);
BOOST_CHECK(db.get_balance(nathan_id, asset_id_type()).amount == 10000);
db.clear_pending();
@ -356,7 +354,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
trx.set_expiration(now + db1.get_global_properties().parameters.maximum_time_until_expiration);
account_id_type nathan_id = account_idx.get_next_id();
account_create_operation cop;
cop.registrar = account_id_type(1);
cop.registrar = GRAPHENE_TEMP_ACCOUNT;
cop.name = "nathan";
cop.owner = authority(1, key_id_type(), 1);
trx.operations.push_back(cop);
@ -365,17 +363,17 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
auto aw = db1.get_global_properties().active_witnesses;
now += db1.block_interval();
auto b = db1.generate_block( now, db1.get_scheduled_witness( 1 ).first, delegate_priv_key );
auto b = db1.generate_block( now, db1.get_scheduled_witness(1).first, delegate_priv_key );
BOOST_CHECK(nathan_id(db1).name == "nathan");
now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
now += db2.block_interval();
b = db2.generate_block( now, db2.get_scheduled_witness( 1 ).first, delegate_priv_key );
b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key);
db1.push_block(b);
aw = db2.get_global_properties().active_witnesses;
now += db2.block_interval();
b = db2.generate_block( now, db2.get_scheduled_witness( 1 ).first, delegate_priv_key );
b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key);
db1.push_block(b);
BOOST_CHECK_THROW(nathan_id(db1), fc::exception);
@ -384,7 +382,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
aw = db2.get_global_properties().active_witnesses;
now += db2.block_interval();
b = db2.generate_block( now, db2.get_scheduled_witness( 1 ).first, delegate_priv_key );
b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key);
db1.push_block(b);
BOOST_CHECK(nathan_id(db1).name == "nathan");
@ -643,22 +641,30 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture )
{
proposal_create_operation cop = proposal_create_operation::genesis_proposal(db);
cop.fee_paying_account = account_id_type(1);
cop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
cop.expiration_time = db.head_block_time() + *cop.review_period_seconds + 10;
global_parameters_update_operation uop;
uop.new_parameters.block_interval = 1;
cop.proposed_ops.emplace_back(uop);
trx.operations.push_back(cop);
trx.sign(key_id_type(),delegate_priv_key);
db.push_transaction(trx);
}
{
proposal_update_operation uop;
uop.fee_paying_account = account_id_type(1);
uop.active_approvals_to_add = {account_id_type(1), account_id_type(2), account_id_type(3), account_id_type(4),
account_id_type(5), account_id_type(6), account_id_type(7), account_id_type(8)};
uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
uop.active_approvals_to_add = {get_account("init0").get_id(), get_account("init1").get_id(),
get_account("init2").get_id(), get_account("init3").get_id(),
get_account("init4").get_id(), get_account("init5").get_id(),
get_account("init6").get_id(), get_account("init7").get_id()};
trx.operations.push_back(uop);
trx.sign(key_id_type(),delegate_priv_key);
trx.sign(get_account("init0").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init1").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init2").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init3").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init4").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init5").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init6").active.get_keys().front(),delegate_priv_key);
trx.sign(get_account("init7").active.get_keys().front(),delegate_priv_key);
db.push_transaction(trx);
BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(&db));
}
@ -693,7 +699,7 @@ BOOST_FIXTURE_TEST_CASE( force_settlement, database_fixture )
transfer(account_id_type()(db), shorter1_id(db), asset(100000000));
transfer(account_id_type()(db), shorter2_id(db), asset(100000000));
transfer(account_id_type()(db), shorter3_id(db), asset(100000000));
asset_id_type bit_usd = create_bitasset("BITUSD", account_id_type(1), 0).get_id();
asset_id_type bit_usd = create_bitasset("BITUSD", GRAPHENE_TEMP_ACCOUNT, 0).get_id();
{
asset_update_bitasset_operation op;
op.asset_to_update = bit_usd;

View file

@ -308,10 +308,11 @@ BOOST_AUTO_TEST_CASE( update_mia )
trx.operations.back() = op;
db.push_transaction(trx, ~0);
idump((bit_usd));
{
asset_publish_feed_operation pop;
pop.asset_id = bit_usd.get_id();
pop.publisher = account_id_type(1);
pop.publisher = get_account("init0").get_id();
price_feed feed;
feed.call_limit = price(bit_usd.amount(5), bit_usd.amount(5));
feed.short_limit = feed.call_limit;
@ -1949,6 +1950,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION);
// last one was unpaid, so pull out a paid one for checks
witness = paid_witness;
wdump((*witness));
// Withdraw the witness's pay
enable_fees(1);
witness_withdraw_pay_operation wop;
@ -1960,8 +1962,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
trx.operations.back() = wop;
trx.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate();
trx.sign(key_id_type(),delegate_priv_key);
db.push_transaction(trx);
db.push_transaction(trx, database::skip_authority_check);
trx.clear();
BOOST_CHECK_EQUAL(get_balance(witness->witness_account(db), *core), witness_ppb - 1/*fee*/);

View file

@ -446,8 +446,7 @@ BOOST_AUTO_TEST_CASE( witness_create )
generator_helper h = std::for_each(near_witnesses.begin(), near_witnesses.end(),
generator_helper{*this, nathan_witness_id, nathan_private_key, false});
BOOST_CHECK(h.nathan_generated_block);
generate_block();
generate_block(0, nathan_private_key);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( global_settle_test )
@ -694,7 +693,7 @@ BOOST_AUTO_TEST_CASE( force_settlement_unavailable )
transfer(account_id_type()(db), shorter1_id(db), asset(100000000));
transfer(account_id_type()(db), shorter2_id(db), asset(100000000));
transfer(account_id_type()(db), shorter3_id(db), asset(100000000));
asset_id_type bit_usd = create_bitasset("BITUSD", account_id_type(1), 0, disable_force_settle).get_id();
asset_id_type bit_usd = create_bitasset("BITUSD", GRAPHENE_TEMP_ACCOUNT, 0, disable_force_settle).get_id();
FC_ASSERT( bit_usd(db).is_market_issued() );
{
asset_update_bitasset_operation op;
@ -757,7 +756,7 @@ BOOST_AUTO_TEST_CASE( force_settlement_unavailable )
{
//Enable force settlement
asset_update_operation op;
op.issuer = account_id_type(1);
op.issuer = bit_usd(db).issuer;
op.asset_to_update = bit_usd;
op.new_options = bit_usd(db).options;
op.new_options.flags &= ~disable_force_settle;
@ -786,7 +785,7 @@ BOOST_AUTO_TEST_CASE( force_settlement_unavailable )
{
//Disable force settlement
asset_update_operation op;
op.issuer = account_id_type(1);
op.issuer = bit_usd(db).issuer;
op.asset_to_update = bit_usd;
op.new_options = bit_usd(db).options;
op.new_options.flags |= disable_force_settle;