diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 7f4d3b90..9c57fd85 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -129,112 +129,86 @@ 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(); + struct auth_inhibitor { + auth_inhibitor(database& db) : db(db), old_flags(db.node_properties().skip_flags) + { db.node_properties().skip_flags |= skip_authority_check; } + ~auth_inhibitor() + { db.node_properties().skip_flags = old_flags; } + private: + database& db; + uint32_t old_flags; + } inhibitor(*this); + + transaction_evaluation_state genesis_eval_state(this); + + // 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; - }); - - 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) { - }); - - 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 ); + n.statistics = create( [&](account_statistics_object& b){}).id; }); + 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.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 = 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 +216,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 +227,72 @@ 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); + p.parameters = genesis_state.initial_parameters; + }); + 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 +300,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/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/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index b149b324..45910090 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -41,11 +41,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/chain/transaction_evaluation_state.cpp b/libraries/chain/transaction_evaluation_state.cpp index 35d3973f..7a4d4e8f 100644 --- a/libraries/chain/transaction_evaluation_state.cpp +++ b/libraries/chain/transaction_evaluation_state.cpp @@ -27,7 +27,8 @@ namespace graphene { namespace chain { { if( (!_is_proposed_trx) && (_db->get_node_properties().skip_flags & database::skip_authority_check) ) return true; - if( approved_by.find(make_pair(account.id, auth_class)) != approved_by.end() ) + if( 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/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 d0ae52f9..13ac821e 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -36,7 +36,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 a3d0a8c3..93480b06 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 997be4a4..cefeb01f 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -50,10 +50,21 @@ 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); - db.init_genesis(); + 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 ) + { + 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}); + } + db.init_genesis(genesis_state); ahplugin->plugin_startup(); generate_block(); @@ -81,8 +92,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)); } @@ -168,7 +179,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; @@ -247,7 +258,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); } } @@ -274,7 +285,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 8ca1e1b6..da154360 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -91,12 +91,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; @@ -115,7 +116,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); /** @@ -191,10 +192,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 2df5550f..f5ce2ff1 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(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception); sign(trx, child_key_obj.id, child_key); @@ -269,19 +269,20 @@ 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")); + 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); @@ -338,7 +339,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); @@ -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); - PUSH_TX( db, trx ); + 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(PUSH_TX( db, trx ), fc::exception); @@ -415,7 +425,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()); @@ -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); PUSH_TX( db, trx ); BOOST_CHECK(prop.is_authorized_to_execute(&db)); @@ -817,7 +838,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"); @@ -908,7 +929,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"); @@ -992,8 +1013,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 4a395a34..bd1d0b5b 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -35,10 +35,27 @@ 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 ) -{ +{ try { fc::temp_directory data_dir; @@ -53,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 ); @@ -79,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() ); @@ -113,11 +130,11 @@ 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() ); - b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key, database::skip_nothing ); + db.open(data_dir.path(), make_genesis() ); + b = db.generate_block(now, db.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); 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); { @@ -281,14 +298,14 @@ BOOST_AUTO_TEST_CASE( undo_pending ) PUSH_TX( db, 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); @@ -296,20 +313,18 @@ BOOST_AUTO_TEST_CASE( undo_pending ) PUSH_TX( db, trx ); now += db.block_interval(); - auto b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key, database::skip_nothing ); + auto b = db.generate_block(now, db.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); 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 ); - PUSH_TX( db, 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 ); - PUSH_TX( db, trx ); + db.push_transaction(trx, ~0); BOOST_CHECK(db.get_balance(nathan_id, asset_id_type()).amount == 10000); db.clear_pending(); @@ -328,18 +343,18 @@ 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; 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); @@ -348,18 +363,18 @@ 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, database::skip_nothing ); + auto b = db1.generate_block(now, db1.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); 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, database::skip_nothing ); - PUSH_BLOCK( db1, b ); + b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); + 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, database::skip_nothing ); - PUSH_BLOCK( db1, b ); + b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); + db1.push_block(b); BOOST_CHECK_THROW(nathan_id(db1), fc::exception); @@ -367,8 +382,8 @@ 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, database::skip_nothing ); - PUSH_BLOCK( db1, b ); + b = db2.generate_block(now, db2.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); + db1.push_block(b); BOOST_CHECK(nathan_id(db1).name == "nathan"); BOOST_CHECK(nathan_id(db2).name == "nathan"); @@ -386,12 +401,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,12 +449,12 @@ 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(); @@ -455,25 +470,20 @@ 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 ); - PUSH_TX( db1, trx ); - + 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, database::skip_nothing ); + b = db1.generate_block(now, db1.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing); + 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(PUSH_TX( db1, 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 ); - PUSH_TX( db1, trx, database::skip_transaction_signatures | database::skip_authority_check ); + 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())); throw; @@ -631,23 +641,31 @@ 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(),generate_private_key("genesis")); - PUSH_TX( db, trx ); + 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(),generate_private_key("genesis")); - PUSH_TX( db, trx ); + 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)); } @@ -672,7 +690,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(); @@ -681,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; @@ -818,7 +836,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 +884,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 71f34b2b..945d19f5 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(); PUSH_TX( db, 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(PUSH_TX( db, trx ), fc::exception); sign(trx, nathan_key.id,nathan_private_key); @@ -130,9 +130,9 @@ 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); - PUSH_TX( db, trx ); + 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 ); } catch (fc::exception& e) { @@ -308,10 +308,11 @@ BOOST_AUTO_TEST_CASE( update_mia ) trx.operations.back() = op; PUSH_TX( db, 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; @@ -1881,8 +1882,8 @@ 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")); - PUSH_TX( db, trx ); + trx.sign(key_id_type(),delegate_priv_key); + db.push_transaction(trx); trx.clear(); BOOST_CHECK_EQUAL(get_balance(*nathan, *core), 8950000000); @@ -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(),generate_private_key("genesis")); - PUSH_TX( db, 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 1dd13d6c..b2ce73d2 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 ) @@ -685,7 +684,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(); @@ -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;