From 929125021431860146278e21595ff1389443ba5b Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 18 Jun 2015 09:19:14 -0400 Subject: [PATCH 1/3] Issue #52: working my way out of the rabbit hole Evils abound. And tests still fail. --- libraries/chain/db_init.cpp | 264 ++++++++---------- libraries/chain/db_maint.cpp | 2 +- libraries/chain/db_management.cpp | 4 +- .../include/graphene/chain/account_object.hpp | 4 +- .../chain/include/graphene/chain/database.hpp | 8 +- libraries/db/object_database.cpp | 2 +- libraries/plugins/witness/witness.cpp | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 6 +- libraries/wallet/wallet.cpp | 6 +- programs/cli_wallet/main.cpp | 2 +- tests/app/main.cpp | 2 +- tests/benchmarks/genesis_allocation.cpp | 2 +- tests/common/database_fixture.cpp | 21 +- tests/common/database_fixture.hpp | 9 +- tests/intense/block_tests.cpp | 2 +- tests/performance/performance_tests.cpp | 2 +- tests/tests/authority_tests.cpp | 14 +- tests/tests/block_tests.cpp | 80 +++--- tests/tests/operation_tests.cpp | 12 +- tests/tests/operation_tests2.cpp | 2 +- 20 files changed, 230 insertions(+), 216 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 7f4d3b90..e65cdf94 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -129,112 +129,45 @@ void database::initialize_indexes() void database::init_genesis(const genesis_state_type& genesis_state) { try { - _undo_db.disable(); + FC_ASSERT(genesis_state.initial_witnesses.size() > 0, + "Cannot start a chain with zero witnesses."); - fc::ecc::private_key genesis_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); - const key_object& genesis_key = - create( [&genesis_private_key](key_object& k) { - k.key_data = public_key_type(genesis_private_key.get_public_key()); - }); - const account_statistics_object& genesis_statistics = - create( [&](account_statistics_object& b){ - }); + _undo_db.disable(); + transaction_evaluation_state genesis_eval_state(this, true); + + // Create initial accounts + fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + create( [&null_private_key](key_object& k) { + k.key_data = public_key_type(null_private_key.get_public_key()); + }); create( [](account_balance_object& b) { b.balance = GRAPHENE_INITIAL_SUPPLY; }); - const account_object& genesis_account = + const account_object& committee_account = create( [&](account_object& n) { n.membership_expiration_date = time_point_sec::maximum(); n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; n.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - n.name = "genesis"; - n.owner.add_authority(genesis_key.get_id(), 1); - n.owner.weight_threshold = 1; + n.name = "committee-account"; n.active = n.owner; - n.options.memo_key = genesis_key.id; - n.statistics = genesis_statistics.id; + n.statistics = create( [&](account_statistics_object& b){}).id; }); - - vector init_delegates; - vector init_witnesses; - flat_set init_witness_set; - - auto delegates_and_witnesses = std::max(GRAPHENE_MIN_WITNESS_COUNT, GRAPHENE_MIN_DELEGATE_COUNT); - for( int i = 0; i < delegates_and_witnesses; ++i ) - { - const account_statistics_object& stats_obj = - create( [&](account_statistics_object&){ - }); - const account_object& delegate_account = - create( [&](account_object& a) { - a.active = a.owner = genesis_account.owner; - a.referrer = account_id_type(i); - a.registrar = account_id_type(i); - a.lifetime_referrer = account_id_type(i); - a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - a.membership_expiration_date = fc::time_point_sec::maximum(); - a.name = string("init") + fc::to_string(i); - a.statistics = stats_obj.id; - }); - const delegate_object& init_delegate = create( [&](delegate_object& d) { - d.delegate_account = delegate_account.id; - d.vote_id = i * 2; - }); - init_delegates.push_back(init_delegate.id); - - const witness_object& init_witness = create( [&](witness_object& d) { - d.witness_account = delegate_account.id; - d.vote_id = i * 2 + 1; - secret_hash_type::encoder enc; - fc::raw::pack( enc, genesis_private_key ); - fc::raw::pack( enc, d.last_secret ); - d.next_secret = secret_hash_type::hash(enc.result()); - }); - init_witnesses.push_back(init_witness.id); - init_witness_set.insert(init_witness.id); - - } - create( [&](block_summary_object& p) { + create([this](account_object& a) { + a.name = "null-account"; + a.statistics = create([](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.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; }); - const witness_schedule_object& wso = - create( [&]( witness_schedule_object& _wso ) - { - memset( _wso.rng_seed.begin(), 0, _wso.rng_seed.size() ); - - witness_scheduler_rng rng( _wso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV ); - - _wso.scheduler = witness_scheduler(); - _wso.scheduler._min_token_count = init_witnesses.size() / 2; - _wso.scheduler.update( init_witness_set ); - - for( size_t i=0; i( [&](global_property_object& p) { - p.active_delegates = init_delegates; - for( const witness_id_type& wit : init_witnesses ) - p.active_witnesses.insert( wit ); - p.next_available_vote_id = delegates_and_witnesses * 2; - p.chain_id = fc::digest(genesis_state); - }); - (void)properties; - - create( [&](dynamic_global_property_object& p) { - p.time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP ); - }); - + // Create core asset const asset_dynamic_data_object& dyn_asset = create( [&]( asset_dynamic_data_object& a ) { a.current_supply = GRAPHENE_INITIAL_SUPPLY; }); - const asset_object& core_asset = create( [&]( asset_object& a ) { a.symbol = GRAPHENE_SYMBOL; @@ -242,7 +175,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; a.options.flags = 0; a.options.issuer_permissions = 0; - a.issuer = genesis_account.id; + a.issuer = committee_account.id; a.options.core_exchange_rate.base.amount = 1; a.options.core_exchange_rate.base.asset_id = 0; a.options.core_exchange_rate.quote.amount = 1; @@ -253,74 +186,71 @@ void database::init_genesis(const genesis_state_type& genesis_state) assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) ); (void)core_asset; + // Create global properties + create([&](global_property_object& p) { + p.chain_id = fc::digest(genesis_state); + }); + create( [&](dynamic_global_property_object& p) { + p.time = fc::time_point_sec(GRAPHENE_GENESIS_TIMESTAMP); + }); + create([&](block_summary_object& p) { + }); + + // Create user accounts, apply initial stake allocation if( !genesis_state.allocation_targets.empty() ) { share_type total_allocation = 0; for( const auto& handout : genesis_state.allocation_targets ) total_allocation += handout.weight; - auto mangle_to_name = [](const fc::static_variant& key) { - string addr = string(key.which() == std::decay::type::tag
::value? key.get
() - : key.get()); - string result = "import"; - string key_string = string(addr).substr(sizeof(GRAPHENE_ADDRESS_PREFIX)-1); - for( char c : key_string ) - { - if( isupper(c) ) - result += string("-") + char(tolower(c)); - else - result += c; - } - return result; - }; - fc::time_point start_time = fc::time_point::now(); for( const auto& handout : genesis_state.allocation_targets ) { asset amount(handout.weight); - amount.amount = ((fc::uint128(amount.amount.value) * GRAPHENE_INITIAL_SUPPLY)/total_allocation.value).to_uint64(); - if( amount.amount == 0 ) - { - wlog("Skipping zero allocation to ${k}", ("k", handout.name)); - continue; - } - signed_transaction trx; - trx.operations.emplace_back(key_create_operation({asset(), genesis_account.id, handout.addr})); - relative_key_id_type key_id(0); - authority account_authority(1, key_id, 1); + key_id_type key_id = apply_operation(genesis_eval_state, key_create_operation({asset(), committee_account.id, handout.addr})).get(); account_create_operation cop; cop.name = handout.name; cop.registrar = account_id_type(1); - cop.active = account_authority; - cop.owner = account_authority; + cop.active = authority(1, key_id, 1); + cop.owner = cop.active; cop.options.memo_key = key_id; - trx.operations.push_back(cop); - trx.validate(); - auto ptrx = apply_transaction(trx, ~0); - trx = signed_transaction(); - account_id_type account_id(ptrx.operation_results.back().get()); - trx.operations.emplace_back(transfer_operation({ asset(), - genesis_account.id, - account_id, - amount, - memo_data()//vector() - })); - trx.validate(); - apply_transaction(trx, ~0); + account_id_type account_id(apply_operation(genesis_eval_state, cop).get()); + + if( handout.is_lifetime_member ) + { + account_upgrade_operation op; + op.account_to_upgrade = account_id; + op.upgrade_to_lifetime_member = true; + apply_operation(genesis_eval_state, op); + } + + if( amount.amount > 0 ) + { + amount.amount = ((fc::uint128(amount.amount.value) * GRAPHENE_INITIAL_SUPPLY)/total_allocation.value).to_uint64(); + apply_operation(genesis_eval_state, transfer_operation({asset(), + committee_account.id, + account_id, + amount, + memo_data() + })); + } } - asset leftovers = get_balance(account_id_type(), asset_id_type()); - if( leftovers.amount > 0 ) + if( total_allocation != 0 ) { - modify(*get_index_type().indices().get().find(boost::make_tuple(account_id_type(), asset_id_type())), - [](account_balance_object& b) { - b.adjust_balance(-b.get_balance()); - }); - modify(core_asset.dynamic_asset_data_id(*this), [&leftovers](asset_dynamic_data_object& d) { - d.accumulated_fees += leftovers.amount; - }); + asset leftovers = get_balance(account_id_type(), asset_id_type()); + if( leftovers.amount > 0 ) + { + modify(*get_index_type().indices().get().find(boost::make_tuple(account_id_type(), asset_id_type())), + [](account_balance_object& b) { + b.adjust_balance(-b.get_balance()); + }); + modify(core_asset.dynamic_asset_data_id(*this), [&leftovers](asset_dynamic_data_object& d) { + d.accumulated_fees += leftovers.amount; + }); + } } fc::microseconds duration = fc::time_point::now() - start_time; @@ -328,6 +258,60 @@ void database::init_genesis(const genesis_state_type& genesis_state) ("n", genesis_state.allocation_targets.size())("t", duration.count() / 1000)); } + flat_set init_delegates; + flat_set init_witnesses; + const auto& accounts_by_name = get_index_type().indices().get(); + + // Create initial witnesses and delegates + std::for_each(genesis_state.initial_witnesses.begin(), genesis_state.initial_witnesses.end(), + [&](const genesis_state_type::initial_witness_type& witness) { + const account_object& witness_account = *accounts_by_name.find(witness.owner_name); + const key_object& signing_key = create([&witness](key_object& k) { k.key_data = witness.block_signing_key; }); + + witness_create_operation op; + op.block_signing_key = signing_key.get_id(); + op.initial_secret = witness.initial_secret; + op.witness_account = witness_account.get_id(); + witness_id_type id = apply_operation(genesis_eval_state, op).get(); + init_witnesses.emplace(id); + }); + std::for_each(genesis_state.initial_committee.begin(), genesis_state.initial_committee.end(), + [&](const genesis_state_type::initial_committee_member_type& member) { + const account_object& member_account = *accounts_by_name.find(member.owner_name); + delegate_create_operation op; + op.delegate_account = member_account.get_id(); + delegate_id_type id = apply_operation(genesis_eval_state, op).get(); + init_delegates.emplace(id); + }); + + // Set initial witnesses and committee as active + modify(get_global_properties(), [&](global_property_object& p) { + p.active_delegates = vector(init_delegates.begin(), init_delegates.end()); + p.active_witnesses = init_witnesses; + std::transform(p.active_witnesses.begin(), p.active_witnesses.end(), + std::inserter(p.witness_accounts, p.witness_accounts.begin()), + [&](witness_id_type id) { return get(id).witness_account; }); + }); + + // Initialize witness schedule + const witness_schedule_object& wso = + create([&](witness_schedule_object& _wso) + { + memset(_wso.rng_seed.begin(), 0, _wso.rng_seed.size()); + + witness_scheduler_rng rng(_wso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV); + + _wso.scheduler = witness_scheduler(); + _wso.scheduler._min_token_count = init_witnesses.size() / 2; + _wso.scheduler.update(init_witnesses); + + for( size_t i=0; i, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, member > > - > account_object_multi_index_type; + > account_multi_index_type; /** * @ingroup object_index */ - typedef generic_index account_index; + typedef generic_index account_index; }} diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index b1b170af..5f691b52 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -40,11 +40,15 @@ namespace graphene { namespace chain { struct genesis_state_type { struct allocation_target_type { - allocation_target_type(const string& name = string(), const address& addr = address(), share_type weight = share_type()) - : name(name), addr(addr), weight(weight){} + allocation_target_type(const string& name = string(), + const address& addr = address(), + share_type weight = share_type(), + bool is_lifetime_member = false) + : name(name), addr(addr), weight(weight),is_lifetime_member(is_lifetime_member){} string name; address addr; share_type weight; + bool is_lifetime_member; }; struct initial_witness_type { /// Must correspond to one of the allocation targets. diff --git a/libraries/db/object_database.cpp b/libraries/db/object_database.cpp index dc5cba58..1949a0c1 100644 --- a/libraries/db/object_database.cpp +++ b/libraries/db/object_database.cpp @@ -84,7 +84,7 @@ void object_database::wipe(const fc::path& data_dir) assert(!fc::exists(data_dir / "object_database")); } -void object_database::open( const fc::path& data_dir ) +void object_database::open(const fc::path& data_dir) { try { ilog("Open object_database in ${d}", ("d", data_dir)); _data_dir = data_dir; diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 71fcafa5..ff4cd1a9 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -35,7 +35,7 @@ void witness_plugin::plugin_set_program_options( ("witness-id,w", bpo::value>()->composing()->multitoken(), "ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)") ("private-key", bpo::value>()->composing()->multitoken()-> - DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("genesis"))))), + DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("null_key"))))), "Tuple of [key ID, private key] (may specify multiple times)") ; config_file_options.add(command_line_options); diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fc1f0a9f..2d339cd6 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -26,8 +26,8 @@ using namespace graphene::utilities; using namespace std; namespace fc{ -void to_variant(const account_object_multi_index_type& accts, variant& vo); -void from_variant(const variant &var, account_object_multi_index_type &vo); +void to_variant(const account_multi_index_type& accts, variant& vo); +void from_variant(const variant &var, account_multi_index_type &vo); } namespace graphene { namespace wallet { @@ -49,7 +49,7 @@ struct plain_keys struct wallet_data { - account_object_multi_index_type my_accounts; + account_multi_index_type my_accounts; /// @return IDs of all accounts in @ref my_accounts vector my_account_ids()const { diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 6dc9e67a..6c7108a8 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1748,13 +1748,13 @@ signed_transaction wallet_api::short_sell_asset(string seller_name, string amoun } } } -void fc::to_variant(const account_object_multi_index_type& accts, fc::variant& vo) +void fc::to_variant(const account_multi_index_type& accts, fc::variant& vo) { vo = vector(accts.begin(), accts.end()); } -void fc::from_variant(const fc::variant& var, account_object_multi_index_type& vo) +void fc::from_variant(const fc::variant& var, account_multi_index_type& vo) { const vector& v = var.as>(); - vo = account_object_multi_index_type(v.begin(), v.end()); + vo = account_multi_index_type(v.begin(), v.end()); } diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index e167bbb1..c3a89df7 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -103,7 +103,7 @@ int main( int argc, char** argv ) //fc::configure_logging( cfg ); - fc::ecc::private_key genesis_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); + fc::ecc::private_key genesis_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); idump( (key_to_wif( genesis_private_key ) ) ); diff --git a/tests/app/main.cpp b/tests/app/main.cpp index d7630550..da1bf2c3 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) ilog("Connected!"); fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); - fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); + fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); graphene::chain::signed_transaction trx; trx.set_expiration(now + fc::seconds(30)); std::shared_ptr db2 = app2.chain_database(); diff --git a/tests/benchmarks/genesis_allocation.cpp b/tests/benchmarks/genesis_allocation.cpp index a9d73f1f..92e64dd9 100644 --- a/tests/benchmarks/genesis_allocation.cpp +++ b/tests/benchmarks/genesis_allocation.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_INITIAL_SUPPLY / account_count); int blocks_out = 0; - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); auto aw = db.get_global_properties().active_witnesses; auto b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, delegate_priv_key, ~0 ); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index fcecaa43..d92d123a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -53,7 +53,18 @@ database_fixture::database_fixture() ahplugin->plugin_set_app( &app ); ahplugin->plugin_initialize( options ); - db.init_genesis(); + secret_hash_type::encoder enc; + fc::raw::pack(enc, delegate_priv_key); + fc::raw::pack(enc, secret_hash_type()); + 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)}); + } + genesis_state.initial_witnesses = vector(10, {"committee-account", + delegate_priv_key.get_public_key(), + secret_hash_type::hash(enc.result())}); + db.init_genesis(genesis_state); ahplugin->plugin_startup(); generate_block(); @@ -79,8 +90,8 @@ database_fixture::~database_fixture() fc::ecc::private_key database_fixture::generate_private_key(string seed) { - static const fc::ecc::private_key genesis = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); - if( seed == "genesis" ) + static const fc::ecc::private_key genesis = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + if( seed == "null_key" ) return genesis; return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); } @@ -250,7 +261,7 @@ void database_fixture::open_database() { if( !data_dir ) { data_dir = fc::temp_directory(); - db.open(data_dir->path()); + db.open(data_dir->path(), genesis_state); } } @@ -277,7 +288,7 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i generate_block(); auto slots_to_miss = db.get_slot_at_time(timestamp) - 1; if( slots_to_miss <= 0 ) return; - generate_block(~0, generate_private_key("genesis"), slots_to_miss); + generate_block(~0, delegate_priv_key, slots_to_miss); return; } while( db.head_block_time() < timestamp ) diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 649df558..92cf0b2e 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -88,12 +88,13 @@ struct database_fixture { // the reason we use an app is to exercise the indexes of built-in // plugins graphene::app::application app; + genesis_state_type genesis_state; chain::database &db; signed_transaction trx; key_id_type genesis_key; account_id_type genesis_account; fc::ecc::private_key private_key = fc::ecc::private_key::generate(); - fc::ecc::private_key delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + fc::ecc::private_key delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); fc::time_point_sec genesis_time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP ); fc::time_point_sec now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP ); const key_object* key1= nullptr; @@ -113,7 +114,7 @@ struct database_fixture { void verify_account_history_plugin_index( )const; void open_database(); signed_block generate_block(uint32_t skip = ~0, - const fc::ecc::private_key& key = generate_private_key("genesis"), + const fc::ecc::private_key& key = generate_private_key("null_key"), int miss_blocks = 0); /** @@ -189,10 +190,10 @@ struct database_fixture { const delegate_object& create_delegate( const account_object& owner ); const witness_object& create_witness(account_id_type owner, key_id_type signing_key = key_id_type(), - const fc::ecc::private_key& signing_private_key = generate_private_key("genesis")); + const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); const witness_object& create_witness(const account_object& owner, key_id_type signing_key = key_id_type(), - const fc::ecc::private_key& signing_private_key = generate_private_key("genesis")); + const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); const key_object& register_key( const public_key_type& key ); const key_object& register_address( const address& addr ); uint64_t fund( const account_object& account, const asset& amount = asset(500000) ); diff --git a/tests/intense/block_tests.cpp b/tests/intense/block_tests.cpp index 1a971b29..bcee36cd 100644 --- a/tests/intense/block_tests.cpp +++ b/tests/intense/block_tests.cpp @@ -49,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture ) ; // Sam is the creator of accounts - private_key_type genesis_key = generate_private_key("genesis"); + private_key_type genesis_key = delegate_priv_key; private_key_type sam_key = generate_private_key("sam"); // diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index 7c3c4697..4f6f98c6 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( transfer_benchmark ) { fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); const key_object& key = register_key(nathan_key.get_public_key()); - const auto& genesis = account_id_type()(db); //get_account( "genesis" ); + const auto& genesis = account_id_type()(db); auto start = fc::time_point::now(); for( uint32_t i = 0; i < 1000*1000; ++i ) { diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index 4ce9740d..18ffa16c 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE( recursive_accounts ) trx.operations.push_back(op); sign(trx, key2.id,parent2_key); sign(trx, grandparent_key_obj.id,grandparent_key); - sign(trx, key_id_type(), generate_private_key("genesis")); + sign(trx, key_id_type(), delegate_priv_key); //Fails due to recursion depth. BOOST_CHECK_THROW(db.push_transaction(trx, database::skip_transaction_dupe_check), fc::exception); sign(trx, child_key_obj.id, child_key); @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE( proposed_single_account ) try { INVOKE(any_two_of_three); - fc::ecc::private_key genesis_key = generate_private_key("genesis"); + fc::ecc::private_key genesis_key = delegate_priv_key; fc::ecc::private_key nathan_key1 = fc::ecc::private_key::regenerate(fc::digest("key1")); 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")); @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE( proposed_single_account ) BOOST_AUTO_TEST_CASE( genesis_authority ) { try { fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); - fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); + fc::ecc::private_key genesis_key = delegate_priv_key; const auto& nathan_key_obj = register_key(nathan_key.get_public_key()); key_id_type nathan_key_id = nathan_key_obj.get_id(); const account_object nathan = create_account("nathan", nathan_key_obj.id); @@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE( genesis_authority ) BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture ) { try { generate_block(); - fc::ecc::private_key genesis_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); + fc::ecc::private_key genesis_key = delegate_priv_key; fc::ecc::private_key delegate_key = fc::ecc::private_key::generate(); auto delegate_key_object = register_key(delegate_key.get_public_key()); @@ -812,7 +812,7 @@ BOOST_FIXTURE_TEST_CASE( max_authority_membership, database_fixture ) transaction tx; processed_transaction ptx; - private_key_type genesis_key = generate_private_key("genesis"); + private_key_type genesis_key = delegate_priv_key; // Sam is the creator of accounts private_key_type sam_key = generate_private_key("sam"); @@ -903,7 +903,7 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) { try { - private_key_type genesis_key = generate_private_key("genesis"); + private_key_type genesis_key = delegate_priv_key; // Sam is the creator of accounts private_key_type alice_key = generate_private_key("alice"); private_key_type bob_key = generate_private_key("bob"); @@ -987,8 +987,10 @@ BOOST_FIXTURE_TEST_CASE( voting_account, database_fixture ) delegate_id_type nathan_delegate = create_delegate(nathan_id(db)).id; delegate_id_type vikram_delegate = create_delegate(vikram_id(db)).id; + wdump((db.get_balance(account_id_type(), asset_id_type()))); generate_block(); + wdump((db.get_balance(account_id_type(), asset_id_type()))); transfer(account_id_type(), nathan_id, asset(1000000)); transfer(account_id_type(), vikram_id, asset(100)); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 0fed7963..08557fb6 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -35,6 +35,23 @@ using namespace graphene::chain; +genesis_state_type make_genesis() { + genesis_state_type genesis_state; + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + secret_hash_type::encoder enc; + fc::raw::pack(enc, delegate_priv_key); + fc::raw::pack(enc, secret_hash_type()); + 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)}); + } + genesis_state.initial_witnesses = vector(10, {"committee-account", + delegate_priv_key.get_public_key(), + secret_hash_type::hash(enc.result())}); + return genesis_state; +} + BOOST_AUTO_TEST_SUITE(block_tests) BOOST_AUTO_TEST_CASE( block_database_test ) @@ -113,10 +130,10 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) now += GRAPHENE_DEFAULT_BLOCK_INTERVAL; // TODO: Don't generate this here - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); { database db; - db.open(data_dir.path(), genesis_state_type() ); + db.open(data_dir.path(), make_genesis() ); b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key ); for( uint32_t i = 1; i < 200; ++i ) @@ -161,10 +178,10 @@ BOOST_AUTO_TEST_CASE( undo_block ) fc::temp_directory data_dir; { database db; - db.open(data_dir.path(), genesis_state_type() ); + db.open(data_dir.path(), make_genesis() ); fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); for( uint32_t i = 0; i < 5; ++i ) { now += db.block_interval(); @@ -204,11 +221,11 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); database db1; - db1.open(data_dir1.path(), genesis_state_type()); + db1.open(data_dir1.path(), make_genesis()); database db2; - db2.open(data_dir2.path(), genesis_state_type()); + db2.open(data_dir2.path(), make_genesis()); - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); for( uint32_t i = 0; i < 10; ++i ) { now += db1.block_interval(); @@ -269,9 +286,9 @@ BOOST_AUTO_TEST_CASE( undo_pending ) fc::temp_directory data_dir; { database db; - db.open(data_dir.path()); + db.open(data_dir.path(), make_genesis()); - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + 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); { @@ -328,11 +345,11 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) dir2; database db1, db2; - db1.open(dir1.path()); - db2.open(dir2.path()); + db1.open(dir1.path(), make_genesis()); + db2.open(dir2.path(), make_genesis()); fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type); signed_transaction trx; @@ -386,12 +403,12 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) dir2; database db1, db2; - db1.open(dir1.path()); - db2.open(dir2.path()); + db1.open(dir1.path(), make_genesis()); + db2.open(dir2.path(), make_genesis()); auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check; - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type); signed_transaction trx; @@ -434,16 +451,16 @@ BOOST_AUTO_TEST_CASE( tapos ) dir2; database db1, db2; - db1.open(dir1.path()); - db2.open(dir2.path()); + db1.open(dir1.path(), make_genesis()); + db2.open(dir2.path(), make_genesis()); const account_object& init1 = *db1.get_index_type().indices().get().find("init1"); - auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")) ); + auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type); 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); signed_transaction trx; //This transaction must be in the next block after its reference, or it is invalid. @@ -455,24 +472,19 @@ BOOST_AUTO_TEST_CASE( tapos ) cop.name = "nathan"; cop.owner = authority(1, key_id_type(), 1); trx.operations.push_back(cop); - trx.sign( key_id_type(), delegate_priv_key ); - - trx.signatures.clear(); - trx.sign( key_id_type(), delegate_priv_key ); + trx.sign(key_id_type(2), delegate_priv_key); db1.push_transaction(trx); - now += db1.block_interval(); - b = db1.generate_block( now, db1.get_scheduled_witness( 1 ).first, delegate_priv_key ); + b = db1.generate_block(now, db1.get_scheduled_witness(1).first, delegate_priv_key); + trx.clear(); - trx.operations.clear(); - trx.signatures.clear(); trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan_id, asset(50)})); - trx.sign( key_id_type(), delegate_priv_key ); + trx.sign(key_id_type(2), delegate_priv_key); //relative_expiration is 1, but ref block is 2 blocks old, so this should fail. BOOST_REQUIRE_THROW(db1.push_transaction(trx, database::skip_transaction_signatures | database::skip_authority_check), fc::exception); trx.set_expiration(db1.head_block_id(), 2); trx.signatures.clear(); - trx.sign( key_id_type(), delegate_priv_key ); + trx.sign(key_id_type(2), delegate_priv_key); db1.push_transaction(trx, database::skip_transaction_signatures | database::skip_authority_check); } catch (fc::exception& e) { edump((e.to_detail_string())); @@ -637,7 +649,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) uop.new_parameters.block_interval = 1; cop.proposed_ops.emplace_back(uop); trx.operations.push_back(cop); - trx.sign(key_id_type(),generate_private_key("genesis")); + trx.sign(key_id_type(),delegate_priv_key); db.push_transaction(trx); } { @@ -646,7 +658,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) 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)}; trx.operations.push_back(uop); - trx.sign(key_id_type(),generate_private_key("genesis")); + trx.sign(key_id_type(),delegate_priv_key); db.push_transaction(trx); BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(&db)); } @@ -672,7 +684,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) BOOST_FIXTURE_TEST_CASE( force_settlement, database_fixture ) { try { - auto private_key = generate_private_key("genesis"); + auto private_key = delegate_priv_key; account_id_type nathan_id = create_account("nathan").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id(); account_id_type shorter2_id = create_account("shorter2").get_id(); @@ -818,7 +830,7 @@ BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) const asset_object& core = asset_id_type()(db); // Sam is the creator of accounts - private_key_type genesis_key = generate_private_key("genesis"); + private_key_type genesis_key = delegate_priv_key; private_key_type sam_key = generate_private_key("sam"); account_object sam_account_object = create_account( "sam", sam_key ); @@ -866,7 +878,7 @@ BOOST_FIXTURE_TEST_CASE( witness_scheduler_missed_blocks, database_fixture ) near_schedule = db.get_near_witness_schedule(); idump((db.head_block_time())); - generate_block(0, generate_private_key("genesis"), 2); + generate_block(0, delegate_priv_key, 2); idump((db.head_block_time())); BOOST_CHECK(db.get_dynamic_global_properties().current_witness == near_schedule[2]); diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index f2c503be..11f5a955 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( create_account_test ) op.owner = auth_bak; trx.operations.back() = op; - trx.sign( key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))) ); + trx.sign(key_id_type(), delegate_priv_key); trx.validate(); db.push_transaction(trx, ~0); @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE( child_account ) op.owner = authority(1, child_key.get_id(), 1); op.active = authority(1, child_key.get_id(), 1); trx.operations.emplace_back(op); - sign(trx, key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")))); + trx.sign({}, delegate_priv_key); BOOST_REQUIRE_THROW(db.push_transaction(trx), fc::exception); sign(trx, nathan_key.id,nathan_private_key); @@ -130,8 +130,8 @@ BOOST_AUTO_TEST_CASE( child_account ) trx.signatures.clear(); op.owner = authority(1, account_id_type(nathan.id), 1); trx.operations = {op}; - sign(trx, key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")))); - sign(trx, nathan_key.id, nathan_private_key); + trx.sign({}, delegate_priv_key); + trx.sign(nathan_key.id, nathan_private_key); db.push_transaction(trx); BOOST_CHECK( get_account("nathan/child").active.auths == op.active.auths ); @@ -1881,7 +1881,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test ) trx.operations.push_back(uop); trx.visit(operation_set_fee(db.current_fee_schedule())); trx.validate(); - trx.sign(key_id_type(),generate_private_key("genesis")); + trx.sign(key_id_type(),delegate_priv_key); db.push_transaction(trx); trx.clear(); BOOST_CHECK_EQUAL(get_balance(*nathan, *core), 8950000000); @@ -1960,7 +1960,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(),generate_private_key("genesis")); + trx.sign(key_id_type(),delegate_priv_key); db.push_transaction(trx); trx.clear(); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index aaebbdc1..1ff69a82 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -685,7 +685,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test ) BOOST_AUTO_TEST_CASE( force_settlement_unavailable ) { try { - auto private_key = generate_private_key("genesis"); + auto private_key = delegate_priv_key; account_id_type nathan_id = create_account("nathan").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id(); account_id_type shorter2_id = create_account("shorter2").get_id(); From d47c2ee2a28cf4dd815bcbdf517be70f7ab7294a Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 18 Jun 2015 15:02:42 -0400 Subject: [PATCH 2/3] Progress #52: The tests pass again. --- libraries/chain/db_init.cpp | 43 ++++++++++++--- .../chain/include/graphene/chain/config.hpp | 4 +- .../chain/transaction_evaluation_state.cpp | 4 +- tests/common/database_fixture.cpp | 16 +++--- tests/tests/authority_tests.cpp | 47 ++++++++++++----- tests/tests/block_tests.cpp | 52 +++++++++++-------- tests/tests/operation_tests.cpp | 7 +-- tests/tests/operation_tests2.cpp | 9 ++-- 8 files changed, 121 insertions(+), 61 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index e65cdf94..35d655fd 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -152,16 +152,47 @@ void database::init_genesis(const genesis_state_type& genesis_state) n.active = n.owner; n.statistics = create( [&](account_statistics_object& b){}).id; }); - create([this](account_object& a) { - a.name = "null-account"; + FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT); + FC_ASSERT(create([this](account_object& a) { + a.name = "witness-account"; a.statistics = create([](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([this](account_object& a) { + a.name = "relaxed-committee-account"; + a.statistics = create([](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([this](account_object& a) { + a.name = "null-account"; + a.statistics = create([](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([this](account_object& a) { + a.name = "temp-account"; + a.statistics = create([](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 = diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 066a18e6..4d1d3613 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -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)) ///@} diff --git a/libraries/chain/transaction_evaluation_state.cpp b/libraries/chain/transaction_evaluation_state.cpp index e1271384..5228c471 100644 --- a/libraries/chain/transaction_evaluation_state.cpp +++ b/libraries/chain/transaction_evaluation_state.cpp @@ -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 ); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index d92d123a..2d18c480 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -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(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 pin = - app.get_plugin( "account_history" ); + app.get_plugin("account_history"); if( pin->tracked_accounts().size() == 0 ) { vector< pair< account_id_type, address > > tuples_from_db; diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index 18ffa16c..08dd05c7 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -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(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)); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 08557fb6..91732cdb 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -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; diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 11f5a955..f7afb78c 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -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*/); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 1ff69a82..1181e204 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -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; From 8bcd1f3bf5b511d82e0453b6e8c3944ddd7519e1 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 18 Jun 2015 15:05:06 -0400 Subject: [PATCH 3/3] Resolve #52: I think it's real this time. --- libraries/chain/db_init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 35d655fd..0ee121f0 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -220,6 +220,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) // Create global properties create([&](global_property_object& p) { p.chain_id = fc::digest(genesis_state); + p.parameters = genesis_state.initial_parameters; }); create( [&](dynamic_global_property_object& p) { p.time = fc::time_point_sec(GRAPHENE_GENESIS_TIMESTAMP);