Issue #52: working my way out of the rabbit hole

Evils abound. And tests still fail.
This commit is contained in:
Nathan Hourt 2015-06-18 09:19:14 -04:00
parent 34388fabee
commit 9291250214
20 changed files with 230 additions and 216 deletions

View file

@ -129,112 +129,45 @@ void database::initialize_indexes()
void database::init_genesis(const genesis_state_type& genesis_state) void database::init_genesis(const genesis_state_type& genesis_state)
{ try { { 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"))); _undo_db.disable();
const key_object& genesis_key = transaction_evaluation_state genesis_eval_state(this, true);
create<key_object>( [&genesis_private_key](key_object& k) {
k.key_data = public_key_type(genesis_private_key.get_public_key()); // Create initial accounts
}); fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
const account_statistics_object& genesis_statistics = create<key_object>( [&null_private_key](key_object& k) {
create<account_statistics_object>( [&](account_statistics_object& b){ k.key_data = public_key_type(null_private_key.get_public_key());
}); });
create<account_balance_object>( [](account_balance_object& b) { create<account_balance_object>( [](account_balance_object& b) {
b.balance = GRAPHENE_INITIAL_SUPPLY; b.balance = GRAPHENE_INITIAL_SUPPLY;
}); });
const account_object& genesis_account = const account_object& committee_account =
create<account_object>( [&](account_object& n) { create<account_object>( [&](account_object& n) {
n.membership_expiration_date = time_point_sec::maximum(); n.membership_expiration_date = time_point_sec::maximum();
n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; 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.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
n.name = "genesis"; n.name = "committee-account";
n.owner.add_authority(genesis_key.get_id(), 1);
n.owner.weight_threshold = 1;
n.active = n.owner; n.active = n.owner;
n.options.memo_key = genesis_key.id; n.statistics = create<account_statistics_object>( [&](account_statistics_object& b){}).id;
n.statistics = genesis_statistics.id;
}); });
create<account_object>([this](account_object& a) {
vector<delegate_id_type> init_delegates; a.name = "null-account";
vector<witness_id_type> init_witnesses; a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
flat_set<witness_id_type> init_witness_set; a.owner = authority(1, key_id_type(), 1);
a.active = a.owner;
auto delegates_and_witnesses = std::max(GRAPHENE_MIN_WITNESS_COUNT, GRAPHENE_MIN_DELEGATE_COUNT); a.registrar = a.lifetime_referrer = a.referrer = account_id_type(1);
for( int i = 0; i < delegates_and_witnesses; ++i ) a.membership_expiration_date = time_point_sec::maximum();
{ a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
const account_statistics_object& stats_obj = a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
create<account_statistics_object>( [&](account_statistics_object&){
});
const account_object& delegate_account =
create<account_object>( [&](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>( [&](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>( [&](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>( [&](block_summary_object& p) {
}); });
const witness_schedule_object& wso = // Create core asset
create<witness_schedule_object>( [&]( 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<init_witnesses.size(); i++ )
_wso.scheduler.produce_schedule( rng );
_wso.last_scheduling_block = 0;
} ) ;
assert( wso.id == witness_schedule_id_type() );
const global_property_object& properties =
create<global_property_object>( [&](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>( [&](dynamic_global_property_object& p) {
p.time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
});
const asset_dynamic_data_object& dyn_asset = const asset_dynamic_data_object& dyn_asset =
create<asset_dynamic_data_object>( [&]( asset_dynamic_data_object& a ) { create<asset_dynamic_data_object>( [&]( asset_dynamic_data_object& a ) {
a.current_supply = GRAPHENE_INITIAL_SUPPLY; a.current_supply = GRAPHENE_INITIAL_SUPPLY;
}); });
const asset_object& core_asset = const asset_object& core_asset =
create<asset_object>( [&]( asset_object& a ) { create<asset_object>( [&]( asset_object& a ) {
a.symbol = GRAPHENE_SYMBOL; 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.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS;
a.options.flags = 0; a.options.flags = 0;
a.options.issuer_permissions = 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.amount = 1;
a.options.core_exchange_rate.base.asset_id = 0; a.options.core_exchange_rate.base.asset_id = 0;
a.options.core_exchange_rate.quote.amount = 1; 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) ); assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) );
(void)core_asset; (void)core_asset;
// Create global properties
create<global_property_object>([&](global_property_object& p) {
p.chain_id = fc::digest(genesis_state);
});
create<dynamic_global_property_object>( [&](dynamic_global_property_object& p) {
p.time = fc::time_point_sec(GRAPHENE_GENESIS_TIMESTAMP);
});
create<block_summary_object>([&](block_summary_object& p) {
});
// Create user accounts, apply initial stake allocation
if( !genesis_state.allocation_targets.empty() ) if( !genesis_state.allocation_targets.empty() )
{ {
share_type total_allocation = 0; share_type total_allocation = 0;
for( const auto& handout : genesis_state.allocation_targets ) for( const auto& handout : genesis_state.allocation_targets )
total_allocation += handout.weight; total_allocation += handout.weight;
auto mangle_to_name = [](const fc::static_variant<public_key_type, address>& key) {
string addr = string(key.which() == std::decay<decltype(key)>::type::tag<address>::value? key.get<address>()
: key.get<public_key_type>());
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(); fc::time_point start_time = fc::time_point::now();
for( const auto& handout : genesis_state.allocation_targets ) for( const auto& handout : genesis_state.allocation_targets )
{ {
asset amount(handout.weight); 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; key_id_type key_id = apply_operation(genesis_eval_state, key_create_operation({asset(), committee_account.id, handout.addr})).get<object_id_type>();
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);
account_create_operation cop; account_create_operation cop;
cop.name = handout.name; cop.name = handout.name;
cop.registrar = account_id_type(1); cop.registrar = account_id_type(1);
cop.active = account_authority; cop.active = authority(1, key_id, 1);
cop.owner = account_authority; cop.owner = cop.active;
cop.options.memo_key = key_id; cop.options.memo_key = key_id;
trx.operations.push_back(cop); account_id_type account_id(apply_operation(genesis_eval_state, cop).get<object_id_type>());
trx.validate();
auto ptrx = apply_transaction(trx, ~0); if( handout.is_lifetime_member )
trx = signed_transaction(); {
account_id_type account_id(ptrx.operation_results.back().get<object_id_type>()); account_upgrade_operation op;
trx.operations.emplace_back(transfer_operation({ asset(), op.account_to_upgrade = account_id;
genesis_account.id, op.upgrade_to_lifetime_member = true;
account_id, apply_operation(genesis_eval_state, op);
amount, }
memo_data()//vector<char>()
})); if( amount.amount > 0 )
trx.validate(); {
apply_transaction(trx, ~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( total_allocation != 0 )
if( leftovers.amount > 0 )
{ {
modify(*get_index_type<account_balance_index>().indices().get<by_balance>().find(boost::make_tuple(account_id_type(), asset_id_type())), asset leftovers = get_balance(account_id_type(), asset_id_type());
[](account_balance_object& b) { if( leftovers.amount > 0 )
b.adjust_balance(-b.get_balance()); {
}); modify(*get_index_type<account_balance_index>().indices().get<by_balance>().find(boost::make_tuple(account_id_type(), asset_id_type())),
modify(core_asset.dynamic_asset_data_id(*this), [&leftovers](asset_dynamic_data_object& d) { [](account_balance_object& b) {
d.accumulated_fees += leftovers.amount; 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; 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)); ("n", genesis_state.allocation_targets.size())("t", duration.count() / 1000));
} }
flat_set<delegate_id_type> init_delegates;
flat_set<witness_id_type> init_witnesses;
const auto& accounts_by_name = get_index_type<account_index>().indices().get<by_name>();
// 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<key_object>([&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<object_id_type>();
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<object_id_type>();
init_delegates.emplace(id);
});
// Set initial witnesses and committee as active
modify(get_global_properties(), [&](global_property_object& p) {
p.active_delegates = vector<delegate_id_type>(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>([&](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<init_witnesses.size(); i++ )
_wso.scheduler.produce_schedule(rng);
_wso.last_scheduling_block = 0;
}) ;
assert( wso.id == witness_schedule_id_type() );
_undo_db.enable(); _undo_db.enable();
} FC_LOG_AND_RETHROW() } } FC_LOG_AND_RETHROW() }

View file

@ -169,7 +169,7 @@ void database::update_active_delegates()
modify( get_global_properties(), [&]( global_property_object& gp ) { modify( get_global_properties(), [&]( global_property_object& gp ) {
gp.active_delegates.clear(); gp.active_delegates.clear();
std::transform(delegates.begin(), delegates.end(), std::transform(delegates.begin(), delegates.end(),
std::back_inserter(gp.active_delegates), std::inserter(gp.active_delegates, gp.active_delegates.begin()),
[](const delegate_object& d) { return d.id; }); [](const delegate_object& d) { return d.id; });
}); });
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }

View file

@ -36,9 +36,9 @@ database::~database(){
void database::open( const fc::path& data_dir, const genesis_state_type& initial_allocation ) void database::open( const fc::path& data_dir, const genesis_state_type& initial_allocation )
{ try { { try {
ilog("Open database in ${d}", ("d", data_dir)); ilog("Open database in ${d}", ("d", data_dir));
object_database::open( data_dir ); object_database::open(data_dir);
_block_id_to_block.open( data_dir / "database" / "block_num_to_block" ); _block_id_to_block.open(data_dir / "database" / "block_num_to_block");
if( !find(global_property_id_type()) ) if( !find(global_property_id_type()) )
{ {

View file

@ -292,12 +292,12 @@ class database;
hashed_unique< tag<by_id>, member< object, object_id_type, &object::id > >, hashed_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_non_unique< tag<by_name>, member<account_object, string, &account_object::name> > ordered_non_unique< tag<by_name>, member<account_object, string, &account_object::name> >
> >
> account_object_multi_index_type; > account_multi_index_type;
/** /**
* @ingroup object_index * @ingroup object_index
*/ */
typedef generic_index<account_object, account_object_multi_index_type> account_index; typedef generic_index<account_object, account_multi_index_type> account_index;
}} }}

View file

@ -40,11 +40,15 @@ namespace graphene { namespace chain {
struct genesis_state_type { struct genesis_state_type {
struct allocation_target_type { struct allocation_target_type {
allocation_target_type(const string& name = string(), const address& addr = address(), share_type weight = share_type()) allocation_target_type(const string& name = string(),
: name(name), addr(addr), weight(weight){} 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; string name;
address addr; address addr;
share_type weight; share_type weight;
bool is_lifetime_member;
}; };
struct initial_witness_type { struct initial_witness_type {
/// Must correspond to one of the allocation targets. /// Must correspond to one of the allocation targets.

View file

@ -84,7 +84,7 @@ void object_database::wipe(const fc::path& data_dir)
assert(!fc::exists(data_dir / "object_database")); 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 { { try {
ilog("Open object_database in ${d}", ("d", data_dir)); ilog("Open object_database in ${d}", ("d", data_dir));
_data_dir = data_dir; _data_dir = data_dir;

View file

@ -35,7 +35,7 @@ void witness_plugin::plugin_set_program_options(
("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(), ("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(),
"ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)") "ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)")
("private-key", bpo::value<vector<string>>()->composing()->multitoken()-> ("private-key", bpo::value<vector<string>>()->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)") "Tuple of [key ID, private key] (may specify multiple times)")
; ;
config_file_options.add(command_line_options); config_file_options.add(command_line_options);

View file

@ -26,8 +26,8 @@ using namespace graphene::utilities;
using namespace std; using namespace std;
namespace fc{ namespace fc{
void to_variant(const account_object_multi_index_type& accts, variant& vo); void to_variant(const account_multi_index_type& accts, variant& vo);
void from_variant(const variant &var, account_object_multi_index_type &vo); void from_variant(const variant &var, account_multi_index_type &vo);
} }
namespace graphene { namespace wallet { namespace graphene { namespace wallet {
@ -49,7 +49,7 @@ struct plain_keys
struct wallet_data 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 /// @return IDs of all accounts in @ref my_accounts
vector<object_id_type> my_account_ids()const vector<object_id_type> my_account_ids()const
{ {

View file

@ -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<account_object>(accts.begin(), accts.end()); vo = vector<account_object>(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<account_object>& v = var.as<vector<account_object>>(); const vector<account_object>& v = var.as<vector<account_object>>();
vo = account_object_multi_index_type(v.begin(), v.end()); vo = account_multi_index_type(v.begin(), v.end());
} }

View file

@ -103,7 +103,7 @@ int main( int argc, char** argv )
//fc::configure_logging( cfg ); //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 ) ) ); idump( (key_to_wif( genesis_private_key ) ) );

View file

@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE( two_node_network )
ilog("Connected!"); ilog("Connected!");
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); 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; graphene::chain::signed_transaction trx;
trx.set_expiration(now + fc::seconds(30)); trx.set_expiration(now + fc::seconds(30));
std::shared_ptr<chain::database> db2 = app2.chain_database(); std::shared_ptr<chain::database> db2 = app2.chain_database();

View file

@ -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); BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_INITIAL_SUPPLY / account_count);
int blocks_out = 0; 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 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 ); auto b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, delegate_priv_key, ~0 );

View file

@ -53,7 +53,18 @@ database_fixture::database_fixture()
ahplugin->plugin_set_app( &app ); ahplugin->plugin_set_app( &app );
ahplugin->plugin_initialize( options ); 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<genesis_state_type::initial_witness_type>(10, {"committee-account",
delegate_priv_key.get_public_key(),
secret_hash_type::hash(enc.result())});
db.init_genesis(genesis_state);
ahplugin->plugin_startup(); ahplugin->plugin_startup();
generate_block(); generate_block();
@ -79,8 +90,8 @@ database_fixture::~database_fixture()
fc::ecc::private_key database_fixture::generate_private_key(string seed) 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"))); static const fc::ecc::private_key genesis = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
if( seed == "genesis" ) if( seed == "null_key" )
return genesis; return genesis;
return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); return fc::ecc::private_key::regenerate(fc::sha256::hash(seed));
} }
@ -250,7 +261,7 @@ void database_fixture::open_database()
{ {
if( !data_dir ) { if( !data_dir ) {
data_dir = fc::temp_directory(); 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(); generate_block();
auto slots_to_miss = db.get_slot_at_time(timestamp) - 1; auto slots_to_miss = db.get_slot_at_time(timestamp) - 1;
if( slots_to_miss <= 0 ) return; 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; return;
} }
while( db.head_block_time() < timestamp ) while( db.head_block_time() < timestamp )

View file

@ -88,12 +88,13 @@ struct database_fixture {
// the reason we use an app is to exercise the indexes of built-in // the reason we use an app is to exercise the indexes of built-in
// plugins // plugins
graphene::app::application app; graphene::app::application app;
genesis_state_type genesis_state;
chain::database &db; chain::database &db;
signed_transaction trx; signed_transaction trx;
key_id_type genesis_key; key_id_type genesis_key;
account_id_type genesis_account; account_id_type genesis_account;
fc::ecc::private_key private_key = fc::ecc::private_key::generate(); 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 genesis_time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
fc::time_point_sec now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP ); fc::time_point_sec now = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP );
const key_object* key1= nullptr; const key_object* key1= nullptr;
@ -113,7 +114,7 @@ struct database_fixture {
void verify_account_history_plugin_index( )const; void verify_account_history_plugin_index( )const;
void open_database(); void open_database();
signed_block generate_block(uint32_t skip = ~0, 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); int miss_blocks = 0);
/** /**
@ -189,10 +190,10 @@ struct database_fixture {
const delegate_object& create_delegate( const account_object& owner ); const delegate_object& create_delegate( const account_object& owner );
const witness_object& create_witness(account_id_type owner, const witness_object& create_witness(account_id_type owner,
key_id_type signing_key = key_id_type(), 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, const witness_object& create_witness(const account_object& owner,
key_id_type signing_key = key_id_type(), 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_key( const public_key_type& key );
const key_object& register_address( const address& addr ); const key_object& register_address( const address& addr );
uint64_t fund( const account_object& account, const asset& amount = asset(500000) ); uint64_t fund( const account_object& account, const asset& amount = asset(500000) );

View file

@ -49,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture )
; ;
// Sam is the creator of accounts // 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"); private_key_type sam_key = generate_private_key("sam");
// //

View file

@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( transfer_benchmark )
{ {
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); fc::ecc::private_key nathan_key = fc::ecc::private_key::generate();
const key_object& key = register_key(nathan_key.get_public_key()); 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(); auto start = fc::time_point::now();
for( uint32_t i = 0; i < 1000*1000; ++i ) for( uint32_t i = 0; i < 1000*1000; ++i )
{ {

View file

@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
trx.operations.push_back(op); trx.operations.push_back(op);
sign(trx, key2.id,parent2_key); sign(trx, key2.id,parent2_key);
sign(trx, grandparent_key_obj.id,grandparent_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. //Fails due to recursion depth.
BOOST_CHECK_THROW(db.push_transaction(trx, database::skip_transaction_dupe_check), fc::exception); BOOST_CHECK_THROW(db.push_transaction(trx, database::skip_transaction_dupe_check), fc::exception);
sign(trx, child_key_obj.id, child_key); sign(trx, child_key_obj.id, child_key);
@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
try { try {
INVOKE(any_two_of_three); 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_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_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3")); 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 ) BOOST_AUTO_TEST_CASE( genesis_authority )
{ try { { try {
fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); 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()); const auto& nathan_key_obj = register_key(nathan_key.get_public_key());
key_id_type nathan_key_id = nathan_key_obj.get_id(); key_id_type nathan_key_id = nathan_key_obj.get_id();
const account_object nathan = create_account("nathan", nathan_key_obj.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 ) BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
{ try { { try {
generate_block(); 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(); fc::ecc::private_key delegate_key = fc::ecc::private_key::generate();
auto delegate_key_object = register_key(delegate_key.get_public_key()); 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; transaction tx;
processed_transaction ptx; 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 // Sam is the creator of accounts
private_key_type sam_key = generate_private_key("sam"); private_key_type sam_key = generate_private_key("sam");
@ -903,7 +903,7 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture )
{ {
try try
{ {
private_key_type genesis_key = generate_private_key("genesis"); private_key_type genesis_key = delegate_priv_key;
// Sam is the creator of accounts // Sam is the creator of accounts
private_key_type alice_key = generate_private_key("alice"); private_key_type alice_key = generate_private_key("alice");
private_key_type bob_key = generate_private_key("bob"); 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 nathan_delegate = create_delegate(nathan_id(db)).id;
delegate_id_type vikram_delegate = create_delegate(vikram_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(); generate_block();
wdump((db.get_balance(account_id_type(), asset_id_type())));
transfer(account_id_type(), nathan_id, asset(1000000)); transfer(account_id_type(), nathan_id, asset(1000000));
transfer(account_id_type(), vikram_id, asset(100)); transfer(account_id_type(), vikram_id, asset(100));

View file

@ -35,6 +35,23 @@
using namespace graphene::chain; 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<genesis_state_type::initial_witness_type>(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_SUITE(block_tests)
BOOST_AUTO_TEST_CASE( block_database_test ) BOOST_AUTO_TEST_CASE( block_database_test )
@ -113,10 +130,10 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
now += GRAPHENE_DEFAULT_BLOCK_INTERVAL; now += GRAPHENE_DEFAULT_BLOCK_INTERVAL;
// TODO: Don't generate this here // 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; 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 ); b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, delegate_priv_key );
for( uint32_t i = 1; i < 200; ++i ) for( uint32_t i = 1; i < 200; ++i )
@ -161,10 +178,10 @@ BOOST_AUTO_TEST_CASE( undo_block )
fc::temp_directory data_dir; fc::temp_directory data_dir;
{ {
database db; 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 ); 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 ) for( uint32_t i = 0; i < 5; ++i )
{ {
now += db.block_interval(); now += db.block_interval();
@ -204,11 +221,11 @@ BOOST_AUTO_TEST_CASE( fork_blocks )
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP );
database db1; database db1;
db1.open(data_dir1.path(), genesis_state_type()); db1.open(data_dir1.path(), make_genesis());
database db2; 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 ) for( uint32_t i = 0; i < 10; ++i )
{ {
now += db1.block_interval(); now += db1.block_interval();
@ -269,9 +286,9 @@ BOOST_AUTO_TEST_CASE( undo_pending )
fc::temp_directory data_dir; fc::temp_directory data_dir;
{ {
database db; 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); 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; dir2;
database db1, database db1,
db2; db2;
db1.open(dir1.path()); db1.open(dir1.path(), make_genesis());
db2.open(dir2.path()); db2.open(dir2.path(), make_genesis());
fc::time_point_sec now( GRAPHENE_GENESIS_TIMESTAMP ); 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); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
signed_transaction trx; signed_transaction trx;
@ -386,12 +403,12 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
dir2; dir2;
database db1, database db1,
db2; db2;
db1.open(dir1.path()); db1.open(dir1.path(), make_genesis());
db2.open(dir2.path()); db2.open(dir2.path(), make_genesis());
auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check; 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); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
signed_transaction trx; signed_transaction trx;
@ -434,16 +451,16 @@ BOOST_AUTO_TEST_CASE( tapos )
dir2; dir2;
database db1, database db1,
db2; db2;
db1.open(dir1.path()); db1.open(dir1.path(), make_genesis());
db2.open(dir2.path()); db2.open(dir2.path(), make_genesis());
const account_object& init1 = *db1.get_index_type<account_index>().indices().get<by_name>().find("init1"); const account_object& init1 = *db1.get_index_type<account_index>().indices().get<by_name>().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); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type);
now += db1.block_interval(); 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; signed_transaction trx;
//This transaction must be in the next block after its reference, or it is invalid. //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.name = "nathan";
cop.owner = authority(1, key_id_type(), 1); cop.owner = authority(1, key_id_type(), 1);
trx.operations.push_back(cop); trx.operations.push_back(cop);
trx.sign( key_id_type(), delegate_priv_key ); trx.sign(key_id_type(2), delegate_priv_key);
trx.signatures.clear();
trx.sign( key_id_type(), delegate_priv_key );
db1.push_transaction(trx); db1.push_transaction(trx);
now += db1.block_interval(); 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.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. //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); 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.set_expiration(db1.head_block_id(), 2);
trx.signatures.clear(); 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); db1.push_transaction(trx, database::skip_transaction_signatures | database::skip_authority_check);
} catch (fc::exception& e) { } catch (fc::exception& e) {
edump((e.to_detail_string())); edump((e.to_detail_string()));
@ -637,7 +649,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture )
uop.new_parameters.block_interval = 1; uop.new_parameters.block_interval = 1;
cop.proposed_ops.emplace_back(uop); cop.proposed_ops.emplace_back(uop);
trx.operations.push_back(cop); 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); 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), 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)}; account_id_type(5), account_id_type(6), account_id_type(7), account_id_type(8)};
trx.operations.push_back(uop); 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); db.push_transaction(trx);
BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(&db)); 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 ) BOOST_FIXTURE_TEST_CASE( force_settlement, database_fixture )
{ try { { 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 nathan_id = create_account("nathan").get_id();
account_id_type shorter1_id = create_account("shorter1").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id();
account_id_type shorter2_id = create_account("shorter2").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); const asset_object& core = asset_id_type()(db);
// Sam is the creator of accounts // 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"); private_key_type sam_key = generate_private_key("sam");
account_object sam_account_object = create_account( "sam", sam_key ); 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(); near_schedule = db.get_near_witness_schedule();
idump((db.head_block_time())); 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())); idump((db.head_block_time()));
BOOST_CHECK(db.get_dynamic_global_properties().current_witness == near_schedule[2]); BOOST_CHECK(db.get_dynamic_global_properties().current_witness == near_schedule[2]);

View file

@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( create_account_test )
op.owner = auth_bak; op.owner = auth_bak;
trx.operations.back() = op; 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(); trx.validate();
db.push_transaction(trx, ~0); 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.owner = authority(1, child_key.get_id(), 1);
op.active = authority(1, child_key.get_id(), 1); op.active = authority(1, child_key.get_id(), 1);
trx.operations.emplace_back(op); 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); BOOST_REQUIRE_THROW(db.push_transaction(trx), fc::exception);
sign(trx, nathan_key.id,nathan_private_key); sign(trx, nathan_key.id,nathan_private_key);
@ -130,8 +130,8 @@ BOOST_AUTO_TEST_CASE( child_account )
trx.signatures.clear(); trx.signatures.clear();
op.owner = authority(1, account_id_type(nathan.id), 1); op.owner = authority(1, account_id_type(nathan.id), 1);
trx.operations = {op}; trx.operations = {op};
sign(trx, key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis")))); trx.sign({}, delegate_priv_key);
sign(trx, nathan_key.id, nathan_private_key); trx.sign(nathan_key.id, nathan_private_key);
db.push_transaction(trx); db.push_transaction(trx);
BOOST_CHECK( get_account("nathan/child").active.auths == op.active.auths ); 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.operations.push_back(uop);
trx.visit(operation_set_fee(db.current_fee_schedule())); trx.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate(); trx.validate();
trx.sign(key_id_type(),generate_private_key("genesis")); trx.sign(key_id_type(),delegate_priv_key);
db.push_transaction(trx); db.push_transaction(trx);
trx.clear(); trx.clear();
BOOST_CHECK_EQUAL(get_balance(*nathan, *core), 8950000000); 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.operations.back() = wop;
trx.visit(operation_set_fee(db.current_fee_schedule())); trx.visit(operation_set_fee(db.current_fee_schedule()));
trx.validate(); trx.validate();
trx.sign(key_id_type(),generate_private_key("genesis")); trx.sign(key_id_type(),delegate_priv_key);
db.push_transaction(trx); db.push_transaction(trx);
trx.clear(); trx.clear();

View file

@ -685,7 +685,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test )
BOOST_AUTO_TEST_CASE( force_settlement_unavailable ) BOOST_AUTO_TEST_CASE( force_settlement_unavailable )
{ try { { 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 nathan_id = create_account("nathan").get_id();
account_id_type shorter1_id = create_account("shorter1").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id();
account_id_type shorter2_id = create_account("shorter2").get_id(); account_id_type shorter2_id = create_account("shorter2").get_id();