Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:EOSIO/eos
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Jun 21, 2017
2 parents e59e296 + 214d2b2 commit ecad802
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions libraries/chain/chain_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ signed_block chain_controller::_generate_block(

pending_block.producer = producer_obj.owner;

// If this block is last in a round, calculate the schedule for the new round
if (pending_block.block_num() % config::BlocksPerRound == 0) {
auto new_schedule = _admin->get_next_round(_db);
pending_block.producer_changes = get_global_properties().active_producers - new_schedule;
}

if( !(skip & skip_producer_signature) )
pending_block.sign( block_signing_private_key );

Expand Down
12 changes: 10 additions & 2 deletions tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ testing_fixture::testing_fixture() {
auto private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(name));
public_key_type public_key = private_key.get_public_key();
default_genesis_state.initial_accounts.emplace_back(name, 0, 100000, public_key, public_key);
key_ring[public_key] = private_key;
store_private_key(private_key);

private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(name + ".producer"));
public_key = private_key.get_public_key();
default_genesis_state.initial_producers.emplace_back(name, public_key);
key_ring[public_key] = private_key;
store_private_key(private_key);
}
}

Expand All @@ -81,6 +81,10 @@ native_contract::genesis_state_type& testing_fixture::genesis_state() {
return default_genesis_state;
}

void testing_fixture::store_private_key(const private_key_type& key) {
key_ring[key.get_public_key()] = key;
}

private_key_type testing_fixture::get_private_key(const public_key_type& public_key) const {
auto itr = key_ring.find(public_key);
EOS_ASSERT(itr != key_ring.end(), missing_key_exception,
Expand Down Expand Up @@ -143,6 +147,10 @@ std::set<types::AccountName> testing_database::get_approved_producers(const type
return {set.begin(), set.end()};
}

types::PublicKey testing_database::get_block_signing_key(const types::AccountName& producerName) {
return get_database().get<producer_object, by_owner>(producerName).signing_key;
}

void testing_network::connect_database(testing_database& new_database) {
if (databases.count(&new_database))
return;
Expand Down
4 changes: 4 additions & 0 deletions tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class testing_fixture {
const native_contract::genesis_state_type& genesis_state() const;
native_contract::genesis_state_type& genesis_state();

void store_private_key(const private_key_type& key);
private_key_type get_private_key(const public_key_type& public_key) const;

protected:
Expand Down Expand Up @@ -170,6 +171,8 @@ class testing_database : public chain_controller {

/// @brief Get the set of producers approved by the named account
std::set<AccountName> get_approved_producers(const AccountName& account);
/// @brief Get the specified block producer's signing key
PublicKey get_block_signing_key(const AccountName& producerName);

protected:
testing_fixture& fixture;
Expand Down Expand Up @@ -284,6 +287,7 @@ class testing_network {
* @endcode
*/
#define Make_Key(name) auto name ## _private_key = private_key_type::regenerate(fc::digest(#name "_private_key")); \
store_private_key(name ## _private_key); \
PublicKey name ## _public_key = name ## _private_key.get_public_key();

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ vector<uint8_t> assemble_wast( const std::string& wast ) {
}

//Test account script processing
BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture, *boost::unit_test::expected_failures(1))
{ try {
Make_Database(db);
db.produce_blocks(10);
Expand Down
6 changes: 2 additions & 4 deletions tests/tests/database_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters_2, testing_fixture)
} FC_LOG_AND_RETHROW() }

// Test that if I create a producer and vote for him, he gets in on the next round (but not before)
BOOST_FIXTURE_TEST_CASE(producer_voting_1, testing_fixture, *boost::unit_test::expected_failures(1)) {
BOOST_FIXTURE_TEST_CASE(producer_voting_1, testing_fixture) {
try {
Make_Database(db)
db.produce_blocks();
Expand All @@ -210,7 +210,6 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_1, testing_fixture, *boost::unit_test::e
db.produce_blocks();

const auto& gpo = db.get_global_properties();
#warning TODO: expected failure because chain_controller::generate_block does not update round
BOOST_REQUIRE(boost::find(gpo.active_producers, "joe") != gpo.active_producers.end());

Approve_Producer(db, bob, joe, false);
Expand All @@ -226,7 +225,7 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_1, testing_fixture, *boost::unit_test::e
}

// Same as producer_voting_1, except we first cast the vote for the producer, _then_ get a stake
BOOST_FIXTURE_TEST_CASE(producer_voting_2, testing_fixture, *boost::unit_test::expected_failures(1)) {
BOOST_FIXTURE_TEST_CASE(producer_voting_2, testing_fixture) {
try {
Make_Database(db)
db.produce_blocks();
Expand Down Expand Up @@ -261,7 +260,6 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_2, testing_fixture, *boost::unit_test::e
db.produce_blocks();

const auto& gpo = db.get_global_properties();
#warning TODO: expected failure because chain_controller::generate_block does not update round
BOOST_REQUIRE(boost::find(gpo.active_producers, "joe") != gpo.active_producers.end());

Approve_Producer(db, bob, joe, false);
Expand Down

0 comments on commit ecad802

Please sign in to comment.