2015-06-08 15:50:35 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-06-08 15:50:35 +00:00
|
|
|
*/
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
|
|
|
|
|
#include <graphene/account_history/account_history_plugin.hpp>
|
2015-06-24 18:01:37 +00:00
|
|
|
#include <graphene/market_history/market_history_plugin.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
#include <graphene/db/simple_index.hpp>
|
|
|
|
|
|
|
|
|
|
#include <graphene/chain/account_object.hpp>
|
|
|
|
|
#include <graphene/chain/asset_object.hpp>
|
2015-07-13 20:06:02 +00:00
|
|
|
#include <graphene/chain/committee_member_object.hpp>
|
2016-02-15 19:58:01 +00:00
|
|
|
#include <graphene/chain/fba_object.hpp>
|
2016-01-08 15:37:22 +00:00
|
|
|
#include <graphene/chain/market_object.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <graphene/chain/vesting_balance_object.hpp>
|
|
|
|
|
#include <graphene/chain/witness_object.hpp>
|
|
|
|
|
|
2015-07-13 18:56:29 +00:00
|
|
|
#include <graphene/utilities/tempdir.hpp>
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <fc/crypto/digest.hpp>
|
2015-07-09 12:22:04 +00:00
|
|
|
#include <fc/smart_ref_impl.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include "database_fixture.hpp"
|
|
|
|
|
|
2015-07-23 19:11:55 +00:00
|
|
|
using namespace graphene::chain::test;
|
|
|
|
|
|
2015-10-30 23:12:05 +00:00
|
|
|
uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000;
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
namespace graphene { namespace chain {
|
|
|
|
|
|
|
|
|
|
using std::cout;
|
2015-06-18 22:42:44 +00:00
|
|
|
using std::cerr;
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
database_fixture::database_fixture()
|
|
|
|
|
: app(), db( *app.chain_database() )
|
|
|
|
|
{
|
2015-06-24 18:01:37 +00:00
|
|
|
try {
|
2015-07-08 16:14:54 +00:00
|
|
|
int argc = boost::unit_test::framework::master_test_suite().argc;
|
|
|
|
|
char** argv = boost::unit_test::framework::master_test_suite().argv;
|
|
|
|
|
for( int i=1; i<argc; i++ )
|
|
|
|
|
{
|
|
|
|
|
const std::string arg = argv[i];
|
|
|
|
|
if( arg == "--record-assert-trip" )
|
|
|
|
|
fc::enable_record_assert_trip = true;
|
|
|
|
|
if( arg == "--show-test-names" )
|
|
|
|
|
std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
auto ahplugin = app.register_plugin<graphene::account_history::account_history_plugin>();
|
2015-06-24 18:01:37 +00:00
|
|
|
auto mhplugin = app.register_plugin<graphene::market_history::market_history_plugin>();
|
2015-07-13 19:41:50 +00:00
|
|
|
init_account_pub_key = init_account_priv_key.get_public_key();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
boost::program_options::variables_map options;
|
|
|
|
|
|
2015-07-07 19:37:31 +00:00
|
|
|
genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
|
|
|
|
|
|
2015-07-06 18:14:15 +00:00
|
|
|
genesis_state.initial_active_witnesses = 10;
|
|
|
|
|
for( int i = 0; i < genesis_state.initial_active_witnesses; ++i )
|
2015-06-18 13:19:14 +00:00
|
|
|
{
|
2015-06-18 19:02:42 +00:00
|
|
|
auto name = "init"+fc::to_string(i);
|
2015-06-30 20:42:41 +00:00
|
|
|
genesis_state.initial_accounts.emplace_back(name,
|
2015-07-13 19:41:50 +00:00
|
|
|
init_account_priv_key.get_public_key(),
|
|
|
|
|
init_account_priv_key.get_public_key(),
|
2015-06-30 20:42:41 +00:00
|
|
|
true);
|
2015-07-01 21:18:49 +00:00
|
|
|
genesis_state.initial_committee_candidates.push_back({name});
|
2015-07-13 19:41:50 +00:00
|
|
|
genesis_state.initial_witness_candidates.push_back({name, init_account_priv_key.get_public_key()});
|
2015-06-18 13:19:14 +00:00
|
|
|
}
|
2015-07-09 12:22:04 +00:00
|
|
|
genesis_state.initial_parameters.current_fees->zero_all_fees();
|
2015-09-28 14:50:12 +00:00
|
|
|
open_database();
|
|
|
|
|
|
|
|
|
|
// app.initialize();
|
|
|
|
|
ahplugin->plugin_set_app(&app);
|
|
|
|
|
ahplugin->plugin_initialize(options);
|
|
|
|
|
mhplugin->plugin_set_app(&app);
|
|
|
|
|
mhplugin->plugin_initialize(options);
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
ahplugin->plugin_startup();
|
2015-06-24 18:01:37 +00:00
|
|
|
mhplugin->plugin_startup();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
generate_block();
|
|
|
|
|
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-24 18:01:37 +00:00
|
|
|
} catch ( const fc::exception& e )
|
|
|
|
|
{
|
|
|
|
|
edump( (e.to_detail_string()) );
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
database_fixture::~database_fixture()
|
2015-06-30 19:11:26 +00:00
|
|
|
{ try {
|
2015-06-19 17:43:39 +00:00
|
|
|
// If we're unwinding due to an exception, don't do any more checks.
|
|
|
|
|
// This way, boost test's last checkpoint tells us approximately where the error was.
|
2015-06-08 15:50:35 +00:00
|
|
|
if( !std::uncaught_exception() )
|
|
|
|
|
{
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-08 15:50:35 +00:00
|
|
|
verify_account_history_plugin_index();
|
2015-06-19 17:43:39 +00:00
|
|
|
BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing );
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( data_dir )
|
|
|
|
|
db.close();
|
|
|
|
|
return;
|
2015-06-30 19:11:26 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW() }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
fc::ecc::private_key database_fixture::generate_private_key(string seed)
|
|
|
|
|
{
|
2015-07-13 19:19:36 +00:00
|
|
|
static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
|
2015-06-18 13:19:14 +00:00
|
|
|
if( seed == "null_key" )
|
2015-07-13 19:19:36 +00:00
|
|
|
return committee;
|
2015-06-08 15:50:35 +00:00
|
|
|
return fc::ecc::private_key::regenerate(fc::sha256::hash(seed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string database_fixture::generate_anon_acct_name()
|
|
|
|
|
{
|
|
|
|
|
// names of the form "anon-acct-x123" ; the "x" is necessary
|
|
|
|
|
// to workaround issue #46
|
|
|
|
|
return "anon-acct-x" + std::to_string( anon_acct_count++ );
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 21:10:19 +00:00
|
|
|
void database_fixture::verify_asset_supplies( const database& db )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-06-18 19:17:48 +00:00
|
|
|
//wlog("*** Begin asset supply verification ***");
|
2015-06-08 15:50:35 +00:00
|
|
|
const asset_dynamic_data_object& core_asset_data = db.get_core_asset().dynamic_asset_data_id(db);
|
|
|
|
|
BOOST_CHECK(core_asset_data.fee_pool == 0);
|
|
|
|
|
|
|
|
|
|
const simple_index<account_statistics_object>& statistics_index = db.get_index_type<simple_index<account_statistics_object>>();
|
|
|
|
|
const auto& balance_index = db.get_index_type<account_balance_index>().indices();
|
|
|
|
|
const auto& settle_index = db.get_index_type<force_settlement_index>().indices();
|
|
|
|
|
map<asset_id_type,share_type> total_balances;
|
|
|
|
|
map<asset_id_type,share_type> total_debts;
|
|
|
|
|
share_type core_in_orders;
|
|
|
|
|
share_type reported_core_in_orders;
|
|
|
|
|
|
|
|
|
|
for( const account_balance_object& b : balance_index )
|
|
|
|
|
total_balances[b.asset_type] += b.balance;
|
|
|
|
|
for( const force_settlement_object& s : settle_index )
|
|
|
|
|
total_balances[s.balance.asset_id] += s.balance.amount;
|
|
|
|
|
for( const account_statistics_object& a : statistics_index )
|
|
|
|
|
{
|
|
|
|
|
reported_core_in_orders += a.total_core_in_orders;
|
2015-06-11 17:54:42 +00:00
|
|
|
total_balances[asset_id_type()] += a.pending_fees + a.pending_vested_fees;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
for( const limit_order_object& o : db.get_index_type<limit_order_index>().indices() )
|
|
|
|
|
{
|
|
|
|
|
asset for_sale = o.amount_for_sale();
|
|
|
|
|
if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount;
|
|
|
|
|
total_balances[for_sale.asset_id] += for_sale.amount;
|
2015-12-03 20:48:52 +00:00
|
|
|
total_balances[asset_id_type()] += o.deferred_fee;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
for( const call_order_object& o : db.get_index_type<call_order_index>().indices() )
|
|
|
|
|
{
|
|
|
|
|
asset col = o.get_collateral();
|
|
|
|
|
if( col.asset_id == asset_id_type() ) core_in_orders += col.amount;
|
|
|
|
|
total_balances[col.asset_id] += col.amount;
|
|
|
|
|
total_debts[o.get_debt().asset_id] += o.get_debt().amount;
|
|
|
|
|
}
|
|
|
|
|
for( const asset_object& asset_obj : db.get_index_type<asset_index>().indices() )
|
|
|
|
|
{
|
|
|
|
|
total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees;
|
|
|
|
|
if( asset_obj.id != asset_id_type() )
|
|
|
|
|
BOOST_CHECK_EQUAL(total_balances[asset_obj.id].value, asset_obj.dynamic_asset_data_id(db).current_supply.value);
|
|
|
|
|
total_balances[asset_id_type()] += asset_obj.dynamic_asset_data_id(db).fee_pool;
|
2015-06-19 18:47:42 +00:00
|
|
|
if( asset_obj.is_market_issued() )
|
|
|
|
|
{
|
|
|
|
|
const auto& bad = asset_obj.bitasset_data(db);
|
|
|
|
|
total_balances[bad.options.short_backing_asset] += bad.settlement_fund;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
2015-07-17 05:32:52 +00:00
|
|
|
for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() )
|
2015-06-08 15:50:35 +00:00
|
|
|
total_balances[ vbo.balance.asset_id ] += vbo.balance.amount;
|
2016-02-15 19:58:01 +00:00
|
|
|
for( const fba_accumulator_object& fba : db.get_index_type< simple_index< fba_accumulator_object > >() )
|
|
|
|
|
total_balances[ asset_id_type() ] += fba.accumulated_fba_fees;
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget;
|
|
|
|
|
|
|
|
|
|
for( const auto& item : total_debts )
|
|
|
|
|
{
|
|
|
|
|
BOOST_CHECK_EQUAL(item.first(db).dynamic_asset_data_id(db).current_supply.value, item.second.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( core_in_orders.value , reported_core_in_orders.value );
|
2015-07-22 18:45:13 +00:00
|
|
|
BOOST_CHECK_EQUAL( total_balances[asset_id_type()].value , core_asset_data.current_supply.value - core_asset_data.confidential_supply.value);
|
2015-06-18 19:17:48 +00:00
|
|
|
// wlog("*** End asset supply verification ***");
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::verify_account_history_plugin_index( )const
|
|
|
|
|
{
|
2015-06-24 20:38:56 +00:00
|
|
|
return;
|
2015-06-08 15:50:35 +00:00
|
|
|
if( skip_key_index_test )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const std::shared_ptr<graphene::account_history::account_history_plugin> pin =
|
2015-06-18 19:02:42 +00:00
|
|
|
app.get_plugin<graphene::account_history::account_history_plugin>("account_history");
|
2015-06-08 15:50:35 +00:00
|
|
|
if( pin->tracked_accounts().size() == 0 )
|
|
|
|
|
{
|
2015-07-02 05:52:45 +00:00
|
|
|
/*
|
2015-06-08 15:50:35 +00:00
|
|
|
vector< pair< account_id_type, address > > tuples_from_db;
|
|
|
|
|
const auto& primary_account_idx = db.get_index_type<account_index>().indices().get<by_id>();
|
2015-07-02 05:52:45 +00:00
|
|
|
flat_set< public_key_type > acct_addresses;
|
2015-06-08 15:50:35 +00:00
|
|
|
acct_addresses.reserve( 2 * GRAPHENE_DEFAULT_MAX_AUTHORITY_MEMBERSHIP + 2 );
|
|
|
|
|
|
|
|
|
|
for( const account_object& acct : primary_account_idx )
|
|
|
|
|
{
|
|
|
|
|
account_id_type account_id = acct.id;
|
|
|
|
|
acct_addresses.clear();
|
2015-07-02 05:52:45 +00:00
|
|
|
for( const pair< account_id_type, weight_type >& auth : acct.owner.account_auths )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
if( auth.first.type() == key_object_type )
|
2015-07-02 05:52:45 +00:00
|
|
|
acct_addresses.insert( auth.first );
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
for( const pair< object_id_type, weight_type >& auth : acct.active.auths )
|
|
|
|
|
{
|
|
|
|
|
if( auth.first.type() == key_object_type )
|
2015-07-02 05:52:45 +00:00
|
|
|
acct_addresses.insert( auth.first );
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
2015-06-16 18:42:02 +00:00
|
|
|
acct_addresses.insert( acct.options.get_memo_key()(db).key_address() );
|
2015-06-08 15:50:35 +00:00
|
|
|
for( const address& addr : acct_addresses )
|
|
|
|
|
tuples_from_db.emplace_back( account_id, addr );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector< pair< account_id_type, address > > tuples_from_index;
|
|
|
|
|
tuples_from_index.reserve( tuples_from_db.size() );
|
|
|
|
|
const auto& key_account_idx =
|
|
|
|
|
db.get_index_type<graphene::account_history::key_account_index>()
|
|
|
|
|
.indices().get<graphene::account_history::by_key>();
|
|
|
|
|
|
|
|
|
|
for( const graphene::account_history::key_account_object& key_account : key_account_idx )
|
|
|
|
|
{
|
|
|
|
|
address addr = key_account.key;
|
|
|
|
|
for( const account_id_type& account_id : key_account.account_ids )
|
|
|
|
|
tuples_from_index.emplace_back( account_id, addr );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: use function for common functionality
|
|
|
|
|
{
|
|
|
|
|
// due to hashed index, account_id's may not be in sorted order...
|
|
|
|
|
std::sort( tuples_from_db.begin(), tuples_from_db.end() );
|
|
|
|
|
size_t size_before_uniq = tuples_from_db.size();
|
|
|
|
|
auto last = std::unique( tuples_from_db.begin(), tuples_from_db.end() );
|
|
|
|
|
tuples_from_db.erase( last, tuples_from_db.end() );
|
|
|
|
|
// but they should be unique (multiple instances of the same
|
|
|
|
|
// address within an account should have been de-duplicated
|
|
|
|
|
// by the flat_set above)
|
|
|
|
|
BOOST_CHECK( tuples_from_db.size() == size_before_uniq );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// (address, account) should be de-duplicated by flat_set<>
|
|
|
|
|
// in key_account_object
|
|
|
|
|
std::sort( tuples_from_index.begin(), tuples_from_index.end() );
|
|
|
|
|
auto last = std::unique( tuples_from_index.begin(), tuples_from_index.end() );
|
|
|
|
|
size_t size_before_uniq = tuples_from_db.size();
|
|
|
|
|
tuples_from_index.erase( last, tuples_from_index.end() );
|
|
|
|
|
BOOST_CHECK( tuples_from_index.size() == size_before_uniq );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//BOOST_CHECK_EQUAL( tuples_from_db, tuples_from_index );
|
|
|
|
|
bool is_equal = true;
|
|
|
|
|
is_equal &= (tuples_from_db.size() == tuples_from_index.size());
|
|
|
|
|
for( size_t i=0,n=tuples_from_db.size(); i<n; i++ )
|
|
|
|
|
is_equal &= (tuples_from_db[i] == tuples_from_index[i] );
|
|
|
|
|
|
|
|
|
|
bool account_history_plugin_index_ok = is_equal;
|
|
|
|
|
BOOST_CHECK( account_history_plugin_index_ok );
|
2015-06-24 20:38:56 +00:00
|
|
|
*/
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::open_database()
|
|
|
|
|
{
|
|
|
|
|
if( !data_dir ) {
|
2015-07-13 18:56:29 +00:00
|
|
|
data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() );
|
2015-07-08 21:39:28 +00:00
|
|
|
db.open(data_dir->path(), [this]{return genesis_state;});
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signed_block database_fixture::generate_block(uint32_t skip, const fc::ecc::private_key& key, int miss_blocks)
|
|
|
|
|
{
|
2015-07-15 18:13:24 +00:00
|
|
|
skip |= database::skip_undo_history_check;
|
2015-06-08 15:50:35 +00:00
|
|
|
// skip == ~0 will skip checks specified in database::validation_steps
|
2015-09-17 15:29:26 +00:00
|
|
|
auto block = db.generate_block(db.get_slot_time(miss_blocks + 1),
|
2015-08-25 18:46:56 +00:00
|
|
|
db.get_scheduled_witness(miss_blocks + 1),
|
2015-06-08 15:50:35 +00:00
|
|
|
key, skip);
|
2015-09-17 15:29:26 +00:00
|
|
|
db.clear_pending();
|
|
|
|
|
return block;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::generate_blocks( uint32_t block_count )
|
|
|
|
|
{
|
|
|
|
|
for( uint32_t i = 0; i < block_count; ++i )
|
|
|
|
|
generate_block();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 21:56:14 +00:00
|
|
|
void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks, uint32_t skip)
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-06-15 21:28:20 +00:00
|
|
|
if( miss_intermediate_blocks )
|
|
|
|
|
{
|
2016-02-15 21:56:14 +00:00
|
|
|
generate_block(skip);
|
2016-02-08 06:23:01 +00:00
|
|
|
auto slots_to_miss = db.get_slot_at_time(timestamp);
|
|
|
|
|
if( slots_to_miss <= 1 )
|
|
|
|
|
return;
|
|
|
|
|
--slots_to_miss;
|
2016-02-15 21:56:14 +00:00
|
|
|
generate_block(skip, init_account_priv_key, slots_to_miss);
|
2015-06-15 21:28:20 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2015-06-08 15:50:35 +00:00
|
|
|
while( db.head_block_time() < timestamp )
|
2016-02-15 21:56:14 +00:00
|
|
|
generate_block(skip);
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
account_create_operation database_fixture::make_account(
|
|
|
|
|
const std::string& name /* = "nathan" */,
|
2015-07-02 05:52:45 +00:00
|
|
|
public_key_type key /* = key_id_type() */
|
2015-06-08 15:50:35 +00:00
|
|
|
)
|
2015-07-02 05:52:45 +00:00
|
|
|
{ try {
|
2015-06-08 15:50:35 +00:00
|
|
|
account_create_operation create_account;
|
|
|
|
|
create_account.registrar = account_id_type();
|
|
|
|
|
|
|
|
|
|
create_account.name = name;
|
|
|
|
|
create_account.owner = authority(123, key, 123);
|
|
|
|
|
create_account.active = authority(321, key, 321);
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.memo_key = key;
|
2015-08-26 19:35:36 +00:00
|
|
|
create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT;
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-13 20:06:02 +00:00
|
|
|
auto& active_committee_members = db.get_global_properties().active_committee_members;
|
|
|
|
|
if( active_committee_members.size() > 0 )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
set<vote_id_type> votes;
|
2015-07-13 20:06:02 +00:00
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.votes = flat_set<vote_id_type>(votes.begin(), votes.end());
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.num_committee = create_account.options.votes.size();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
create_account.fee = db.current_fee_schedule().calculate_fee( create_account );
|
2015-06-08 15:50:35 +00:00
|
|
|
return create_account;
|
2015-07-02 05:52:45 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW() }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
account_create_operation database_fixture::make_account(
|
|
|
|
|
const std::string& name,
|
|
|
|
|
const account_object& registrar,
|
|
|
|
|
const account_object& referrer,
|
|
|
|
|
uint8_t referrer_percent /* = 100 */,
|
2015-07-02 05:52:45 +00:00
|
|
|
public_key_type key /* = public_key_type() */
|
2015-06-08 15:50:35 +00:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
account_create_operation create_account;
|
|
|
|
|
|
|
|
|
|
create_account.registrar = registrar.id;
|
|
|
|
|
create_account.referrer = referrer.id;
|
|
|
|
|
create_account.referrer_percent = referrer_percent;
|
|
|
|
|
|
|
|
|
|
create_account.name = name;
|
|
|
|
|
create_account.owner = authority(123, key, 123);
|
|
|
|
|
create_account.active = authority(321, key, 321);
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.memo_key = key;
|
2015-08-26 19:35:36 +00:00
|
|
|
create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT;
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-13 20:06:02 +00:00
|
|
|
const vector<committee_member_id_type>& active_committee_members = db.get_global_properties().active_committee_members;
|
|
|
|
|
if( active_committee_members.size() > 0 )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
set<vote_id_type> votes;
|
2015-07-13 20:06:02 +00:00
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
|
|
|
|
votes.insert(active_committee_members[rand() % active_committee_members.size()](db).vote_id);
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.votes = flat_set<vote_id_type>(votes.begin(), votes.end());
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
2015-06-16 18:42:02 +00:00
|
|
|
create_account.options.num_committee = create_account.options.votes.size();
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
create_account.fee = db.current_fee_schedule().calculate_fee( create_account );
|
2015-06-08 15:50:35 +00:00
|
|
|
return create_account;
|
|
|
|
|
}
|
|
|
|
|
FC_CAPTURE_AND_RETHROW((name)(referrer_percent))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const asset_object& database_fixture::get_asset( const string& symbol )const
|
|
|
|
|
{
|
2015-09-16 20:37:54 +00:00
|
|
|
const auto& idx = db.get_index_type<asset_index>().indices().get<by_symbol>();
|
|
|
|
|
const auto itr = idx.find(symbol);
|
|
|
|
|
assert( itr != idx.end() );
|
|
|
|
|
return *itr;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const account_object& database_fixture::get_account( const string& name )const
|
|
|
|
|
{
|
2015-09-16 20:37:54 +00:00
|
|
|
const auto& idx = db.get_index_type<account_index>().indices().get<by_name>();
|
|
|
|
|
const auto itr = idx.find(name);
|
|
|
|
|
assert( itr != idx.end() );
|
|
|
|
|
return *itr;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const asset_object& database_fixture::create_bitasset(
|
|
|
|
|
const string& name,
|
2015-09-21 21:17:30 +00:00
|
|
|
account_id_type issuer /* = GRAPHENE_WITNESS_ACCOUNT */,
|
2015-06-08 15:50:35 +00:00
|
|
|
uint16_t market_fee_percent /* = 100 */ /* 1% */,
|
|
|
|
|
uint16_t flags /* = charge_market_fee */
|
|
|
|
|
)
|
|
|
|
|
{ try {
|
|
|
|
|
asset_create_operation creator;
|
|
|
|
|
creator.issuer = issuer;
|
|
|
|
|
creator.fee = asset();
|
|
|
|
|
creator.symbol = name;
|
|
|
|
|
creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
2015-06-26 14:57:38 +00:00
|
|
|
creator.precision = 2;
|
2015-06-08 15:50:35 +00:00
|
|
|
creator.common_options.market_fee_percent = market_fee_percent;
|
2015-10-09 15:07:10 +00:00
|
|
|
if( issuer == GRAPHENE_WITNESS_ACCOUNT )
|
|
|
|
|
flags |= witness_fed_asset;
|
2015-06-08 15:50:35 +00:00
|
|
|
creator.common_options.issuer_permissions = flags;
|
|
|
|
|
creator.common_options.flags = flags & ~global_settle;
|
2015-12-17 16:32:22 +00:00
|
|
|
creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)});
|
2015-07-09 17:50:47 +00:00
|
|
|
creator.bitasset_opts = bitasset_options();
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.push_back(std::move(creator));
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return db.get<asset_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (name)(flags) ) }
|
|
|
|
|
|
2015-06-19 19:57:08 +00:00
|
|
|
const asset_object& database_fixture::create_prediction_market(
|
|
|
|
|
const string& name,
|
2015-09-21 21:17:30 +00:00
|
|
|
account_id_type issuer /* = GRAPHENE_WITNESS_ACCOUNT */,
|
2015-06-19 19:57:08 +00:00
|
|
|
uint16_t market_fee_percent /* = 100 */ /* 1% */,
|
|
|
|
|
uint16_t flags /* = charge_market_fee */
|
|
|
|
|
)
|
|
|
|
|
{ try {
|
|
|
|
|
asset_create_operation creator;
|
|
|
|
|
creator.issuer = issuer;
|
|
|
|
|
creator.fee = asset();
|
|
|
|
|
creator.symbol = name;
|
|
|
|
|
creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
2015-06-26 14:57:38 +00:00
|
|
|
creator.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS;
|
2015-06-19 19:57:08 +00:00
|
|
|
creator.common_options.market_fee_percent = market_fee_percent;
|
|
|
|
|
creator.common_options.issuer_permissions = flags | global_settle;
|
|
|
|
|
creator.common_options.flags = flags & ~global_settle;
|
2015-10-09 15:07:10 +00:00
|
|
|
if( issuer == GRAPHENE_WITNESS_ACCOUNT )
|
|
|
|
|
creator.common_options.flags |= witness_fed_asset;
|
2015-12-17 16:32:22 +00:00
|
|
|
creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)});
|
2015-07-09 17:50:47 +00:00
|
|
|
creator.bitasset_opts = bitasset_options();
|
2015-06-19 19:57:08 +00:00
|
|
|
creator.is_prediction_market = true;
|
|
|
|
|
trx.operations.push_back(std::move(creator));
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return db.get<asset_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (name)(flags) ) }
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
const asset_object& database_fixture::create_user_issued_asset( const string& name )
|
|
|
|
|
{
|
|
|
|
|
asset_create_operation creator;
|
|
|
|
|
creator.issuer = account_id_type();
|
|
|
|
|
creator.fee = asset();
|
|
|
|
|
creator.symbol = name;
|
|
|
|
|
creator.common_options.max_supply = 0;
|
|
|
|
|
creator.precision = 2;
|
2015-12-17 16:32:22 +00:00
|
|
|
creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)});
|
2015-06-08 15:50:35 +00:00
|
|
|
creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
|
|
|
|
creator.common_options.flags = charge_market_fee;
|
|
|
|
|
creator.common_options.issuer_permissions = charge_market_fee;
|
|
|
|
|
trx.operations.push_back(std::move(creator));
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return db.get<asset_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 20:57:22 +00:00
|
|
|
const asset_object& database_fixture::create_user_issued_asset( const string& name, const account_object& issuer, uint16_t flags )
|
|
|
|
|
{
|
|
|
|
|
asset_create_operation creator;
|
|
|
|
|
creator.issuer = issuer.id;
|
|
|
|
|
creator.fee = asset();
|
|
|
|
|
creator.symbol = name;
|
|
|
|
|
creator.common_options.max_supply = 0;
|
|
|
|
|
creator.precision = 2;
|
2015-12-17 16:32:22 +00:00
|
|
|
creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)});
|
2015-07-01 20:57:22 +00:00
|
|
|
creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
|
|
|
|
creator.common_options.flags = flags;
|
|
|
|
|
creator.common_options.issuer_permissions = flags;
|
2015-10-31 18:50:11 +00:00
|
|
|
trx.operations.clear();
|
2015-07-01 20:57:22 +00:00
|
|
|
trx.operations.push_back(std::move(creator));
|
2015-10-31 18:50:11 +00:00
|
|
|
set_expiration( db, trx );
|
2015-07-01 20:57:22 +00:00
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return db.get<asset_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
void database_fixture::issue_uia( const account_object& recipient, asset amount )
|
|
|
|
|
{
|
2015-07-24 21:10:36 +00:00
|
|
|
BOOST_TEST_MESSAGE( "Issuing UIA" );
|
2015-07-09 12:22:04 +00:00
|
|
|
asset_issue_operation op;
|
|
|
|
|
op.issuer = amount.asset_id(db).issuer;
|
|
|
|
|
op.asset_to_issue = amount;
|
|
|
|
|
op.issue_to_account = recipient.id;
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.push_back(op);
|
2015-07-24 21:10:36 +00:00
|
|
|
db.push_transaction( trx, ~0 );
|
|
|
|
|
trx.operations.clear();
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-03 20:48:52 +00:00
|
|
|
void database_fixture::issue_uia( account_id_type recipient_id, asset amount )
|
|
|
|
|
{
|
|
|
|
|
issue_uia( recipient_id(db), amount );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::change_fees(
|
|
|
|
|
const flat_set< fee_parameters >& new_params,
|
|
|
|
|
uint32_t new_scale /* = 0 */
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
const chain_parameters& current_chain_params = db.get_global_properties().parameters;
|
|
|
|
|
const fee_schedule& current_fees = *(current_chain_params.current_fees);
|
|
|
|
|
|
|
|
|
|
flat_map< int, fee_parameters > fee_map;
|
|
|
|
|
fee_map.reserve( current_fees.parameters.size() );
|
|
|
|
|
for( const fee_parameters& op_fee : current_fees.parameters )
|
|
|
|
|
fee_map[ op_fee.which() ] = op_fee;
|
|
|
|
|
for( const fee_parameters& new_fee : new_params )
|
|
|
|
|
fee_map[ new_fee.which() ] = new_fee;
|
|
|
|
|
|
|
|
|
|
fee_schedule_type new_fees;
|
|
|
|
|
|
|
|
|
|
for( const std::pair< int, fee_parameters >& item : fee_map )
|
|
|
|
|
new_fees.parameters.insert( item.second );
|
|
|
|
|
if( new_scale != 0 )
|
|
|
|
|
new_fees.scale = new_scale;
|
|
|
|
|
|
|
|
|
|
chain_parameters new_chain_params = current_chain_params;
|
|
|
|
|
new_chain_params.current_fees = new_fees;
|
|
|
|
|
|
|
|
|
|
db.modify(db.get_global_properties(), [&](global_property_object& p) {
|
|
|
|
|
p.parameters = new_chain_params;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
const account_object& database_fixture::create_account(
|
|
|
|
|
const string& name,
|
2015-07-02 05:52:45 +00:00
|
|
|
const public_key_type& key /* = public_key_type() */
|
2015-06-08 15:50:35 +00:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
trx.operations.push_back(make_account(name, key));
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
auto& result = db.get<account_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const account_object& database_fixture::create_account(
|
|
|
|
|
const string& name,
|
|
|
|
|
const account_object& registrar,
|
|
|
|
|
const account_object& referrer,
|
|
|
|
|
uint8_t referrer_percent /* = 100 */,
|
2015-07-02 05:52:45 +00:00
|
|
|
const public_key_type& key /*= public_key_type()*/
|
2015-06-08 15:50:35 +00:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
trx.operations.resize(1);
|
|
|
|
|
trx.operations.back() = (make_account(name, registrar, referrer, referrer_percent, key));
|
|
|
|
|
trx.validate();
|
|
|
|
|
auto r = db.push_transaction(trx, ~0);
|
|
|
|
|
const auto& result = db.get<account_object>(r.operation_results[0].get<object_id_type>());
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
FC_CAPTURE_AND_RETHROW( (name)(registrar)(referrer) )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const account_object& database_fixture::create_account(
|
|
|
|
|
const string& name,
|
|
|
|
|
const private_key_type& key,
|
|
|
|
|
const account_id_type& registrar_id /* = account_id_type() */,
|
|
|
|
|
const account_id_type& referrer_id /* = account_id_type() */,
|
|
|
|
|
uint8_t referrer_percent /* = 100 */
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
trx.operations.clear();
|
|
|
|
|
|
|
|
|
|
account_create_operation account_create_op;
|
|
|
|
|
|
|
|
|
|
account_create_op.registrar = registrar_id;
|
|
|
|
|
account_create_op.name = name;
|
2015-07-02 05:52:45 +00:00
|
|
|
account_create_op.owner = authority(1234, public_key_type(key.get_public_key()), 1234);
|
|
|
|
|
account_create_op.active = authority(5678, public_key_type(key.get_public_key()), 5678);
|
|
|
|
|
account_create_op.options.memo_key = key.get_public_key();
|
2015-08-26 19:35:36 +00:00
|
|
|
account_create_op.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT;
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.push_back( account_create_op );
|
|
|
|
|
|
|
|
|
|
trx.validate();
|
|
|
|
|
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
2015-06-18 19:17:48 +00:00
|
|
|
//wdump( (ptx) );
|
2015-07-02 05:52:45 +00:00
|
|
|
const account_object& result = db.get<account_object>(ptx.operation_results[0].get<object_id_type>());
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
FC_CAPTURE_AND_RETHROW( (name)(registrar_id)(referrer_id) )
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 20:06:02 +00:00
|
|
|
const committee_member_object& database_fixture::create_committee_member( const account_object& owner )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-07-13 20:06:02 +00:00
|
|
|
committee_member_create_operation op;
|
|
|
|
|
op.committee_member_account = owner.id;
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.push_back(op);
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-13 20:06:02 +00:00
|
|
|
return db.get<committee_member_object>(ptx.operation_results[0].get<object_id_type>());
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-02 05:52:45 +00:00
|
|
|
const witness_object&database_fixture::create_witness(account_id_type owner, const fc::ecc::private_key& signing_private_key)
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-07-02 05:52:45 +00:00
|
|
|
return create_witness(owner(db), signing_private_key);
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-02 05:52:45 +00:00
|
|
|
const witness_object& database_fixture::create_witness( const account_object& owner,
|
2015-06-08 15:50:35 +00:00
|
|
|
const fc::ecc::private_key& signing_private_key )
|
|
|
|
|
{ try {
|
|
|
|
|
witness_create_operation op;
|
|
|
|
|
op.witness_account = owner.id;
|
2015-07-02 05:52:45 +00:00
|
|
|
op.block_signing_key = signing_private_key.get_public_key();
|
2016-09-10 19:28:09 +00:00
|
|
|
secret_hash_type::encoder enc;
|
|
|
|
|
fc::raw::pack(enc, signing_private_key);
|
|
|
|
|
fc::raw::pack(enc, secret_hash_type());
|
|
|
|
|
op.initial_secret = secret_hash_type::hash(enc.result());
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.push_back(op);
|
|
|
|
|
trx.validate();
|
|
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.clear();
|
|
|
|
|
return db.get<witness_object>(ptx.operation_results[0].get<object_id_type>());
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW() }
|
|
|
|
|
|
|
|
|
|
uint64_t database_fixture::fund(
|
|
|
|
|
const account_object& account,
|
|
|
|
|
const asset& amount /* = asset(500000) */
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
transfer(account_id_type()(db), account, amount);
|
|
|
|
|
return get_balance(account, amount.asset_id(db));
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 05:52:45 +00:00
|
|
|
void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key)
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-08-06 16:41:45 +00:00
|
|
|
trx.sign( key, db.get_chain_id() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
digest_type database_fixture::digest( const transaction& tx )
|
|
|
|
|
{
|
|
|
|
|
return tx.digest();
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv)
|
|
|
|
|
{
|
2015-07-01 21:10:19 +00:00
|
|
|
auto r = create_sell_order(user(db), amount, recv);
|
|
|
|
|
verify_asset_supplies(db);
|
|
|
|
|
return r;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const limit_order_object* database_fixture::create_sell_order( const account_object& user, const asset& amount, const asset& recv )
|
|
|
|
|
{
|
2015-06-18 19:17:48 +00:00
|
|
|
//wdump((amount)(recv));
|
2015-06-08 15:50:35 +00:00
|
|
|
limit_order_create_operation buy_order;
|
|
|
|
|
buy_order.seller = user.id;
|
|
|
|
|
buy_order.amount_to_sell = amount;
|
|
|
|
|
buy_order.min_to_receive = recv;
|
|
|
|
|
trx.operations.push_back(buy_order);
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.validate();
|
|
|
|
|
auto processed = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-18 19:17:48 +00:00
|
|
|
//wdump((processed));
|
2015-06-08 15:50:35 +00:00
|
|
|
return db.find<limit_order_object>( processed.operation_results[0].get<object_id_type>() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
asset database_fixture::cancel_limit_order( const limit_order_object& order )
|
|
|
|
|
{
|
|
|
|
|
limit_order_cancel_operation cancel_order;
|
|
|
|
|
cancel_order.fee_paying_account = order.seller;
|
|
|
|
|
cancel_order.order = order.id;
|
|
|
|
|
trx.operations.push_back(cancel_order);
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.validate();
|
|
|
|
|
auto processed = db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-08 15:50:35 +00:00
|
|
|
return processed.operation_results[0].get<asset>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::transfer(
|
|
|
|
|
account_id_type from,
|
|
|
|
|
account_id_type to,
|
|
|
|
|
const asset& amount,
|
|
|
|
|
const asset& fee /* = asset() */
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
transfer(from(db), to(db), amount, fee);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::transfer(
|
|
|
|
|
const account_object& from,
|
|
|
|
|
const account_object& to,
|
|
|
|
|
const asset& amount,
|
|
|
|
|
const asset& fee /* = asset() */ )
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-07-09 12:22:04 +00:00
|
|
|
transfer_operation trans;
|
|
|
|
|
trans.from = from.id;
|
|
|
|
|
trans.to = to.id;
|
|
|
|
|
trans.amount = amount;
|
|
|
|
|
trx.operations.push_back(trans);
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
if( fee == asset() )
|
|
|
|
|
{
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW( (from.id)(to.id)(amount)(fee) )
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 19:17:48 +00:00
|
|
|
void database_fixture::update_feed_producers( const asset_object& mia, flat_set<account_id_type> producers )
|
|
|
|
|
{ try {
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
asset_update_feed_producers_operation op;
|
|
|
|
|
op.asset_to_update = mia.id;
|
|
|
|
|
op.issuer = mia.issuer;
|
|
|
|
|
op.new_feed_producers = std::move(producers);
|
2015-06-18 21:05:12 +00:00
|
|
|
trx.operations = {std::move(op)};
|
2015-06-18 19:17:48 +00:00
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-18 19:17:48 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (mia)(producers) ) }
|
|
|
|
|
|
2015-07-23 19:11:55 +00:00
|
|
|
void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f )
|
2015-06-18 19:17:48 +00:00
|
|
|
{
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
|
|
|
|
|
asset_publish_feed_operation op;
|
|
|
|
|
op.publisher = by.id;
|
|
|
|
|
op.asset_id = mia.id;
|
|
|
|
|
op.feed = f;
|
2015-10-28 17:03:31 +00:00
|
|
|
if( op.feed.core_exchange_rate.is_null() )
|
|
|
|
|
op.feed.core_exchange_rate = op.feed.settlement_price;
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.operations.emplace_back( std::move(op) );
|
|
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-18 19:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-19 19:57:08 +00:00
|
|
|
void database_fixture::force_global_settle( const asset_object& what, const price& p )
|
|
|
|
|
{ try {
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-19 19:57:08 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
asset_global_settle_operation sop;
|
|
|
|
|
sop.issuer = what.issuer;
|
|
|
|
|
sop.asset_to_settle = what.id;
|
|
|
|
|
sop.settle_price = p;
|
|
|
|
|
trx.operations.push_back(sop);
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-19 19:57:08 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-19 19:57:08 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (what)(p) ) }
|
|
|
|
|
|
2015-07-20 16:55:58 +00:00
|
|
|
operation_result database_fixture::force_settle( const account_object& who, asset what )
|
2015-06-19 18:47:42 +00:00
|
|
|
{ try {
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-19 18:47:42 +00:00
|
|
|
trx.operations.clear();
|
|
|
|
|
asset_settle_operation sop;
|
|
|
|
|
sop.account = who.id;
|
|
|
|
|
sop.amount = what;
|
|
|
|
|
trx.operations.push_back(sop);
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-19 18:47:42 +00:00
|
|
|
trx.validate();
|
2015-07-20 16:55:58 +00:00
|
|
|
processed_transaction ptx = db.push_transaction(trx, ~0);
|
|
|
|
|
const operation_result& op_result = ptx.operation_results.front();
|
2015-06-19 18:47:42 +00:00
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-07-20 16:55:58 +00:00
|
|
|
return op_result;
|
2015-06-19 18:47:42 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (who)(what) ) }
|
|
|
|
|
|
2015-07-16 19:05:50 +00:00
|
|
|
const call_order_object* database_fixture::borrow(const account_object& who, asset what, asset collateral)
|
2015-06-18 19:17:48 +00:00
|
|
|
{ try {
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.operations.clear();
|
2015-07-09 12:22:04 +00:00
|
|
|
call_order_update_operation update;
|
|
|
|
|
update.funding_account = who.id;
|
|
|
|
|
update.delta_collateral = collateral;
|
|
|
|
|
update.delta_debt = what;
|
|
|
|
|
trx.operations.push_back(update);
|
|
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-07-16 19:05:50 +00:00
|
|
|
|
|
|
|
|
auto& call_idx = db.get_index_type<call_order_index>().indices().get<by_account>();
|
|
|
|
|
auto itr = call_idx.find( boost::make_tuple(who.id, what.asset_id) );
|
|
|
|
|
const call_order_object* call_obj = nullptr;
|
|
|
|
|
|
|
|
|
|
if( itr != call_idx.end() )
|
|
|
|
|
call_obj = &*itr;
|
|
|
|
|
return call_obj;
|
2015-06-18 19:17:48 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (who.name)(what)(collateral) ) }
|
|
|
|
|
|
2015-07-23 19:11:55 +00:00
|
|
|
void database_fixture::cover(const account_object& who, asset what, asset collateral)
|
2015-06-18 19:17:48 +00:00
|
|
|
{ try {
|
2015-07-23 19:11:55 +00:00
|
|
|
set_expiration( db, trx );
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.operations.clear();
|
2015-07-09 12:22:04 +00:00
|
|
|
call_order_update_operation update;
|
|
|
|
|
update.funding_account = who.id;
|
|
|
|
|
update.delta_collateral = -collateral;
|
|
|
|
|
update.delta_debt = -what;
|
|
|
|
|
trx.operations.push_back(update);
|
|
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-18 19:17:48 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-18 19:17:48 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (who.name)(what)(collateral) ) }
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
void database_fixture::fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount )
|
|
|
|
|
{
|
2015-07-09 12:22:04 +00:00
|
|
|
asset_fund_fee_pool_operation fund;
|
|
|
|
|
fund.from_account = from.id;
|
|
|
|
|
fund.asset_id = asset_to_fund.id;
|
|
|
|
|
fund.amount = amount;
|
|
|
|
|
trx.operations.push_back( fund );
|
2015-06-08 15:50:35 +00:00
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.validate();
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
trx.operations.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-09 12:22:04 +00:00
|
|
|
void database_fixture::enable_fees()
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-07-09 12:22:04 +00:00
|
|
|
db.modify(global_property_id_type()(db), [](global_property_object& gpo)
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-07-09 12:22:04 +00:00
|
|
|
gpo.parameters.current_fees = fee_schedule::get_default();
|
2015-08-10 20:39:09 +00:00
|
|
|
});
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-09 20:46:00 +00:00
|
|
|
void database_fixture::upgrade_to_lifetime_member(account_id_type account)
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
2015-06-09 20:46:00 +00:00
|
|
|
upgrade_to_lifetime_member(account(db));
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-09 20:46:00 +00:00
|
|
|
void database_fixture::upgrade_to_lifetime_member( const account_object& account )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-06-10 18:17:13 +00:00
|
|
|
account_upgrade_operation op;
|
|
|
|
|
op.account_to_upgrade = account.get_id();
|
|
|
|
|
op.upgrade_to_lifetime_member = true;
|
2015-07-09 12:22:04 +00:00
|
|
|
op.fee = db.get_global_properties().parameters.current_fees->calculate_fee(op);
|
2015-06-10 18:17:13 +00:00
|
|
|
trx.operations = {op};
|
2015-06-15 21:28:20 +00:00
|
|
|
db.push_transaction(trx, ~0);
|
2015-06-10 18:17:13 +00:00
|
|
|
FC_ASSERT( op.account_to_upgrade(db).is_lifetime_member() );
|
2015-06-08 15:50:35 +00:00
|
|
|
trx.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
FC_CAPTURE_AND_RETHROW((account))
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 21:28:20 +00:00
|
|
|
void database_fixture::upgrade_to_annual_member(account_id_type account)
|
|
|
|
|
{
|
|
|
|
|
upgrade_to_annual_member(account(db));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::upgrade_to_annual_member(const account_object& account)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
account_upgrade_operation op;
|
|
|
|
|
op.account_to_upgrade = account.get_id();
|
2015-07-09 12:22:04 +00:00
|
|
|
op.fee = db.get_global_properties().parameters.current_fees->calculate_fee(op);
|
2015-06-15 21:28:20 +00:00
|
|
|
trx.operations = {op};
|
|
|
|
|
db.push_transaction(trx, ~0);
|
|
|
|
|
FC_ASSERT( op.account_to_upgrade(db).is_member(db.head_block_time()) );
|
|
|
|
|
trx.clear();
|
2015-07-01 21:10:19 +00:00
|
|
|
verify_asset_supplies(db);
|
2015-06-15 21:28:20 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW((account))
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
void database_fixture::print_market( const string& syma, const string& symb )const
|
|
|
|
|
{
|
|
|
|
|
const auto& limit_idx = db.get_index_type<limit_order_index>();
|
|
|
|
|
const auto& price_idx = limit_idx.indices().get<by_price>();
|
|
|
|
|
|
2015-06-18 22:42:44 +00:00
|
|
|
cerr << std::fixed;
|
|
|
|
|
cerr.precision(5);
|
|
|
|
|
cerr << std::setw(10) << std::left << "NAME" << " ";
|
|
|
|
|
cerr << std::setw(16) << std::right << "FOR SALE" << " ";
|
|
|
|
|
cerr << std::setw(16) << std::right << "FOR WHAT" << " ";
|
|
|
|
|
cerr << std::setw(10) << std::right << "PRICE (S/W)" << " ";
|
|
|
|
|
cerr << std::setw(10) << std::right << "1/PRICE (W/S)" << "\n";
|
|
|
|
|
cerr << string(70, '=') << std::endl;
|
2015-06-08 15:50:35 +00:00
|
|
|
auto cur = price_idx.begin();
|
|
|
|
|
while( cur != price_idx.end() )
|
|
|
|
|
{
|
2015-06-18 22:42:44 +00:00
|
|
|
cerr << std::setw( 10 ) << std::left << cur->seller(db).name << " ";
|
|
|
|
|
cerr << std::setw( 10 ) << std::right << cur->for_sale.value << " ";
|
|
|
|
|
cerr << std::setw( 5 ) << std::left << cur->amount_for_sale().asset_id(db).symbol << " ";
|
|
|
|
|
cerr << std::setw( 10 ) << std::right << cur->amount_to_receive().amount.value << " ";
|
|
|
|
|
cerr << std::setw( 5 ) << std::left << cur->amount_to_receive().asset_id(db).symbol << " ";
|
|
|
|
|
cerr << std::setw( 10 ) << std::right << cur->sell_price.to_real() << " ";
|
|
|
|
|
cerr << std::setw( 10 ) << std::right << (~cur->sell_price).to_real() << " ";
|
|
|
|
|
cerr << "\n";
|
2015-06-08 15:50:35 +00:00
|
|
|
++cur;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string database_fixture::pretty( const asset& a )const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << a.amount.value << " ";
|
|
|
|
|
ss << a.asset_id(db).symbol;
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::print_limit_order( const limit_order_object& cur )const
|
|
|
|
|
{
|
|
|
|
|
std::cout << std::setw(10) << cur.seller(db).name << " ";
|
|
|
|
|
std::cout << std::setw(10) << "LIMIT" << " ";
|
|
|
|
|
std::cout << std::setw(16) << pretty( cur.amount_for_sale() ) << " ";
|
|
|
|
|
std::cout << std::setw(16) << pretty( cur.amount_to_receive() ) << " ";
|
|
|
|
|
std::cout << std::setw(16) << cur.sell_price.to_real() << " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::print_call_orders()const
|
|
|
|
|
{
|
|
|
|
|
cout << std::fixed;
|
|
|
|
|
cout.precision(5);
|
|
|
|
|
cout << std::setw(10) << std::left << "NAME" << " ";
|
|
|
|
|
cout << std::setw(10) << std::right << "TYPE" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "DEBT" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "COLLAT" << " ";
|
2015-06-18 22:42:44 +00:00
|
|
|
cout << std::setw(16) << std::right << "CALL PRICE(D/C)" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "~CALL PRICE(C/D)" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "SWAN(D/C)" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "SWAN(C/D)" << "\n";
|
2015-06-08 15:50:35 +00:00
|
|
|
cout << string(70, '=');
|
|
|
|
|
|
|
|
|
|
for( const call_order_object& o : db.get_index_type<call_order_index>().indices() )
|
|
|
|
|
{
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
cout << std::setw( 10 ) << std::left << o.borrower(db).name << " ";
|
|
|
|
|
cout << std::setw( 16 ) << std::right << pretty( o.get_debt() ) << " ";
|
|
|
|
|
cout << std::setw( 16 ) << std::right << pretty( o.get_collateral() ) << " ";
|
|
|
|
|
cout << std::setw( 16 ) << std::right << o.call_price.to_real() << " ";
|
|
|
|
|
cout << std::setw( 16 ) << std::right << (~o.call_price).to_real() << " ";
|
2015-06-18 22:42:44 +00:00
|
|
|
cout << std::setw( 16 ) << std::right << (o.get_debt()/o.get_collateral()).to_real() << " ";
|
|
|
|
|
cout << std::setw( 16 ) << std::right << (~(o.get_debt()/o.get_collateral())).to_real() << " ";
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void database_fixture::print_joint_market( const string& syma, const string& symb )const
|
|
|
|
|
{
|
|
|
|
|
cout << std::fixed;
|
|
|
|
|
cout.precision(5);
|
|
|
|
|
|
|
|
|
|
cout << std::setw(10) << std::left << "NAME" << " ";
|
|
|
|
|
cout << std::setw(10) << std::right << "TYPE" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "FOR SALE" << " ";
|
|
|
|
|
cout << std::setw(16) << std::right << "FOR WHAT" << " ";
|
2015-06-18 22:42:44 +00:00
|
|
|
cout << std::setw(16) << std::right << "PRICE (S/W)" << "\n";
|
2015-06-08 15:50:35 +00:00
|
|
|
cout << string(70, '=');
|
|
|
|
|
|
|
|
|
|
const auto& limit_idx = db.get_index_type<limit_order_index>();
|
|
|
|
|
const auto& limit_price_idx = limit_idx.indices().get<by_price>();
|
|
|
|
|
|
|
|
|
|
auto limit_itr = limit_price_idx.begin();
|
2015-06-16 16:17:09 +00:00
|
|
|
while( limit_itr != limit_price_idx.end() )
|
2015-06-08 15:50:35 +00:00
|
|
|
{
|
|
|
|
|
std::cout << std::endl;
|
2015-06-16 16:17:09 +00:00
|
|
|
print_limit_order( *limit_itr );
|
|
|
|
|
++limit_itr;
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t database_fixture::get_balance( account_id_type account, asset_id_type a )const
|
|
|
|
|
{
|
|
|
|
|
return db.get_balance(account, a).amount.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t database_fixture::get_balance( const account_object& account, const asset_object& a )const
|
|
|
|
|
{
|
|
|
|
|
return db.get_balance(account.get_id(), a.get_id()).amount.value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 19:58:01 +00:00
|
|
|
vector< operation_history_object > database_fixture::get_operation_history( account_id_type account_id )const
|
|
|
|
|
{
|
|
|
|
|
vector< operation_history_object > result;
|
|
|
|
|
const auto& stats = account_id(db).statistics(db);
|
|
|
|
|
if(stats.most_recent_op == account_transaction_history_id_type())
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
const account_transaction_history_object* node = &stats.most_recent_op(db);
|
|
|
|
|
while( true )
|
|
|
|
|
{
|
|
|
|
|
result.push_back( node->operation_id(db) );
|
|
|
|
|
if(node->next == account_transaction_history_id_type())
|
|
|
|
|
break;
|
|
|
|
|
node = db.find(node->next);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-17 20:07:50 +00:00
|
|
|
namespace test {
|
|
|
|
|
|
2015-07-23 19:11:55 +00:00
|
|
|
void set_expiration( const database& db, transaction& tx )
|
|
|
|
|
{
|
|
|
|
|
const chain_parameters& params = db.get_global_properties().parameters;
|
|
|
|
|
tx.set_reference_block(db.head_block_id());
|
2015-07-28 15:57:58 +00:00
|
|
|
tx.set_expiration( db.head_block_time() + fc::seconds( params.block_interval * (params.maintenance_skip_slots + 1) * 3 ) );
|
2015-07-23 19:11:55 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-17 20:07:50 +00:00
|
|
|
bool _push_block( database& db, const signed_block& b, uint32_t skip_flags /* = 0 */ )
|
|
|
|
|
{
|
|
|
|
|
return db.push_block( b, skip_flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags /* = 0 */ )
|
2015-06-25 16:07:39 +00:00
|
|
|
{ try {
|
2015-07-01 21:10:19 +00:00
|
|
|
auto pt = db.push_transaction( tx, skip_flags );
|
|
|
|
|
database_fixture::verify_asset_supplies(db);
|
|
|
|
|
return pt;
|
2015-06-25 16:07:39 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW((tx)) }
|
2015-06-17 20:07:50 +00:00
|
|
|
|
|
|
|
|
} // graphene::chain::test
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
} } // graphene::chain
|