提交 842ef395 编写于 作者: N Nathan Hourt

Refactor Complete

This completes the refactor (to a buildable/tests passing state) from my
last commit.
上级 750da775
......@@ -13,6 +13,7 @@ add_library( eos_chain
block_log.cpp
BlockchainConfiguration.cpp
chain_model.cpp
${HEADERS}
)
......
......@@ -68,8 +68,8 @@ namespace eos { namespace chain {
}
block_log::~block_log() {
my.reset();
flush();
my.reset();
}
void block_log::open(const fc::path& file) {
......
......@@ -154,6 +154,10 @@ std::vector<block_id_type> chain_controller::get_block_ids_on_fork(block_id_type
return result;
}
chain_model chain_controller::get_model() const {
return chain_model(_db);
}
/**
* Push block "may fail" in which case every partial change is unwound. After
* push block is successful the block is appended to the chain database on disk.
......@@ -544,15 +548,16 @@ void chain_controller::validate_tapos(const SignedTransaction& trx)const {
}
void chain_controller::validate_referenced_accounts(const SignedTransaction& trx)const {
auto model = get_model();
for(const auto& auth : trx.authorizations) {
get_account(auth.account);
model.get_account(auth.account);
}
for(const auto& msg : trx.messages) {
get_account(msg.sender);
get_account(msg.recipient);
model.get_account(msg.sender);
model.get_account(msg.recipient);
const AccountName* previous_notify_account = nullptr;
for(const auto& current_notify_account : msg.notify) {
get_account(current_notify_account);
model.get_account(current_notify_account);
if(previous_notify_account) {
EOS_ASSERT(current_notify_account < *previous_notify_account, message_validate_exception,
"Message notify accounts out of order. Possibly a bug in the wallet?");
......@@ -875,9 +880,9 @@ chain_controller::chain_controller(database& database, fork_database& fork_db, b
}();
initialize_indexes();
initialize_genesis(genesis_loader);
spinup_db();
spinup_fork_db();
initialize_genesis(genesis_loader);
}
chain_controller::~chain_controller() {
......@@ -1129,14 +1134,4 @@ void chain_controller::set_apply_handler( const AccountName& contract, const Acc
apply_handlers[contract][std::make_pair(scope,action)] = v;
}
const account_object& chain_controller::get_account( const AccountName& name )const {
try {
return _db.get<account_object,by_name>(name);
} FC_CAPTURE_AND_RETHROW((name)) }
const producer_object&chain_controller::get_producer(const types::AccountName& name) const {
try {
return _db.get<producer_object, by_owner>(get_account(name).id);
} FC_CAPTURE_AND_RETHROW((name)) }
} }
#include <eos/chain/chain_model.hpp>
#include <eos/chain/account_object.hpp>
#include <eos/chain/producer_object.hpp>
namespace eos { namespace chain {
const account_object& chain_model::get_account(const AccountName& name) const {
return db.get<account_object, by_name>(name);
}
const producer_object& chain_model::get_producer(const AccountName& name) const {
return db.get<producer_object, by_owner>(get_account(name).id);
}
} } // namespace eos::chain
......@@ -84,7 +84,7 @@ namespace eos { namespace chain {
id_type id;
account_id_type owner; ///< the account this permission belongs to
id_type parent; ///< parent permission
PermissionName name;
PermissionName name;
shared_authority auth; ///< TODO
};
......
......@@ -29,6 +29,7 @@
#include <eos/chain/fork_database.hpp>
#include <eos/chain/genesis_state.hpp>
#include <eos/chain/block_log.hpp>
#include <eos/chain/chain_model.hpp>
#include <chainbase/chainbase.hpp>
#include <fc/scoped_exit.hpp>
......@@ -170,8 +171,7 @@ namespace eos { namespace chain {
const SignedTransaction& get_recent_transaction( const transaction_id_type& trx_id )const;
std::vector<block_id_type> get_block_ids_on_fork(block_id_type head_of_fork) const;
const account_object& get_account(const AccountName& name)const;
const producer_object& get_producer(const AccountName& name)const;
chain_model get_model()const;
/**
* Calculate the percent of block production slots that were missed in the
......
#pragma once
#include <chainbase/chainbase.hpp>
#include <eos/types/types.hpp>
namespace eos { namespace chain {
class account_object;
class producer_object;
using types::AccountName;
/**
* @brief The chain_model class provides read-only access to blockchain state
*
* The raw chainbase::database API is a lower level of abstraction, dealing with indexes and revisions and undo
* semantics, than clients to the blockchain ought to consume. This class wraps the database with a higher-level,
* read-only API.
*
* @note This class has reference-semantics only. This reference does not imply ownership of the database, and will
* dangle if it outlives the underlying database.
*/
class chain_model {
const chainbase::database& db;
public:
chain_model(const chainbase::database& db) : db(db) {}
const account_object& get_account(const AccountName& name) const;
const producer_object& get_producer(const AccountName& name) const;
template<typename ObjectType, typename IndexedByType, typename CompatibleKey>
const ObjectType* find(CompatibleKey&& key) const {
return db.find<ObjectType, IndexedByType, CompatibleKey>(std::forward<CompatibleKey>(key));
}
template<typename ObjectType>
const ObjectType* find(chainbase::oid<ObjectType> key = chainbase::oid<ObjectType>()) const { return db.find(key); }
template<typename ObjectType, typename IndexedByType, typename CompatibleKey>
const ObjectType& get(CompatibleKey&& key) const {
return db.get<ObjectType, IndexedByType, CompatibleKey>(std::forward<CompatibleKey>(key));
}
template<typename ObjectType>
const ObjectType& get(const chainbase::oid<ObjectType>& key = chainbase::oid<ObjectType>()) const {
return db.get(key);
}
};
} } // namespace eos::chain
......@@ -27,6 +27,7 @@
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/ordered_index.hpp>
namespace bmi = boost::multi_index;
using bmi::indexed_by;
......
#pragma once
/// @file Exists to make including the eos types less toxic. Build error hilarity ensues if you don't include enough of
/// these in the right order.
#include <eos/types/PublicKey.hpp>
#include <eos/types/Asset.hpp>
#include <eos/types/native.hpp>
#include <eos/types/generated.hpp>
......@@ -24,7 +24,6 @@
#pragma once
#include <eos/chain_plugin/chain_plugin.hpp>
#include <eos/database_plugin/database_plugin.hpp>
#include <eos/p2p_plugin/p2p_plugin.hpp>
#include <appbase/application.hpp>
......@@ -48,7 +47,7 @@ namespace block_production_condition {
class producer_plugin : public appbase::plugin<producer_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((chain_plugin)(database_plugin)(p2p_plugin))
APPBASE_PLUGIN_REQUIRES((chain_plugin)(p2p_plugin))
producer_plugin();
virtual ~producer_plugin();
......
......@@ -87,37 +87,25 @@ private_key_type testing_fixture::get_private_key(const public_key_type& public_
return itr->second;
}
testing_database::testing_database(testing_fixture& fixture, std::string id,
fc::optional<genesis_state_type> override_genesis_state)
: genesis_state(override_genesis_state? *override_genesis_state : fixture.genesis_state()),
testing_database::testing_database(chainbase::database& db, fork_database& fork_db, block_log& blocklog,
testing_fixture& fixture, fc::optional<genesis_state_type> override_genesis_state)
: chain_controller(db, fork_db, blocklog, [&override_genesis_state, &fixture] {
if (override_genesis_state) return *override_genesis_state;
return fixture.genesis_state();
}),
fixture(fixture) {
data_dir = fixture.get_temp_dir(id);
// Install the system contract implementation
native_system_contract_plugin::install(*this);
}
void testing_database::open() {
chain_controller::open(data_dir, TEST_DB_SIZE, [this]{return genesis_state;});
}
void testing_database::replay() {
chain_controller::replay(data_dir, TEST_DB_SIZE, genesis_state);
}
void testing_database::wipe(bool include_blocks) {
chain_controller::wipe(data_dir, include_blocks);
}
void testing_database::produce_blocks(uint32_t count, uint32_t blocks_to_miss) {
if (count == 0)
return;
BOOST_REQUIRE_MESSAGE(is_open(), "Producing blocks on closed db... Did you forget to open it?");
for (int i = 0; i < count; ++i) {
auto slot = blocks_to_miss + 1;
auto producer_id = get_scheduled_producer(slot);
const auto& producer = get(producer_id);
const auto& producer = get_model().get(producer_id);
auto private_key = fixture.get_private_key(producer.signing_key);
generate_block(get_slot_time(slot), producer_id, private_key, 0);
}
......
......@@ -134,24 +134,9 @@ protected:
*/
class testing_database : public chain_controller {
public:
testing_database(testing_fixture& fixture, std::string id = std::string(),
testing_database(chainbase::database& db, fork_database& fork_db, block_log& blocklog, testing_fixture& fixture,
fc::optional<genesis_state_type> override_genesis_state = {});
/**
* @brief Open the database using the boilerplate testing database settings
*/
void open();
/**
* @brief Reindex the database using the boilerplate testing database settings
*/
void replay();
/**
* @brief Wipe the database using the boilerplate testing database settings
* @param include_blocks If true, the blocks will be removed as well; otherwise, only the database will be wiped and
* can then be rebuilt from the local blocks
*/
void wipe(bool include_blocks = true);
/**
* @brief Produce new blocks, adding them to the database, optionally following a gap of missed blocks
* @param count Number of blocks to produce
......@@ -174,9 +159,6 @@ public:
void sync_with(testing_database& other);
protected:
fc::path data_dir;
genesis_state_type genesis_state;
testing_fixture& fixture;
};
......
......@@ -3,8 +3,16 @@
* should not be used directly. Use their frontends instead.
*/
#define MKDB1(name) testing_database name(*this); name.open();
#define MKDB2(name, id) testing_database name(*this, #id); name.open();
#define MKDB1(name) \
chainbase::database name ## _db(get_temp_dir(), chainbase::database::read_write, TEST_DB_SIZE); \
block_log name ## _log(get_temp_dir() / "blocklog"); \
fork_database name ## _fdb; \
testing_database name(name ## _db, name ## _fdb, name ## _log, *this);
#define MKDB2(name, id) \
chainbase::database name ## _db(get_temp_dir(#id), chainbase::database::read_write, TEST_DB_SIZE); \
block_log name ## _log(get_temp_dir(#id) / "blocklog"); \
fork_database name ## _fdb; \
testing_database name(name ## _db, name ## _fdb, name ## _log, *this);
#define MKDBS_MACRO(x, y, name) Make_Database(name)
#define MKNET1(name) testing_network name;
......@@ -71,4 +79,4 @@
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
}
#define UPPDCR3(db, owner, key) UPPDCR4(db, owner, key, db.get_producer(owner).configuration)
#define UPPDCR3(db, owner, key) UPPDCR4(db, owner, key, db.get_model().get_producer(owner).configuration)
......@@ -59,15 +59,16 @@ BOOST_FIXTURE_TEST_CASE(produce_blocks, testing_fixture)
BOOST_FIXTURE_TEST_CASE(order_dependent_transactions, testing_fixture)
{ try {
Make_Database(db);
auto model = db.get_model();
db.produce_blocks(10);
Make_Account(db, newguy);
auto newguy = db.find<account_object, by_name>("newguy");
auto newguy = model.find<account_object, by_name>("newguy");
BOOST_CHECK(newguy != nullptr);
Transfer_Asset(db, newguy, init0, Asset(1));
BOOST_CHECK_EQUAL(db.get_account("newguy").balance, Asset(99));
BOOST_CHECK_EQUAL(db.get_account("init0").balance, Asset(100000-99));
BOOST_CHECK_EQUAL(model.get_account("newguy").balance, Asset(99));
BOOST_CHECK_EQUAL(model.get_account("init0").balance, Asset(100000-99));
db.produce_blocks();
BOOST_CHECK_EQUAL(db.head_block_num(), 11);
......@@ -75,14 +76,15 @@ BOOST_FIXTURE_TEST_CASE(order_dependent_transactions, testing_fixture)
BOOST_CHECK(!db.fetch_block_by_number(11)->cycles.empty());
BOOST_CHECK(!db.fetch_block_by_number(11)->cycles.front().empty());
BOOST_CHECK_EQUAL(db.fetch_block_by_number(11)->cycles.front().front().user_input.size(), 2);
BOOST_CHECK_EQUAL(db.get_account("newguy").balance, Asset(99));
BOOST_CHECK_EQUAL(db.get_account("init0").balance, Asset(100000-99));
BOOST_CHECK_EQUAL(model.get_account("newguy").balance, Asset(99));
BOOST_CHECK_EQUAL(model.get_account("init0").balance, Asset(100000-99));
} FC_LOG_AND_RETHROW() }
//Test account script processing
BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
{ try {
Make_Database(db);
auto model = db.get_model();
db.produce_blocks(10);
SignedTransaction trx;
......@@ -120,7 +122,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
Transfer_Asset(db, init3, init1, Asset(100), "transfer 100");
db.produce_blocks(1);
const auto& world = db.get<key_value_object,by_scope_key>(boost::make_tuple(AccountName("init1"), String("hello")));
const auto& world = model.get<key_value_object,by_scope_key>(boost::make_tuple(AccountName("init1"), String("hello")));
BOOST_CHECK_EQUAL( string(world.value.c_str()), "world" );
} FC_LOG_AND_RETHROW() }
......@@ -129,6 +131,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
BOOST_FIXTURE_TEST_CASE(missed_blocks, testing_fixture)
{ try {
Make_Database(db)
auto model = db.get_model();
db.produce_blocks();
BOOST_CHECK_EQUAL(db.head_block_num(), 1);
......@@ -144,10 +147,10 @@ BOOST_FIXTURE_TEST_CASE(missed_blocks, testing_fixture)
BOOST_CHECK_EQUAL(db.head_block_num(), 2);
BOOST_CHECK_EQUAL(db.head_block_time().to_iso_string(), next_block_time.to_iso_string());
BOOST_CHECK_EQUAL(db.head_block_producer()._id, next_producer._id);
BOOST_CHECK_EQUAL(db.get(next_producer).total_missed, 0);
BOOST_CHECK_EQUAL(model.get(next_producer).total_missed, 0);
for (auto producer : skipped_producers) {
BOOST_CHECK_EQUAL(db.get(producer).total_missed, 1);
BOOST_CHECK_EQUAL(model.get(producer).total_missed, 1);
}
} FC_LOG_AND_RETHROW() }
......@@ -338,21 +341,24 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
// Check that a db rewinds to the LIB after being closed and reopened
BOOST_FIXTURE_TEST_CASE(restart_db, testing_fixture)
{ try {
Make_Database(db)
auto lag = EOS_PERCENT(config::ProducerCount, config::IrreversibleThresholdPercent);
db.produce_blocks(20);
{
Make_Database(db, x);
BOOST_CHECK_EQUAL(db.head_block_num(), 20);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 20 - lag);
db.produce_blocks(20);
db.close();
db.open();
BOOST_CHECK_EQUAL(db.head_block_num(), 20);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 20 - lag);
}
// After restarting, we should have rewound to the last irreversible block.
BOOST_CHECK_EQUAL(db.head_block_num(), 20 - lag);
db.produce_blocks(5);
BOOST_CHECK_EQUAL(db.head_block_num(), 25 - lag);
{
Make_Database(db, x);
// After restarting, we should have rewound to the last irreversible block.
BOOST_CHECK_EQUAL(db.head_block_num(), 20 - lag);
db.produce_blocks(5);
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
......@@ -373,7 +379,6 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture)
BOOST_CHECK_EQUAL(sleepy.head_block_num(), 20);
net.disconnect_database(sleepy);
sleepy.close();
}
// 5 new blocks are produced
......@@ -393,49 +398,67 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture)
// Test reindexing the blockchain
BOOST_FIXTURE_TEST_CASE(reindex, testing_fixture)
{ try {
Make_Database(db)
auto lag = EOS_PERCENT(config::ProducerCount, config::IrreversibleThresholdPercent);
db.produce_blocks(100);
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 100 - lag);
db.close();
db.replay();
BOOST_CHECK_EQUAL(db.head_block_num(), 100 - lag);
db.produce_blocks(20);
BOOST_CHECK_EQUAL(db.head_block_num(), 120 - lag);
{
chainbase::database db(get_temp_dir(), chainbase::database::read_write, TEST_DB_SIZE);
block_log log(get_temp_dir("log"));
fork_database fdb;
testing_database chain(db, fdb, log, *this);
chain.produce_blocks(100);
BOOST_CHECK_EQUAL(chain.last_irreversible_block_num(), 100 - lag);
}
{
chainbase::database db(get_temp_dir(), chainbase::database::read_write, TEST_DB_SIZE);
block_log log(get_temp_dir("log"));
fork_database fdb;
testing_database chain(db, fdb, log, *this);
BOOST_CHECK_EQUAL(chain.head_block_num(), 100 - lag);
chain.produce_blocks(20);
BOOST_CHECK_EQUAL(chain.head_block_num(), 120 - lag);
}
} FC_LOG_AND_RETHROW() }
// Test wiping a database and resyncing with an ongoing network
BOOST_FIXTURE_TEST_CASE(wipe, testing_fixture)
{ try {
Make_Databases((db1)(db2)(db3))
Make_Network(net, (db1)(db2)(db3))
Make_Databases((db1)(db2))
Make_Network(net, (db1)(db2))
{
// Create db3 with a temporary data dir
Make_Database(db3)
net.connect_database(db3);
db1.produce_blocks(3);
db2.produce_blocks(3);
BOOST_CHECK_EQUAL(db1.head_block_num(), 6);
BOOST_CHECK_EQUAL(db2.head_block_num(), 6);
BOOST_CHECK_EQUAL(db3.head_block_num(), 6);
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db2.head_block_id().str());
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db3.head_block_id().str());
net.disconnect_database(db3);
}
db1.produce_blocks(3);
db2.produce_blocks(3);
BOOST_CHECK_EQUAL(db1.head_block_num(), 6);
BOOST_CHECK_EQUAL(db2.head_block_num(), 6);
BOOST_CHECK_EQUAL(db3.head_block_num(), 6);
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db2.head_block_id().str());
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db3.head_block_id().str());
net.disconnect_database(db3);
db3.close();
db3.wipe();
db3.open();
BOOST_CHECK_EQUAL(db3.head_block_num(), 0);
net.connect_database(db3);
BOOST_CHECK_EQUAL(db3.head_block_num(), 6);
db1.produce_blocks(3);
db2.produce_blocks(3);
BOOST_CHECK_EQUAL(db1.head_block_num(), 12);
BOOST_CHECK_EQUAL(db2.head_block_num(), 12);
BOOST_CHECK_EQUAL(db3.head_block_num(), 12);
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db2.head_block_id().str());
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db3.head_block_id().str());
{
// Create new db3 with a new temporary data dir
Make_Database(db3)
BOOST_CHECK_EQUAL(db3.head_block_num(), 0);
net.connect_database(db3);
BOOST_CHECK_EQUAL(db3.head_block_num(), 6);
db1.produce_blocks(3);
db2.produce_blocks(3);
BOOST_CHECK_EQUAL(db1.head_block_num(), 12);
BOOST_CHECK_EQUAL(db2.head_block_num(), 12);
BOOST_CHECK_EQUAL(db3.head_block_num(), 12);
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db2.head_block_id().str());
BOOST_CHECK_EQUAL(db1.head_block_id().str(), db3.head_block_id().str());
}
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()
......@@ -24,6 +24,7 @@
#include <eos/chain/chain_controller.hpp>
#include <eos/chain/account_object.hpp>
#include <chainbase/chainbase.hpp>
#include <fc/crypto/digest.hpp>
......@@ -33,12 +34,13 @@
namespace eos {
using namespace chain;
namespace bfs = boost::filesystem;
// Simple tests of undo infrastructure
BOOST_FIXTURE_TEST_CASE(undo_test, testing_fixture)
{ try {
testing_database db(*this);
db.open();
auto db = database(get_temp_dir(), database::read_write, 8*1024*1024);
db.add_index<account_index>();
auto ses = db.start_undo_session(true);
// Create an account
......@@ -121,7 +123,7 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters, testing_fixture, * boost::un
for (int i = 0; i < votes.size(); ++i) {
auto name = std::string("init") + fc::to_string(i);
Update_Producer(db, name, db.get_producer(name).signing_key, votes[i]);
Update_Producer(db, name, db.get_model().get_producer(name).signing_key, votes[i]);
}
BOOST_CHECK_NE(db.get_global_properties().configuration, medians);
......
......@@ -23,25 +23,26 @@ BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
{ try {
Make_Database(db);
db.produce_blocks(10);
auto model = db.get_model();
const auto& init1_account = db.get_account("init1");
const auto& init1_account = model.get_account("init1");
BOOST_CHECK_EQUAL(init1_account.balance, Asset(100000));
Make_Account(db, joe, init1, Asset(1000));
{ // test in the pending state
const auto& joe_account = db.get_account("joe");
const auto& joe_account = model.get_account("joe");
BOOST_CHECK_EQUAL(joe_account.balance, Asset(1000));
BOOST_CHECK_EQUAL(init1_account.balance, Asset(100000 - 1000));
const auto& joe_owner_authority = db.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "owner"));
const auto& joe_owner_authority = model.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "owner"));
BOOST_CHECK_EQUAL(joe_owner_authority.auth.threshold, 1);
BOOST_CHECK_EQUAL(joe_owner_authority.auth.accounts.size(), 0);
BOOST_CHECK_EQUAL(joe_owner_authority.auth.keys.size(), 1);
BOOST_CHECK_EQUAL(string(joe_owner_authority.auth.keys[0].key), string(joe_public_key));
BOOST_CHECK_EQUAL(joe_owner_authority.auth.keys[0].weight, 1);
const auto& joe_active_authority = db.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "active"));
const auto& joe_active_authority = model.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "active"));
BOOST_CHECK_EQUAL(joe_active_authority.auth.threshold, 1);
BOOST_CHECK_EQUAL(joe_active_authority.auth.accounts.size(), 0);
BOOST_CHECK_EQUAL(joe_active_authority.auth.keys.size(), 1);
......@@ -51,18 +52,18 @@ BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
db.produce_blocks(1); /// verify changes survived creating a new block
{
const auto& joe_account = db.get_account("joe");
const auto& joe_account = model.get_account("joe");
BOOST_CHECK_EQUAL(joe_account.balance, Asset(1000));
BOOST_CHECK_EQUAL(init1_account.balance, Asset(100000 - 1000));
const auto& joe_owner_authority = db.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "owner"));
const auto& joe_owner_authority = model.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "owner"));
BOOST_CHECK_EQUAL(joe_owner_authority.auth.threshold, 1);
BOOST_CHECK_EQUAL(joe_owner_authority.auth.accounts.size(), 0);
BOOST_CHECK_EQUAL(joe_owner_authority.auth.keys.size(), 1);
BOOST_CHECK_EQUAL(string(joe_owner_authority.auth.keys[0].key), string(joe_public_key));
BOOST_CHECK_EQUAL(joe_owner_authority.auth.keys[0].weight, 1);
const auto& joe_active_authority = db.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "active"));
const auto& joe_active_authority = model.get<permission_object, by_owner>(boost::make_tuple(joe_account.id, "active"));
BOOST_CHECK_EQUAL(joe_active_authority.auth.threshold, 1);
BOOST_CHECK_EQUAL(joe_active_authority.auth.accounts.size(), 0);
BOOST_CHECK_EQUAL(joe_active_authority.auth.keys.size(), 1);
......@@ -75,6 +76,7 @@ BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
{ try {
Make_Database(db)
auto model = db.get_model();
BOOST_CHECK_EQUAL(db.head_block_num(), 0);
db.produce_blocks(10);
......@@ -106,21 +108,22 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
trx.setMessage(0, "Transfer", trans);
db.push_transaction(trx);
BOOST_CHECK_EQUAL(db.get_account("init1").balance, Asset(100000 - 100));
BOOST_CHECK_EQUAL(db.get_account("init2").balance, Asset(100000 + 100));
BOOST_CHECK_EQUAL(model.get_account("init1").balance, Asset(100000 - 100));
BOOST_CHECK_EQUAL(model.get_account("init2").balance, Asset(100000 + 100));
db.produce_blocks(1);
BOOST_REQUIRE_THROW(db.push_transaction(trx), transaction_exception); // not unique
Transfer_Asset(db, init2, init1, Asset(100));
BOOST_CHECK_EQUAL(db.get_account("init1").balance, Asset(100000));
BOOST_CHECK_EQUAL(db.get_account("init2").balance, Asset(100000));
BOOST_CHECK_EQUAL(model.get_account("init1").balance, Asset(100000));
BOOST_CHECK_EQUAL(model.get_account("init2").balance, Asset(100000));
} FC_LOG_AND_RETHROW() }
// Simple test of creating/updating a new block producer
BOOST_FIXTURE_TEST_CASE(producer_creation, testing_fixture)
{ try {
Make_Database(db)
auto model = db.get_model();
db.produce_blocks();
BOOST_CHECK_EQUAL(db.head_block_num(), 1);
......@@ -128,8 +131,8 @@ BOOST_FIXTURE_TEST_CASE(producer_creation, testing_fixture)
Make_Producer(db, producer, producer_public_key);
while (db.head_block_num() < 3) {
auto& producer = db.get_producer("producer");
BOOST_CHECK_EQUAL(db.get(producer.owner).name, "producer");
auto& producer = model.get_producer("producer");
BOOST_CHECK_EQUAL(model.get(producer.owner).name, "producer");
BOOST_CHECK_EQUAL(producer.signing_key, producer_public_key);
BOOST_CHECK_EQUAL(producer.last_aslot, 0);
BOOST_CHECK_EQUAL(producer.total_missed, 0);
......@@ -139,7 +142,7 @@ BOOST_FIXTURE_TEST_CASE(producer_creation, testing_fixture)
Make_Key(signing);
Update_Producer(db, "producer", signing_public_key);
auto& producer = db.get_producer("producer");
auto& producer = model.get_producer("producer");
BOOST_CHECK_EQUAL(producer.signing_key, signing_public_key);
} FC_LOG_AND_RETHROW() }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册