提交 6c4e89f3 编写于 作者: N Nathan Hourt

Update naming in test framework

The testing framework still used "database" to refer to the blockchain, which doesn't make sense since we split the blockchain class from the database class. This commit updates the names/docs in the
test framework to use chain instead of database as appropriate.
上级 528fedf8
......@@ -92,12 +92,12 @@ private_key_type testing_fixture::get_private_key(const public_key_type& public_
return itr->second;
}
testing_database::testing_database(chainbase::database& db, fork_database& fork_db, block_log& blocklog,
testing_blockchain::testing_blockchain(chainbase::database& db, fork_database& fork_db, block_log& blocklog,
chain_initializer_interface& initializer, testing_fixture& fixture)
: chain_controller(db, fork_db, blocklog, initializer, native_contract::make_administrator()),
fixture(fixture) {}
void testing_database::produce_blocks(uint32_t count, uint32_t blocks_to_miss) {
void testing_blockchain::produce_blocks(uint32_t count, uint32_t blocks_to_miss) {
if (count == 0)
return;
......@@ -109,7 +109,7 @@ void testing_database::produce_blocks(uint32_t count, uint32_t blocks_to_miss) {
}
}
void testing_database::sync_with(testing_database& other) {
void testing_blockchain::sync_with(testing_blockchain& other) {
// Already in sync?
if (head_block_id() == other.head_block_id())
return;
......@@ -117,7 +117,7 @@ void testing_database::sync_with(testing_database& other) {
if (head_block_num() < other.head_block_num())
return other.sync_with(*this);
auto sync_dbs = [](testing_database& a, testing_database& b) {
auto sync_dbs = [](testing_blockchain& a, testing_blockchain& b) {
for (int i = 1; i <= a.head_block_num(); ++i) {
auto block = a.fetch_block_by_number(i);
if (block && !b.is_known_block(block->id())) {
......@@ -130,19 +130,19 @@ void testing_database::sync_with(testing_database& other) {
sync_dbs(other, *this);
}
types::Asset testing_database::get_liquid_balance(const types::AccountName& account) {
types::Asset testing_blockchain::get_liquid_balance(const types::AccountName& account) {
return get_database().get<BalanceObject, byOwnerName>(account).balance;
}
types::Asset testing_database::get_staked_balance(const types::AccountName& account) {
types::Asset testing_blockchain::get_staked_balance(const types::AccountName& account) {
return get_database().get<StakedBalanceObject, byOwnerName>(account).stakedBalance;
}
types::Asset testing_database::get_unstaking_balance(const types::AccountName& account) {
types::Asset testing_blockchain::get_unstaking_balance(const types::AccountName& account) {
return get_database().get<StakedBalanceObject, byOwnerName>(account).unstakingBalance;
}
std::set<types::AccountName> testing_database::get_approved_producers(const types::AccountName& account) {
std::set<types::AccountName> testing_blockchain::get_approved_producers(const types::AccountName& account) {
const auto& sbo = get_database().get<StakedBalanceObject, byOwnerName>(account);
if (sbo.producerVotes.contains<ProducerSlate>()) {
auto range = sbo.producerVotes.get<ProducerSlate>().range();
......@@ -151,37 +151,37 @@ std::set<types::AccountName> testing_database::get_approved_producers(const type
return {};
}
types::PublicKey testing_database::get_block_signing_key(const types::AccountName& producerName) {
types::PublicKey testing_blockchain::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))
void testing_network::connect_blockchain(testing_blockchain& new_database) {
if (blockchains.count(&new_database))
return;
// If the network isn't empty, sync the new database with one of the old ones. The old ones are already in sync with
// eachother, so just grab one arbitrarily. The old databases are connected to the propagation signals, so when one
// of them gets synced, it will propagate blocks to the others as well.
if (!databases.empty()) {
databases.begin()->first->sync_with(new_database);
if (!blockchains.empty()) {
blockchains.begin()->first->sync_with(new_database);
}
// The new database is now in sync with any old ones; go ahead and connect the propagation signal.
databases[&new_database] = new_database.applied_block.connect([this, &new_database](const signed_block& block) {
blockchains[&new_database] = new_database.applied_block.connect([this, &new_database](const signed_block& block) {
propagate_block(block, new_database);
});
}
void testing_network::disconnect_database(testing_database& leaving_database) {
databases.erase(&leaving_database);
void testing_network::disconnect_database(testing_blockchain& leaving_database) {
blockchains.erase(&leaving_database);
}
void testing_network::disconnect_all() {
databases.clear();
blockchains.clear();
}
void testing_network::propagate_block(const signed_block& block, const testing_database& skip_db) {
for (const auto& pair : databases) {
void testing_network::propagate_block(const signed_block& block, const testing_blockchain& skip_db) {
for (const auto& pair : blockchains) {
if (pair.first == &skip_db) continue;
boost::signals2::shared_connection_block blocker(pair.second);
pair.first->push_block(block);
......
......@@ -88,7 +88,7 @@ FC_DECLARE_EXCEPTION(testing_exception, 6000000, "test framework exception")
FC_DECLARE_DERIVED_EXCEPTION(missing_key_exception, eos::chain::testing_exception, 6010000, "key could not be found")
/**
* @brief The testing_fixture class provides various services relevant to testing the database.
* @brief The testing_fixture class provides various services relevant to testing the blockchain.
*/
class testing_fixture {
public:
......@@ -125,42 +125,43 @@ protected:
};
/**
* @brief The testing_database class wraps database and eliminates some of the boilerplate for common operations on the
* database during testing.
* @brief The testing_blockchain class wraps chain_controller and eliminates some of the boilerplate for common
* operations on the blockchain during testing.
*
* testing_databases have an optional ID, which is passed to the constructor. If two testing_databases are created with
* the same ID, they will have the same data directory. If no ID, or an empty ID, is provided, the database will have a
* unique data directory which no subsequent testing_database will be assigned.
* testing_blockchains have an optional ID, which is passed to the constructor. If two testing_blockchains are created
* with the same ID, they will have the same data directory. If no ID, or an empty ID, is provided, the database will
* have a unique data directory which no subsequent testing_blockchain will be assigned.
*
* testing_database helps with producing blocks, or missing blocks, via the @ref produce_blocks and @ref miss_blocks
* testing_blockchain helps with producing blocks, or missing blocks, via the @ref produce_blocks and @ref miss_blocks
* methods. To produce N blocks, simply call produce_blocks(N); to miss N blocks, call miss_blocks(N). Note that missing
* blocks has no effect on the database until the next block, following the missed blocks, is produced.
* blocks has no effect on the blockchain until the next block, following the missed blocks, is produced.
*/
class testing_database : public chain_controller {
class testing_blockchain : public chain_controller {
public:
testing_database(chainbase::database& db, fork_database& fork_db, block_log& blocklog,
testing_blockchain(chainbase::database& db, fork_database& fork_db, block_log& blocklog,
chain_initializer_interface& initializer, testing_fixture& fixture);
/**
* @brief Produce new blocks, adding them to the database, optionally following a gap of missed blocks
* @brief Produce new blocks, adding them to the blockchain, optionally following a gap of missed blocks
* @param count Number of blocks to produce
* @param blocks_to_miss Number of block intervals to miss a production before producing the next block
*
* Creates and adds @ref count new blocks to the database, after going @ref blocks_to_miss intervals without
* Creates and adds @ref count new blocks to the blockchain, after going @ref blocks_to_miss intervals without
* producing a block.
*/
void produce_blocks(uint32_t count = 1, uint32_t blocks_to_miss = 0);
/**
* @brief Sync this database with other
* @param other Database to sync with
* @brief Sync this blockchain with other
* @param other Blockchain to sync with
*
* To sync the databases, all blocks from one database which are unknown to the other are pushed to the other, then
* the same thing in reverse. Whichever database has more blocks will have its blocks sent to the other first.
* To sync the blockchains, all blocks from one blockchain which are unknown to the other are pushed to the other,
* then the same thing in reverse. Whichever blockchain has more blocks will have its blocks sent to the other
* first.
*
* Blocks not on the main fork are ignored.
*/
void sync_with(testing_database& other);
void sync_with(testing_blockchain& other);
/// @brief Get the liquid balance belonging to the named account
Asset get_liquid_balance(const types::AccountName& account);
......@@ -181,39 +182,39 @@ protected:
using boost::signals2::scoped_connection;
/**
* @brief The testing_network class provides a simplistic virtual P2P network connecting testing_databases together.
* @brief The testing_network class provides a simplistic virtual P2P network connecting testing_blockchains together.
*
* A testing_database may be connected to zero or more testing_networks at any given time. When a new testing_database
* joins the network, it will be synced with all other databases already in the network (blocks known only to the new
* database will be pushed to the prior network members and vice versa, ignoring blocks not on the main fork). After
* this, whenever any database in the network gets a new block, that block will be pushed to all other databases in the
* network as well.
* A testing_blockchain may be connected to zero or more testing_networks at any given time. When a new
* testing_blockchain joins the network, it will be synced with all other blockchains already in the network (blocks
* known only to the new chain will be pushed to the prior network members and vice versa, ignoring blocks not on the
* main fork). After this, whenever any blockchain in the network gets a new block, that block will be pushed to all
* other blockchains in the network as well.
*/
class testing_network {
public:
/**
* @brief Add a new database to the network
* @param new_database The database to add
* @param new_blockchain The blockchain to add
*/
void connect_database(testing_database& new_database);
void connect_blockchain(testing_blockchain& new_database);
/**
* @brief Remove a database from the network
* @param leaving_database The database to remove
* @param leaving_blockchain The database to remove
*/
void disconnect_database(testing_database& leaving_database);
void disconnect_database(testing_blockchain& leaving_blockchain);
/**
* @brief Disconnect all databases from the network
* @brief Disconnect all blockchains from the network
*/
void disconnect_all();
/**
* @brief Send a block to all databases in this network
* @brief Send a block to all blockchains in this network
* @param block The block to send
*/
void propagate_block(const signed_block& block, const testing_database& skip_db);
void propagate_block(const signed_block& block, const testing_blockchain& skip_db);
protected:
std::map<testing_database*, scoped_connection> databases;
std::map<testing_blockchain*, scoped_connection> blockchains;
};
/// Some helpful macros to reduce boilerplate when making testcases
......@@ -221,53 +222,53 @@ protected:
#include "macro_support.hpp"
/**
* @brief Create/Open a testing_database, optionally with an ID
* @brief Create/Open a testing_blockchain, optionally with an ID
*
* Creates and opens a testing_database with the first argument as its name, and, if present, the second argument as
* Creates and opens a testing_blockchain with the first argument as its name, and, if present, the second argument as
* its ID. The ID should be provided without quotes.
*
* Example:
* @code{.cpp}
* // Create testing_database db1
* Make_Database(db1)
* // Create testing_blockchain chain1
* Make_Blockchain(chain1)
*
* // The above creates the following objects:
* chainbase::database db1_db;
* block_log db1_log;
* fork_database db1_fdb;
* native_contract::native_contract_chain_initializer db1_initializer;
* testing_database db1;
* chainbase::database chain1_db;
* block_log chain1_log;
* fork_database chain1_fdb;
* native_contract::native_contract_chain_initializer chain1_initializer;
* testing_blockchain chain1;
* @endcode
*/
#define Make_Database(...) BOOST_PP_OVERLOAD(MKDB, __VA_ARGS__)(__VA_ARGS__)
#define Make_Blockchain(...) BOOST_PP_OVERLOAD(MKCHAIN, __VA_ARGS__)(__VA_ARGS__)
/**
* @brief Similar to @ref Make_Database, but works with several databases at once
* @brief Similar to @ref Make_Blockchain, but works with several chains at once
*
* Creates and opens several testing_databases
* Creates and opens several testing_blockchains
*
* Example:
* @code{.cpp}
* // Create testing_databases db1 and db2, with db2 having ID "id2"
* Make_Databases((db1)(db2, id2))
* // Create testing_blockchains chain1 and chain2, with chain2 having ID "id2"
* Make_Blockchains((chain1)(chain2, id2))
* @endcode
*/
#define Make_Databases(...) BOOST_PP_SEQ_FOR_EACH(MKDBS_MACRO, _, __VA_ARGS__)
#define Make_Blockchains(...) BOOST_PP_SEQ_FOR_EACH(MKCHAINS_MACRO, _, __VA_ARGS__)
/**
* @brief Make_Network is a shorthand way to create a testing_network and connect some testing_databases to it.
* @brief Make_Network is a shorthand way to create a testing_network and connect some testing_blockchains to it.
*
* Example usage:
* @code{.cpp}
* // Create and open testing_databases named alice, bob, and charlie
* // Create and open testing_blockchains named alice, bob, and charlie
* MKDBS((alice)(bob)(charlie))
* // Create a testing_network named net and connect alice and bob to it
* Make_Network(net, (alice)(bob))
*
* // Connect charlie to net, then disconnect alice
* net.connect_database(charlie);
* net.disconnect_database(alice);
* net.connect_blockchain(charlie);
* net.disconnect_blockchain(alice);
*
* // Create a testing_network named net2 with no databases connected
* // Create a testing_network named net2 with no blockchains connected
* Make_Network(net2)
* @endcode
*/
......@@ -309,13 +310,14 @@ protected:
* @brief Make_Account is a shorthand way to create an account
*
* Use Make_Account to create an account, including keys. The changes will be applied via a transaction applied to the
* provided database object. The changes will not be incorporated into a block; they will be left in the pending state.
* provided blockchain object. The changes will not be incorporated into a block; they will be left in the pending
* state.
*
* Unless overridden, new accounts are created with a balance of Asset(100)
*
* Example:
* @code{.cpp}
* Make_Account(db, joe)
* Make_Account(chain, joe)
* // ... creates these objects:
* private_key_type joe_private_key;
* PublicKey joe_public_key;
......@@ -325,14 +327,14 @@ protected:
*
* You may specify a third argument for the creating account:
* @code{.cpp}
* // Same as MKACCT(db, joe) except that sam will create joe's account instead of init0
* Make_Account(db, joe, sam)
* // Same as MKACCT(chain, joe) except that sam will create joe's account instead of init0
* Make_Account(chain, joe, sam)
* @endcode
*
* You may specify a fourth argument for the amount to transfer in account creation:
* @code{.cpp}
* // Same as MKACCT(db, joe, sam) except that sam will send joe ASSET(100) during creation
* Make_Account(db, joe, sam, Asset(100))
* // Same as MKACCT(chain, joe, sam) except that sam will send joe ASSET(100) during creation
* Make_Account(chain, joe, sam, Asset(100))
* @endcode
*
* You may specify a fifth argument, which will be used as the owner authority (must be an Authority, NOT a key!).
......@@ -350,13 +352,13 @@ protected:
* Use Transfer_Asset to send funds from one account to another:
* @code{.cpp}
* // Send 10 EOS from alice to bob
* Transfer_Asset(db, alice, bob, Asset(10));
* Transfer_Asset(chain, alice, bob, Asset(10));
*
* // Send 10 EOS from alice to bob with memo "Thanks for all the fish!"
* Transfer_Asset(db, alice, bob, Asset(10), "Thanks for all the fish!");
* Transfer_Asset(chain, alice, bob, Asset(10), "Thanks for all the fish!");
* @endcode
*
* The changes will be applied via a transaction applied to the provided database object. The changes will not be
* The changes will be applied via a transaction applied to the provided blockchain object. The changes will not be
* incorporated into a block; they will be left in the pending state.
*/
#define Transfer_Asset(...) BOOST_PP_OVERLOAD(XFER, __VA_ARGS__)(__VA_ARGS__)
......@@ -367,10 +369,10 @@ protected:
* Use Stake_Asset to stake liquid funds:
* @code{.cpp}
* // Convert 10 of bob's EOS from liquid to staked
* Stake_Asset(db, bob, Asset(10).amount);
* Stake_Asset(chain, bob, Asset(10).amount);
*
* // Stake and transfer 10 EOS from alice to bob (alice pays liquid EOS and bob receives stake)
* Stake_Asset(db, alice, bob, Asset(10).amount);
* Stake_Asset(chain, alice, bob, Asset(10).amount);
* @endcode
*/
#define Stake_Asset(...) BOOST_PP_OVERLOAD(STAKE, __VA_ARGS__)(__VA_ARGS__)
......@@ -381,7 +383,7 @@ protected:
* Use Unstake_Asset to begin unstaking funds:
* @code{.cpp}
* // Begin unstaking 10 of bob's EOS
* Unstake_Asset(db, bob, Asset(10).amount);
* Unstake_Asset(chain, bob, Asset(10).amount);
* @endcode
*
* This can also be used to cancel an unstaking in progress, by passing Asset(0) as the amount.
......@@ -394,7 +396,7 @@ protected:
* Use Finish_Unstake_Asset to liquidate unstaked funds:
* @code{.cpp}
* // Reclaim as liquid 10 of bob's unstaked EOS
* Unstake_Asset(db, bob, Asset(10).amount);
* Unstake_Asset(chain, bob, Asset(10).amount);
* @endcode
*/
#define Finish_Unstake_Asset(...) BOOST_PP_OVERLOAD(FINISH_UNSTAKE, __VA_ARGS__)(__VA_ARGS__)
......@@ -405,20 +407,20 @@ protected:
* Use Allow_Proxy to set whether an accound allows other accounts to proxy votes to it:
* @code{.cpp}
* // Enable proxying to bob
* Allow_Proxy(db, bob, true);
* Allow_Proxy(chain, bob, true);
*
* // Disable proxying to sam
* Allow_Proxy(db, sam, false);
* Allow_Proxy(chain, sam, false);
* @endcode
*/
#define Allow_Proxy(db, proxy, allowed) \
#define Allow_Proxy(chain, proxy, allowed) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#proxy, config::StakedBalanceContractName, vector<AccountName>{}, "AllowVoteProxying", \
types::AllowVoteProxying{bool(allowed)}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
/**
......@@ -427,13 +429,13 @@ protected:
* Use Set_Proxy to set what account a stakeholding account proxies its voting power to
* @code{.cpp}
* // Proxy sam's votes to bob
* Set_Proxy(db, sam, bob);
* Set_Proxy(chain, sam, bob);
*
* // Unproxy sam's votes
* Set_Proxy(db, sam, sam);
* Set_Proxy(chain, sam, sam);
* @endcode
*/
#define Set_Proxy(db, stakeholder, proxy) \
#define Set_Proxy(chain, stakeholder, proxy) \
{ \
eos::chain::SignedTransaction trx; \
vector<AccountName> notifies; \
......@@ -441,9 +443,9 @@ protected:
notifies.emplace_back(#proxy); \
trx.emplaceMessage(#stakeholder, config::StakedBalanceContractName, notifies, "SetVoteProxy", \
types::SetVoteProxy{#proxy}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
/**
......@@ -453,13 +455,13 @@ protected:
* @code{.cpp}
* // Create a block producer belonging to joe using signing_key as the block signing key and config as the producer's
* // vote for a @ref BlockchainConfiguration:
* Make_Producer(db, joe, signing_key, config);
* Make_Producer(chain, joe, signing_key, config);
*
* // Create a block producer belonging to joe using signing_key as the block signing key:
* Make_Producer(db, joe, signing_key);
* Make_Producer(chain, joe, signing_key);
*
* // Create a block producer belonging to joe, using a new key as the block signing key:
* Make_Producer(db, joe);
* Make_Producer(chain, joe);
* // ... creates the objects:
* private_key_type joe_producer_private_key;
* PublicKey joe_producer_public_key;
......@@ -473,9 +475,9 @@ protected:
* Use Approve_Producer to change an account's approval of a block producer:
* @code{.cpp}
* // Set joe's approval for pete's block producer to Approve
* Approve_Producer(db, joe, pete, true);
* Approve_Producer(chain, joe, pete, true);
* // Set joe's approval for pete's block producer to Disapprove
* Approve_Producer(db, joe, pete, false);
* Approve_Producer(chain, joe, pete, false);
* @endcode
*/
#define Approve_Producer(...) BOOST_PP_OVERLOAD(APPDCR, __VA_ARGS__)(__VA_ARGS__)
......@@ -494,10 +496,10 @@ protected:
* @code{.cpp}
* // Update a block producer belonging to joe using signing_key as the new block signing key, and config as the
* // producer's new vote for a @ref BlockchainConfiguration:
* Update_Producer(db, "joe", signing_key, config)
* Update_Producer(chain, "joe", signing_key, config)
*
* // Update a block producer belonging to joe using signing_key as the new block signing key:
* Update_Producer(db, "joe", signing_key)
* Update_Producer(chain, "joe", signing_key)
* @endcode
*/
#define Update_Producer(...) BOOST_PP_OVERLOAD(UPPDCR, __VA_ARGS__)(__VA_ARGS__)
......
......@@ -3,64 +3,67 @@
* should not be used directly. Use their frontends instead.
*/
#define MKDB1(name) \
#define MKCHAIN1(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; \
native_contract::native_contract_chain_initializer name ## _initializer(genesis_state()); \
testing_database name(name ## _db, name ## _fdb, name ## _log, name ## _initializer, *this);
#define MKDB2(name, id) \
testing_blockchain name(name ## _db, name ## _fdb, name ## _log, name ## _initializer, *this);
#define MKCHAIN2(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; \
native_contract::native_contract_chain_initializer name ## _initializer(genesis_state()); \
testing_database name(name ## _db, name ## _fdb, name ## _log, name ## _initializer, *this);
#define MKDBS_MACRO(x, y, name) Make_Database(name)
testing_blockchain name(name ## _db, name ## _fdb, name ## _log, name ## _initializer, *this);
#define MKCHAINS_MACRO(x, y, name) Make_Blockchain(name)
#define MKNET1(name) testing_network name;
#define MKNET2_MACRO(x, name, db) name.connect_database(db);
#define MKNET2_MACRO(x, name, chain) name.connect_blockchain(chain);
#define MKNET2(name, ...) MKNET1(name) BOOST_PP_SEQ_FOR_EACH(MKNET2_MACRO, name, __VA_ARGS__)
#define MKACCT_IMPL(db, name, creator, active, owner, recovery, deposit) \
#define MKACCT_IMPL(chain, name, creator, active, owner, recovery, deposit) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#creator, config::SystemContractName, \
vector<types::AccountName>{config::StakedBalanceContractName, \
config::EosContractName}, "CreateAccount", \
types::CreateAccount{#creator, #name, owner, active, recovery, deposit}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define MKACCT2(db, name) \
#define MKACCT2(chain, name) \
Make_Key(name) \
MKACCT_IMPL(db, name, init0, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), Account_Authority(init0), Asset(100))
#define MKACCT3(db, name, creator) \
MKACCT_IMPL(chain, name, init0, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), \
Account_Authority(init0), Asset(100))
#define MKACCT3(chain, name, creator) \
Make_Key(name) \
MKACCT_IMPL(db, name, creator, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), Account_Authority(creator), Asset(100))
#define MKACCT4(db, name, creator, deposit) \
MKACCT_IMPL(chain, name, creator, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), \
Account_Authority(creator), Asset(100))
#define MKACCT4(chain, name, creator, deposit) \
Make_Key(name) \
MKACCT_IMPL(db, name, creator, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), Account_Authority(creator), deposit)
#define MKACCT5(db, name, creator, deposit, owner) \
MKACCT_IMPL(chain, name, creator, Key_Authority(name ## _public_key), Key_Authority(name ## _public_key), \
Account_Authority(creator), deposit)
#define MKACCT5(chain, name, creator, deposit, owner) \
Make_Key(name) \
MKACCT_IMPL(db, name, creator, owner, Key_Authority(name ## _public_key), Account_Authority(creator), deposit)
#define MKACCT6(db, name, creator, deposit, owner, active) \
MKACCT_IMPL(db, name, creator, owner, active, Account_Authority(creator), deposit)
#define MKACCT7(db, name, creator, deposit, owner, active, recovery) \
MKACCT_IMPL(db, name, creator, owner, active, recovery, deposit)
MKACCT_IMPL(chain, name, creator, owner, Key_Authority(name ## _public_key), Account_Authority(creator), deposit)
#define MKACCT6(chain, name, creator, deposit, owner, active) \
MKACCT_IMPL(chain, name, creator, owner, active, Account_Authority(creator), deposit)
#define MKACCT7(chain, name, creator, deposit, owner, active, recovery) \
MKACCT_IMPL(chain, name, creator, owner, active, recovery, deposit)
#define XFER5(db, sender, recipient, amount, memo) \
#define XFER5(chain, sender, recipient, amount, memo) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#sender, config::EosContractName, vector<AccountName>{#recipient}, "Transfer", \
types::Transfer{#sender, #recipient, amount, memo}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define XFER4(db, sender, recipient, amount) XFER5(db, sender, recipient, amount, "")
#define XFER4(chain, sender, recipient, amount) XFER5(chain, sender, recipient, amount, "")
#define STAKE4(db, sender, recipient, amount) \
#define STAKE4(chain, sender, recipient, amount) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#sender, config::EosContractName, vector<AccountName>{config::StakedBalanceContractName}, \
......@@ -69,63 +72,63 @@
trx.messages.front().notify.emplace_back(#recipient); \
boost::sort(trx.messages.front().notify); \
} \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define STAKE3(db, account, amount) STAKE4(db, account, account, amount)
#define STAKE3(chain, account, amount) STAKE4(chain, account, account, amount)
#define BEGIN_UNSTAKE3(db, account, amount) \
#define BEGIN_UNSTAKE3(chain, account, amount) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#account, config::StakedBalanceContractName, vector<AccountName>{}, \
"StartUnlockEos", types::StartUnlockEos{#account, amount}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define FINISH_UNSTAKE3(db, account, amount) \
#define FINISH_UNSTAKE3(chain, account, amount) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#account, config::StakedBalanceContractName, vector<AccountName>{config::EosContractName}, \
"ClaimUnlockedEos", types::ClaimUnlockedEos{#account, amount}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define MKPDCR4(db, owner, key, cfg) \
#define MKPDCR4(chain, owner, key, cfg) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#owner, config::StakedBalanceContractName, vector<AccountName>{}, "CreateProducer", \
types::CreateProducer{#owner, key, cfg}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define MKPDCR3(db, owner, key) MKPDCR4(db, owner, key, BlockchainConfiguration{});
#define MKPDCR2(db, owner) \
#define MKPDCR3(chain, owner, key) MKPDCR4(chain, owner, key, BlockchainConfiguration{});
#define MKPDCR2(chain, owner) \
Make_Key(owner ## _producer); \
MKPDCR4(db, owner, owner ## _producer_public_key, BlockchainConfiguration{});
MKPDCR4(chain, owner, owner ## _producer_public_key, BlockchainConfiguration{});
#define APPDCR4(db, voter, producer, approved) \
#define APPDCR4(chain, voter, producer, approved) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(#voter, config::StakedBalanceContractName, vector<AccountName>{}, "ApproveProducer", \
types::ApproveProducer{#producer, approved? 1 : 0}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define UPPDCR4(db, owner, key, cfg) \
#define UPPDCR4(chain, owner, key, cfg) \
{ \
eos::chain::SignedTransaction trx; \
trx.emplaceMessage(owner, config::StakedBalanceContractName, vector<AccountName>{}, "UpdateProducer", \
types::UpdateProducer{owner, key, cfg}); \
trx.expiration = db.head_block_time() + 100; \
trx.set_reference_block(db.head_block_id()); \
db.push_transaction(trx); \
trx.expiration = chain.head_block_time() + 100; \
trx.set_reference_block(chain.head_block_id()); \
chain.push_transaction(trx); \
}
#define UPPDCR3(db, owner, key) UPPDCR4(db, owner, key, db.get_producer(owner).configuration)
#define UPPDCR3(chain, owner, key) UPPDCR4(chain, owner, key, chain.get_producer(owner).configuration)
此差异已折叠。
......@@ -64,27 +64,27 @@ BOOST_FIXTURE_TEST_CASE(undo_test, testing_fixture)
// Test the block fetching methods on database, get_block_id_for_num, fetch_bock_by_id, and fetch_block_by_number
BOOST_FIXTURE_TEST_CASE(get_blocks, testing_fixture)
{ try {
Make_Database(db)
Make_Blockchain(chain)
vector<block_id_type> block_ids;
// Produce 20 blocks and check their IDs should match the above
db.produce_blocks(20);
chain.produce_blocks(20);
for (int i = 0; i < 20; ++i) {
block_ids.emplace_back(db.fetch_block_by_number(i+1)->id());
block_ids.emplace_back(chain.fetch_block_by_number(i+1)->id());
BOOST_CHECK_EQUAL(block_header::num_from_id(block_ids.back()), i+1);
BOOST_CHECK_EQUAL(db.get_block_id_for_num(i+1), block_ids.back());
BOOST_CHECK_EQUAL(db.fetch_block_by_number(i+1)->id(), block_ids.back());
BOOST_CHECK_EQUAL(chain.get_block_id_for_num(i+1), block_ids.back());
BOOST_CHECK_EQUAL(chain.fetch_block_by_number(i+1)->id(), block_ids.back());
}
// Check the last irreversible block number is set correctly
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 6);
BOOST_CHECK_EQUAL(chain.last_irreversible_block_num(), 6);
// Check that block 21 cannot be found (only 20 blocks exist)
BOOST_CHECK_THROW(db.get_block_id_for_num(21), eos::chain::unknown_block_exception);
BOOST_CHECK_THROW(chain.get_block_id_for_num(21), eos::chain::unknown_block_exception);
db.produce_blocks();
chain.produce_blocks();
// Check the last irreversible block number is updated correctly
BOOST_CHECK_EQUAL(db.last_irreversible_block_num(), 7);
BOOST_CHECK_EQUAL(chain.last_irreversible_block_num(), 7);
// Check that block 21 can now be found
BOOST_CHECK_EQUAL(db.get_block_id_for_num(21), db.head_block_id());
BOOST_CHECK_EQUAL(chain.get_block_id_for_num(21), chain.head_block_id());
} FC_LOG_AND_RETHROW() }
} // namespace eos
......@@ -26,25 +26,26 @@ BOOST_AUTO_TEST_SUITE(system_contract_tests)
//Simple test of account creation
BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
{ try {
Make_Database(db);
db.produce_blocks(10);
Make_Blockchain(chain);
chain.produce_blocks(10);
BOOST_CHECK_EQUAL(db.get_liquid_balance("init1"), Asset(100000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init1"), Asset(100000));
Make_Account(db, joe, init1, Asset(1000));
Make_Account(chain, joe, init1, Asset(1000));
{ // test in the pending state
BOOST_CHECK_EQUAL(db.get_liquid_balance("joe"), Asset(1000));
BOOST_CHECK_EQUAL(db.get_liquid_balance("init1"), Asset(100000 - 1000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("joe"), Asset(1000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init1"), Asset(100000 - 1000));
const auto& joe_owner_authority = db_db.get<permission_object, by_owner>(boost::make_tuple("joe", "owner"));
const auto& joe_owner_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple("joe", "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_db.get<permission_object, by_owner>(boost::make_tuple("joe", "active"));
const auto& joe_active_authority =
chain_db.get<permission_object, by_owner>(boost::make_tuple("joe", "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);
......@@ -52,19 +53,20 @@ BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
BOOST_CHECK_EQUAL(joe_active_authority.auth.keys[0].weight, 1);
}
db.produce_blocks(1); /// verify changes survived creating a new block
chain.produce_blocks(1); /// verify changes survived creating a new block
{
BOOST_CHECK_EQUAL(db.get_liquid_balance("joe"), Asset(1000));
BOOST_CHECK_EQUAL(db.get_liquid_balance("init1"), Asset(100000 - 1000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("joe"), Asset(1000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init1"), Asset(100000 - 1000));
const auto& joe_owner_authority = db_db.get<permission_object, by_owner>(boost::make_tuple("joe", "owner"));
const auto& joe_owner_authority = chain_db.get<permission_object, by_owner>(boost::make_tuple("joe", "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_db.get<permission_object, by_owner>(boost::make_tuple("joe", "active"));
const auto& joe_active_authority =
chain_db.get<permission_object, by_owner>(boost::make_tuple("joe", "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);
......@@ -76,17 +78,17 @@ BOOST_FIXTURE_TEST_CASE(create_account, testing_fixture)
// Simple test to verify a simple transfer transaction works
BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
{ try {
Make_Database(db)
Make_Blockchain(chain)
BOOST_CHECK_EQUAL(db.head_block_num(), 0);
db.produce_blocks(10);
BOOST_CHECK_EQUAL(db.head_block_num(), 10);
BOOST_CHECK_EQUAL(chain.head_block_num(), 0);
chain.produce_blocks(10);
BOOST_CHECK_EQUAL(chain.head_block_num(), 10);
SignedTransaction trx;
BOOST_REQUIRE_THROW(db.push_transaction(trx), transaction_exception); // no messages
BOOST_REQUIRE_THROW(chain.push_transaction(trx), transaction_exception); // no messages
trx.messages.resize(1);
trx.set_reference_block(db.head_block_id());
trx.expiration = db.head_block_time() + 100;
trx.set_reference_block(chain.head_block_id());
trx.expiration = chain.head_block_time() + 100;
trx.messages[0].sender = "init1";
trx.messages[0].recipient = config::EosContractName;
......@@ -101,53 +103,53 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
auto unpack_trans = trx.messageAs<types::Transfer>(0);
BOOST_REQUIRE_THROW(db.push_transaction(trx), message_validate_exception); // "fail to notify receiver, init2"
BOOST_REQUIRE_THROW(chain.push_transaction(trx), message_validate_exception); // "fail to notify receiver, init2"
trx.messages[0].notify = {"init2"};
trx.setMessage(0, "Transfer", trans);
db.push_transaction(trx);
chain.push_transaction(trx);
BOOST_CHECK_EQUAL(db.get_liquid_balance("init1"), Asset(100000 - 100));
BOOST_CHECK_EQUAL(db.get_liquid_balance("init2"), Asset(100000 + 100));
db.produce_blocks(1);
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init1"), Asset(100000 - 100));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init2"), Asset(100000 + 100));
chain.produce_blocks(1);
BOOST_REQUIRE_THROW(db.push_transaction(trx), transaction_exception); // not unique
BOOST_REQUIRE_THROW(chain.push_transaction(trx), transaction_exception); // not unique
Transfer_Asset(db, init2, init1, Asset(100));
BOOST_CHECK_EQUAL(db.get_liquid_balance("init1"), Asset(100000));
BOOST_CHECK_EQUAL(db.get_liquid_balance("init2"), Asset(100000));
Transfer_Asset(chain, init2, init1, Asset(100));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init1"), Asset(100000));
BOOST_CHECK_EQUAL(chain.get_liquid_balance("init2"), 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)
db.produce_blocks();
BOOST_CHECK_EQUAL(db.head_block_num(), 1);
Make_Blockchain(chain)
chain.produce_blocks();
BOOST_CHECK_EQUAL(chain.head_block_num(), 1);
Make_Account(db, producer);
Make_Producer(db, producer, producer_public_key);
Make_Account(chain, producer);
Make_Producer(chain, producer, producer_public_key);
while (db.head_block_num() < 3) {
auto& producer = db.get_producer("producer");
BOOST_CHECK_EQUAL(db.get_producer(producer.owner).owner, "producer");
while (chain.head_block_num() < 3) {
auto& producer = chain.get_producer("producer");
BOOST_CHECK_EQUAL(chain.get_producer(producer.owner).owner, "producer");
BOOST_CHECK_EQUAL(producer.signing_key, producer_public_key);
BOOST_CHECK_EQUAL(producer.last_aslot, 0);
BOOST_CHECK_EQUAL(producer.total_missed, 0);
BOOST_CHECK_EQUAL(producer.last_confirmed_block_num, 0);
db.produce_blocks();
chain.produce_blocks();
}
Make_Key(signing);
Update_Producer(db, "producer", signing_public_key);
auto& producer = db.get_producer("producer");
Update_Producer(chain, "producer", signing_public_key);
auto& producer = chain.get_producer("producer");
BOOST_CHECK_EQUAL(producer.signing_key, signing_public_key);
} FC_LOG_AND_RETHROW() }
// Test producer votes on blockchain parameters in full blockchain context
BOOST_FIXTURE_TEST_CASE(producer_voting_parameters, testing_fixture)
{ try {
Make_Database(db)
db.produce_blocks(21);
Make_Blockchain(chain)
chain.produce_blocks(21);
vector<BlockchainConfiguration> votes{
{1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 },
......@@ -179,21 +181,21 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters, testing_fixture)
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(chain, name, chain.get_producer(name).signing_key, votes[i]);
}
BOOST_CHECK_NE(db.get_global_properties().configuration, medians);
db.produce_blocks(20);
BOOST_CHECK_NE(db.get_global_properties().configuration, medians);
db.produce_blocks();
BOOST_CHECK_EQUAL(db.get_global_properties().configuration, medians);
BOOST_CHECK_NE(chain.get_global_properties().configuration, medians);
chain.produce_blocks(20);
BOOST_CHECK_NE(chain.get_global_properties().configuration, medians);
chain.produce_blocks();
BOOST_CHECK_EQUAL(chain.get_global_properties().configuration, medians);
} FC_LOG_AND_RETHROW() }
// Test producer votes on blockchain parameters in full blockchain context, with missed blocks
BOOST_FIXTURE_TEST_CASE(producer_voting_parameters_2, testing_fixture)
{ try {
Make_Database(db)
db.produce_blocks(21);
Make_Blockchain(chain)
chain.produce_blocks(21);
vector<BlockchainConfiguration> votes{
{1024 , 512 , 4096 , Asset(5000 ).amount, Asset(4000 ).amount, Asset(100 ).amount, 512 },
......@@ -225,50 +227,50 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_parameters_2, testing_fixture)
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(chain, name, chain.get_producer(name).signing_key, votes[i]);
}
BOOST_CHECK_NE(db.get_global_properties().configuration, medians);
db.produce_blocks(2);
db.produce_blocks(18, 5);
BOOST_CHECK_NE(db.get_global_properties().configuration, medians);
db.produce_blocks();
BOOST_CHECK_EQUAL(db.get_global_properties().configuration, medians);
BOOST_CHECK_NE(chain.get_global_properties().configuration, medians);
chain.produce_blocks(2);
chain.produce_blocks(18, 5);
BOOST_CHECK_NE(chain.get_global_properties().configuration, medians);
chain.produce_blocks();
BOOST_CHECK_EQUAL(chain.get_global_properties().configuration, medians);
} 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) {
try {
Make_Database(db)
db.produce_blocks();
Make_Account(db, joe);
Make_Account(db, bob);
Stake_Asset(db, bob, Asset(100).amount);
Make_Producer(db, joe);
Approve_Producer(db, bob, joe, true);
Make_Blockchain(chain)
chain.produce_blocks();
Make_Account(chain, joe);
Make_Account(chain, bob);
Stake_Asset(chain, bob, Asset(100).amount);
Make_Producer(chain, joe);
Approve_Producer(chain, bob, joe, true);
// Produce blocks up to, but not including, the last block in the round
db.produce_blocks(config::BlocksPerRound - db.head_block_num() - 1);
chain.produce_blocks(config::BlocksPerRound - chain.head_block_num() - 1);
{
BOOST_CHECK_EQUAL(db.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(db.get_staked_balance("bob"), Asset(100));
const auto& joeVotes = db_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), db.get_staked_balance("bob"));
BOOST_CHECK_EQUAL(chain.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(chain.get_staked_balance("bob"), Asset(100));
const auto& joeVotes = chain_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), chain.get_staked_balance("bob"));
}
// OK, let's go to the next round
db.produce_blocks();
chain.produce_blocks();
const auto& gpo = db.get_global_properties();
const auto& gpo = chain.get_global_properties();
BOOST_REQUIRE(boost::find(gpo.active_producers, "joe") != gpo.active_producers.end());
Approve_Producer(db, bob, joe, false);
db.produce_blocks();
Approve_Producer(chain, bob, joe, false);
chain.produce_blocks();
{
BOOST_CHECK_EQUAL(db.get_approved_producers("bob").count("joe"), 0);
const auto& joeVotes = db_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(chain.get_approved_producers("bob").count("joe"), 0);
const auto& joeVotes = chain_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), 0);
}
} FC_LOG_AND_RETHROW()
......@@ -277,45 +279,45 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_1, testing_fixture) {
// 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) {
try {
Make_Database(db)
db.produce_blocks();
Make_Blockchain(chain)
chain.produce_blocks();
Make_Account(db, joe);
Make_Account(db, bob);
Make_Producer(db, joe);
Approve_Producer(db, bob, joe, true);
db.produce_blocks();
Make_Account(chain, joe);
Make_Account(chain, bob);
Make_Producer(chain, joe);
Approve_Producer(chain, bob, joe, true);
chain.produce_blocks();
{
BOOST_CHECK_EQUAL(db.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(db.get_staked_balance("bob"), Asset(0));
const auto& joeVotes = db_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), db.get_staked_balance("bob"));
BOOST_CHECK_EQUAL(chain.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(chain.get_staked_balance("bob"), Asset(0));
const auto& joeVotes = chain_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), chain.get_staked_balance("bob"));
}
Stake_Asset(db, bob, Asset(100).amount);
Stake_Asset(chain, bob, Asset(100).amount);
// Produce blocks up to, but not including, the last block in the round
db.produce_blocks(config::BlocksPerRound - db.head_block_num() - 1);
chain.produce_blocks(config::BlocksPerRound - chain.head_block_num() - 1);
{
BOOST_CHECK_EQUAL(db.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(db.get_staked_balance("bob"), Asset(100));
const auto& joeVotes = db_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), db.get_staked_balance("bob"));
BOOST_CHECK_EQUAL(chain.get_approved_producers("bob").count("joe"), 1);
BOOST_CHECK_EQUAL(chain.get_staked_balance("bob"), Asset(100));
const auto& joeVotes = chain_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), chain.get_staked_balance("bob"));
}
// OK, let's go to the next round
db.produce_blocks();
chain.produce_blocks();
const auto& gpo = db.get_global_properties();
const auto& gpo = chain.get_global_properties();
BOOST_REQUIRE(boost::find(gpo.active_producers, "joe") != gpo.active_producers.end());
Approve_Producer(db, bob, joe, false);
db.produce_blocks();
Approve_Producer(chain, bob, joe, false);
chain.produce_blocks();
{
BOOST_CHECK_EQUAL(db.get_approved_producers("bob").count("joe"), 0);
const auto& joeVotes = db_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(chain.get_approved_producers("bob").count("joe"), 0);
const auto& joeVotes = chain_db.get<ProducerVotesObject, byOwnerName>("joe");
BOOST_CHECK_EQUAL(joeVotes.getVotes(), 0);
}
} FC_LOG_AND_RETHROW()
......@@ -324,53 +326,54 @@ BOOST_FIXTURE_TEST_CASE(producer_voting_2, testing_fixture) {
// Test voting for producers by proxy
BOOST_FIXTURE_TEST_CASE(producer_proxy_voting, testing_fixture) {
try {
using Action = std::function<void(testing_database&)>;
Action approve = [](auto& db) {
Approve_Producer(db, proxy, producer, true);
using Action = std::function<void(testing_blockchain&)>;
Action approve = [](auto& chain) {
Approve_Producer(chain, proxy, producer, true);
};
Action setproxy = [](auto& db) {
Set_Proxy(db, stakeholder, proxy);
Action setproxy = [](auto& chain) {
Set_Proxy(chain, stakeholder, proxy);
};
Action allowproxy = [](auto& db) {
Allow_Proxy(db, proxy, true);
Action allowproxy = [](auto& chain) {
Allow_Proxy(chain, proxy, true);
};
Action stake = [](auto& db) {
Stake_Asset(db, stakeholder, Asset(100).amount);
Action stake = [](auto& chain) {
Stake_Asset(chain, stakeholder, Asset(100).amount);
};
auto run = [this](std::vector<Action> actions) {
Make_Database(db)
db.produce_blocks();
Make_Blockchain(chain)
chain.produce_blocks();
Make_Account(db, stakeholder);
Make_Account(db, proxy);
Make_Account(db, producer);
Make_Producer(db, producer);
Make_Account(chain, stakeholder);
Make_Account(chain, proxy);
Make_Account(chain, producer);
Make_Producer(chain, producer);
for (auto& action : actions) action(db);
for (auto& action : actions)
action(chain);
// Produce blocks up to, but not including, the last block in the round
db.produce_blocks(config::BlocksPerRound - db.head_block_num() - 1);
chain.produce_blocks(config::BlocksPerRound - chain.head_block_num() - 1);
{
BOOST_CHECK_EQUAL(db.get_approved_producers("proxy").count("producer"), 1);
BOOST_CHECK_EQUAL(db.get_staked_balance("stakeholder"), Asset(100));
const auto& producerVotes = db_db.get<ProducerVotesObject, byOwnerName>("producer");
BOOST_CHECK_EQUAL(producerVotes.getVotes(), db.get_staked_balance("stakeholder"));
BOOST_CHECK_EQUAL(chain.get_approved_producers("proxy").count("producer"), 1);
BOOST_CHECK_EQUAL(chain.get_staked_balance("stakeholder"), Asset(100));
const auto& producerVotes = chain_db.get<ProducerVotesObject, byOwnerName>("producer");
BOOST_CHECK_EQUAL(producerVotes.getVotes(), chain.get_staked_balance("stakeholder"));
}
// OK, let's go to the next round
db.produce_blocks();
chain.produce_blocks();
const auto& gpo = db.get_global_properties();
const auto& gpo = chain.get_global_properties();
BOOST_REQUIRE(boost::find(gpo.active_producers, "producer") != gpo.active_producers.end());
Approve_Producer(db, proxy, producer, false);
db.produce_blocks();
Approve_Producer(chain, proxy, producer, false);
chain.produce_blocks();
{
BOOST_CHECK_EQUAL(db.get_approved_producers("proxy").count("producer"), 0);
const auto& producerVotes = db_db.get<ProducerVotesObject, byOwnerName>("producer");
BOOST_CHECK_EQUAL(chain.get_approved_producers("proxy").count("producer"), 0);
const auto& producerVotes = chain_db.get<ProducerVotesObject, byOwnerName>("producer");
BOOST_CHECK_EQUAL(producerVotes.getVotes(), 0);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册