提交 861cd06c 编写于 作者: N Nathan Hourt

Resolve #10: Tests Fixed

All tests now pass again. :)
上级 1209d326
......@@ -894,7 +894,7 @@ void database::update_last_irreversible_block()
// 1 1 1 1 1 1 1 2 2 2 -> 1
// 3 3 3 3 3 3 3 3 3 3 -> 3
size_t offset = ((EOS_100_PERCENT - EOS_IRREVERSIBLE_THRESHOLD) * producer_objs.size() / EOS_100_PERCENT);
size_t offset = EOS_PERCENT(producer_objs.size(), EOS_100_PERCENT - EOS_IRREVERSIBLE_THRESHOLD);
std::nth_element( producer_objs.begin(), producer_objs.begin() + offset, producer_objs.end(),
[]( const producer_object* a, const producer_object* b )
......
......@@ -29,6 +29,7 @@
/** percentage fields are fixed point with a denominator of 10,000 */
#define EOS_100_PERCENT 10000
#define EOS_1_PERCENT (EOS_100_PERCENT/100)
#define EOS_DEFAULT_MAX_BLOCK_SIZE (256*1024)
#define EOS_DEFAULT_PRODUCER_PAY_PER_BLOCK (EOS_BLOCKCHAIN_PRECISION * int64_t(10))
......@@ -36,6 +37,12 @@
#define EOS_IRREVERSIBLE_THRESHOLD (70 * EOS_1_PERCENT)
template<typename Number>
Number EOS_PERCENT(Number value, int percentage) {
return value * percentage / EOS_100_PERCENT;
}
namespace eos { namespace config {
const static int EOS_PRODUCER_COUNT = 21;
const static int ProducerCount = 21;
const static int IrreversibleThreshold = 70 * EOS_1_PERCENT;
} } // namespace eos::config
......@@ -50,7 +50,7 @@ namespace eos { namespace chain {
id_type id;
chain_parameters parameters;
std::array<producer_id_type, config::EOS_PRODUCER_COUNT> active_producers;
std::array<producer_id_type, config::ProducerCount> active_producers;
};
......
......@@ -33,7 +33,7 @@ namespace eos { namespace chain {
struct immutable_chain_parameters
{
uint16_t min_producer_count = config::EOS_PRODUCER_COUNT;
uint16_t min_producer_count = config::ProducerCount;
};
} } // eos::chain
......
......@@ -44,7 +44,7 @@ namespace eos { namespace chain {
testing_fixture::testing_fixture() {
default_genesis_state.initial_timestamp = fc::time_point_sec(EOS_TESTING_GENESIS_TIMESTAMP);
default_genesis_state.immutable_parameters.min_producer_count = 11;
default_genesis_state.immutable_parameters.min_producer_count = config::ProducerCount;
for (int i = 0; i < default_genesis_state.immutable_parameters.min_producer_count; ++i) {
auto name = std::string("init") + fc::to_string(i);
auto private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(name));
......
......@@ -34,7 +34,8 @@
#include "../common/database_fixture.hpp"
using namespace eos::chain;
using namespace eos;
using namespace chain;
BOOST_AUTO_TEST_SUITE(block_tests)
......@@ -266,18 +267,20 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
BOOST_FIXTURE_TEST_CASE(restart_db, testing_fixture)
{ try {
MKDB(db)
db.produce_blocks(10);
BOOST_CHECK_EQUAL(db.head_block_num(), 10);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 3);
auto lag = EOS_PERCENT(config::ProducerCount, config::IrreversibleThreshold);
db.produce_blocks(20);
BOOST_CHECK_EQUAL(db.head_block_num(), 20);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 20 - lag);
db.close();
db.open();
// After restarting, we should have rewound to the last irreversible block.
BOOST_CHECK_EQUAL(db.head_block_num(), 3);
BOOST_CHECK_EQUAL(db.head_block_num(), 20 - lag);
db.produce_blocks(5);
BOOST_CHECK_EQUAL(db.head_block_num(), 8);
BOOST_CHECK_EQUAL(db.head_block_num(), 25 - lag);
} FC_LOG_AND_RETHROW() }
// Check that a db which is closed and reopened successfully syncs back with the network, including retrieving blocks
......@@ -286,15 +289,16 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture)
{ try {
MKDB(producer)
MKNET(net, (producer))
// Produce 10 blocks on the chain
producer.produce_blocks(10);
auto lag = EOS_PERCENT(config::ProducerCount, config::IrreversibleThreshold);
producer.produce_blocks(20);
{
// The new node, sleepy, joins, syncs, disconnects
MKDB(sleepy, sleepy)
net.connect_database(sleepy);
BOOST_CHECK_EQUAL(producer.head_block_num(), 10);
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 10);
BOOST_CHECK_EQUAL(producer.head_block_num(), 20);
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 20);
net.disconnect_database(sleepy);
sleepy.close();
......@@ -302,15 +306,15 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture)
// 5 new blocks are produced
producer.produce_blocks(5);
BOOST_CHECK_EQUAL(producer.head_block_num(), 15);
BOOST_CHECK_EQUAL(producer.head_block_num(), 25);
// Sleepy is reborn! Check that it is now rewound to the LIB...
MKDB(sleepy, sleepy)
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 3);
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 20 - lag);
// Reconnect sleepy to the network and check that it syncs up to the present
net.connect_database(sleepy);
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 15);
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 25);
BOOST_CHECK_EQUAL(sleepy.head_block_id().str(), producer.head_block_id().str());
} FC_LOG_AND_RETHROW() }
......@@ -318,13 +322,16 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture)
BOOST_FIXTURE_TEST_CASE(reindex, testing_fixture)
{ try {
MKDB(db)
auto lag = EOS_PERCENT(config::ProducerCount, config::IrreversibleThreshold);
db.produce_blocks(100);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 93);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 100 - lag);
db.close();
db.reindex();
BOOST_CHECK_EQUAL(db.head_block_num(), 93);
BOOST_CHECK_EQUAL(db.head_block_num(), 100 - lag);
db.produce_blocks(20);
BOOST_CHECK_EQUAL(db.head_block_num(), 113);
BOOST_CHECK_EQUAL(db.head_block_num(), 120 - lag);
} FC_LOG_AND_RETHROW() }
// Test wiping a database and resyncing with an ongoing network
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册