It now builds #144

This commit is contained in:
Daniel Larimer 2015-07-09 09:56:50 -04:00
parent 786c65d4b4
commit c8f0ea4abe
13 changed files with 197 additions and 133 deletions

View file

@ -224,10 +224,6 @@ namespace graphene { namespace chain {
asset_update_operation(){}
/// Initializes the operation to apply changes to the provided asset, and copies old.options into @ref new_options
/// TODO: operations should not depend upon data model objects, reverse the dependency
// asset_update_operation(const asset_object& old);
asset fee;
account_id_type issuer;
asset_id_type asset_to_update;

View file

@ -34,6 +34,14 @@ namespace graphene { namespace chain {
*/
void validate()const;
template<typename Operation>
const typename Operation::fee_parameters_type& get()const
{
auto itr = parameters.find( typename Operation::fee_parameters_type() );
FC_ASSERT( itr != parameters.end() );
return itr->template get<typename Operation::fee_parameters_type>();
}
/**
* @note must be sorted by fee_parameters.which() and have no duplicates
*/

View file

@ -85,15 +85,6 @@ void asset_create_operation::validate()const
FC_ASSERT(precision <= 12);
}
/*
asset_update_operation::asset_update_operation(const asset_object& old)
{
issuer = old.issuer;
asset_to_update = old.get_id();
new_options = old.options;
}
*/
void asset_update_operation::validate()const
{
FC_ASSERT( fee.amount >= 0 );

View file

@ -453,21 +453,21 @@ BOOST_FIXTURE_TEST_CASE(bulk_discount, database_fixture)
ACTOR(nathan);
// Give nathan ALLLLLL the money!
transfer(GRAPHENE_COMMITTEE_ACCOUNT, nathan_id, db.get_balance(GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type()));
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
upgrade_to_lifetime_member(nathan_id);
share_type new_fees;
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += transfer_operation().calculate_fee(db.current_fee_schedule());
new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
auto old_cashback = nathan_id(db).cashback_balance(db).balance;
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 8);
@ -476,10 +476,10 @@ BOOST_FIXTURE_TEST_CASE(bulk_discount, database_fixture)
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += transfer_operation().calculate_fee(db.current_fee_schedule());
new_fees += db.current_fee_schedule().calculate_fee(transfer_operation()).amount;
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
enable_fees();//GRAPHENE_BLOCKCHAIN_PRECISION*10);
old_cashback = nathan_id(db).cashback_balance(db).balance;
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));

View file

@ -44,7 +44,10 @@ BOOST_AUTO_TEST_CASE( simple_single_signature )
const asset_object& core = asset_id_type()(db);
auto old_balance = fund(nathan);
transfer_operation op = {asset(),nathan.id, account_id_type(), core.amount(500)};
transfer_operation op;
op.from = nathan.id;
op.to = account_id_type();
op.amount = core.amount(500);
trx.operations.push_back(op);
sign(trx, nathan_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
@ -78,7 +81,10 @@ BOOST_AUTO_TEST_CASE( any_two_of_three )
trx.signatures.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))
transfer_operation op = {asset(), nathan.id, account_id_type(), core.amount(500)};
transfer_operation op;
op.from = nathan.id;
op.to = account_id_type();
op.amount = core.amount(500);
trx.operations.push_back(op);
sign(trx, nathan_key1);
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
@ -134,7 +140,9 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
auto old_balance = fund(child);
BOOST_TEST_MESSAGE( "Attempting to transfer with no signatures, should fail" );
transfer_operation op = {asset(), child.id, account_id_type(), core.amount(500)};
transfer_operation op;
op.from = child.id;
op.amount = core.amount(500);
trx.operations.push_back(op);
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
@ -170,8 +178,11 @@ BOOST_AUTO_TEST_CASE( recursive_accounts )
trx.signatures.clear();
}
op = {asset(),child.id, account_id_type(), core.amount(500)};
op.from = child.id;
op.to = account_id_type();
op.amount = core.amount(500);
trx.operations.push_back(op);
BOOST_TEST_MESSAGE( "Attempting transfer with no signatures, should fail" );
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx, database::skip_transaction_dupe_check ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting transfer just parent1, should fail" );
@ -295,24 +306,33 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
//Following any_two_of_three, nathan's active authority is satisfied by any two of {key1,key2,key3}
BOOST_TEST_MESSAGE( "moneyman is creating proposal for nathan to transfer 100 CORE to moneyman" );
proposal_create_operation op = {moneyman.id, asset(),
{{transfer_operation{asset(),nathan.id, moneyman.get_id(), core.amount(100)}}},
db.head_block_time() + fc::days(1)};
transfer_operation transfer_op;
transfer_op.from = nathan.id;
transfer_op.to = moneyman.get_id();
transfer_op.amount = core.amount(100);
proposal_create_operation op;
op.fee_paying_account = moneyman.id;
op.proposed_ops.emplace_back( transfer_op );
op.expiration_time = db.head_block_time() + fc::days(1);
asset nathan_start_balance = db.get_balance(nathan.get_id(), core.get_id());
{
vector<authority> other;
flat_set<account_id_type> active_set, owner_set;
operation_get_required_active_authorities(op,active_set);
operation_get_required_owner_authorities(op,owner_set);
operation_get_required_authorities(op,active_set,owner_set,other);
BOOST_CHECK_EQUAL(active_set.size(), 1);
BOOST_CHECK_EQUAL(owner_set.size(), 0);
BOOST_CHECK_EQUAL(other.size(), 0);
BOOST_CHECK(*active_set.begin() == moneyman.get_id());
active_set.clear();
//op.proposed_ops.front().get_required_auth(active_set, owner_set);
operation_get_required_active_authorities( op.proposed_ops.front().op, active_set );
operation_get_required_owner_authorities( op.proposed_ops.front().op, owner_set );
other.clear();
operation_get_required_authorities(op,active_set,owner_set,other);
BOOST_CHECK_EQUAL(active_set.size(), 1);
BOOST_CHECK_EQUAL(owner_set.size(), 0);
BOOST_CHECK_EQUAL(other.size(), 0);
BOOST_CHECK(*active_set.begin() == nathan.id);
}
@ -329,21 +349,28 @@ BOOST_AUTO_TEST_CASE( proposed_single_account )
BOOST_CHECK_EQUAL(proposal.available_owner_approvals.size(), 0);
BOOST_CHECK(*proposal.required_active_approvals.begin() == nathan.id);
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
proposal_update_operation pup;
pup.proposal = proposal.id;
pup.active_approvals_to_add.insert(nathan.id);
trx.operations = {pup};
trx.sign( genesis_key );
//Genesis may not add nathan's approval.
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
trx.operations = {proposal_update_operation{account_id_type(), asset(), proposal.id,{account_id_type()},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
pup.active_approvals_to_add.clear();
pup.active_approvals_to_add.insert(account_id_type());
trx.operations = {pup};
trx.sign( genesis_key );
//Genesis has no stake in the transaction.
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
trx.signatures.clear();
trx.operations = {proposal_update_operation{nathan.id, asset(), proposal.id,{nathan.id},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<account_id_type>{},flat_set<public_key_type>{},flat_set<public_key_type>{}}};
pup.active_approvals_to_add.clear();
pup.active_approvals_to_add.insert(nathan.id);
trx.operations = {pup};
trx.sign( nathan_key3 );
trx.sign( nathan_key2 );
// TODO: verify the key_id is proper...
//trx.signatures = {nathan_key3.sign_compact(trx.digest()), nathan_key2.sign_compact(trx.digest())};
BOOST_CHECK_EQUAL(get_balance(nathan, core), nathan_start_balance.amount.value);
PUSH_TX( db, trx );
@ -371,7 +398,10 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
});
BOOST_TEST_MESSAGE( "transfering 100000 CORE to nathan, signing with genesis key" );
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan.id, asset(100000)}));
transfer_operation top;
top.to = nathan.id;
top.amount = asset(100000);
trx.operations.push_back(top);
sign(trx, genesis_key);
GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception);
@ -468,10 +498,14 @@ BOOST_FIXTURE_TEST_CASE( fired_delegates, database_fixture )
}
//A proposal is created to give nathan lots more money.
proposal_create_operation pop = proposal_create_operation::genesis_proposal(db);
proposal_create_operation pop = proposal_create_operation::genesis_proposal(db.get_global_properties().parameters, db.head_block_time());
pop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
pop.expiration_time = db.head_block_time() + *pop.review_period_seconds * 3;
pop.proposed_ops.emplace_back(transfer_operation({asset(),account_id_type(), nathan->id, asset(100000)}));
transfer_operation top;
top.to = nathan->id;
top.amount = asset(100000);
pop.proposed_ops.emplace_back(top);
trx.operations.push_back(pop);
const proposal_object& prop = db.get<proposal_object>(PUSH_TX( db, trx ).operation_results.front().get<object_id_type>());
proposal_id_type pid = prop.id;
@ -954,13 +988,11 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture )
const asset_object& core = asset_id_type()(db);
transfer(genesis_account_object, alice_account_object, core.amount(100000));
operation xfer_op = transfer_operation(
{core.amount(0),
alice_account_object.id,
bob_account_object.id,
core.amount( 5000 ),
memo_data() });
xfer_op.visit( operation_set_fee( db.current_fee_schedule() ) );
transfer_operation xfer_op;
xfer_op.from = alice_account_object.id;
xfer_op.to = bob_account_object.id;
xfer_op.amount = core.amount(5000);
xfer_op.fee = db.current_fee_schedule().calculate_fee( xfer_op );
trx.clear();
trx.operations.push_back( xfer_op );

View file

@ -19,7 +19,7 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/protocol/protocol.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
@ -315,18 +315,6 @@ BOOST_AUTO_TEST_CASE( witness_rng_test_bits )
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( data_fees )
{
fee_schedule_type fs;
fs.data_fee = 10;
int x = 1489520937;
BOOST_CHECK_EQUAL(fs.total_data_fee(), 0);
BOOST_CHECK_EQUAL(fs.total_data_fee(fs), 0);
BOOST_CHECK_EQUAL(fs.total_data_fee(fs.key_create_fee), 0);
BOOST_CHECK_EQUAL(fs.total_data_fee(x, fs, authority()), 0);
auto keys = vector<private_key_type>(100, private_key_type::generate());
BOOST_CHECK_EQUAL(fs.total_data_fee(keys, x), (fc::raw::pack_size(keys) + fc::raw::pack_size(x)) / 1024 * 10);
}
BOOST_AUTO_TEST_CASE( exceptions )
{

View file

@ -19,13 +19,11 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/witness_schedule_object.hpp>
#include <fc/crypto/digest.hpp>
@ -51,7 +49,7 @@ genesis_state_type make_genesis() {
genesis_state.initial_committee_candidates.push_back({name});
genesis_state.initial_witness_candidates.push_back({name, delegate_priv_key.get_public_key()});
}
genesis_state.initial_parameters.current_fees.set_all_fees(0);
genesis_state.initial_parameters.current_fees->zero_all_fees();
return genesis_state;
}
@ -282,10 +280,13 @@ BOOST_AUTO_TEST_CASE( undo_pending )
public_key_type delegate_pub_key = delegate_priv_key.get_public_key();
const graphene::db::index& account_idx = db.get_index(protocol_ids, account_object_type);
transfer_operation t;
t.to = account_id_type(1);
t.amount = asset( 10000000 );
{
signed_transaction trx;
trx.set_expiration(db.head_block_time() + fc::minutes(1));
trx.operations.push_back(transfer_operation({asset(), account_id_type(), account_id_type(1), asset(10000000)}));
trx.operations.push_back(t);
PUSH_TX( db, trx, ~0 );
now += db.block_interval();
@ -310,11 +311,15 @@ BOOST_AUTO_TEST_CASE( undo_pending )
trx.clear();
trx.set_expiration(db.head_block_time() + db.get_global_properties().parameters.maximum_time_until_expiration-1);
trx.operations.push_back(transfer_operation({asset(1),account_id_type(1), nathan_id, asset(5000)}));
t.fee = asset(1);
t.from = account_id_type(1);
t.to = nathan_id;
t.amount = asset(5000);
trx.operations.push_back(t);
db.push_transaction(trx, ~0);
trx.clear();
trx.set_expiration(db.head_block_time() + db.get_global_properties().parameters.maximum_time_until_expiration-2);
trx.operations.push_back(transfer_operation({asset(1),account_id_type(1), nathan_id, asset(5000)}));
trx.operations.push_back(t);
db.push_transaction(trx, ~0);
BOOST_CHECK(db.get_balance(nathan_id, asset_id_type()).amount == 10000);
@ -413,7 +418,10 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
trx = decltype(trx)();
trx.set_expiration(db1.head_block_time() + fc::minutes(1));
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan_id, asset(500)}));
transfer_operation t;
t.to = nathan_id;
t.amount = asset(500);
trx.operations.push_back(t);
trx.sign( delegate_priv_key );
PUSH_TX( db1, trx, skip_sigs );
@ -469,7 +477,10 @@ BOOST_AUTO_TEST_CASE( tapos )
b = db1.generate_block(now, db1.get_scheduled_witness(1).first, delegate_priv_key, database::skip_nothing);
trx.clear();
trx.operations.push_back(transfer_operation({asset(), account_id_type(), nathan_id, asset(50)}));
transfer_operation t;
t.to = nathan_id;
t.amount = asset(50);
trx.operations.push_back(t);
trx.sign(delegate_priv_key);
//relative_expiration is 1, but ref block is 2 blocks old, so this should fail.
GRAPHENE_REQUIRE_THROW(PUSH_TX( db1, trx, database::skip_transaction_signatures | database::skip_authority_check ), fc::exception);
@ -585,15 +596,22 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture )
asset amount(1000);
trx.set_expiration(db.head_block_time() + fc::minutes(1));
trx.operations.push_back(transfer_operation({ asset(), alice.id, bob.id, amount, memo_data() }));
for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule()));
transfer_operation t;
t.from = alice.id;
t.to = bob.id;
t.amount = amount;
trx.operations.push_back(t);
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
trx.validate();
db.push_transaction(trx, ~0);
trx.operations.clear();
trx.operations.push_back(transfer_operation({ asset(), bob.id, alice.id, amount, memo_data() }));
for( auto& op : trx.operations ) op.visit(operation_set_fee(db.current_fee_schedule()));
t.from = bob.id;
t.to = alice.id;
t.amount = amount;
trx.operations.push_back(t);
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
trx.validate();
BOOST_TEST_MESSAGE( "Verify that not-signing causes an exception" );
@ -625,10 +643,10 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture )
});
{
proposal_create_operation cop = proposal_create_operation::genesis_proposal(db);
proposal_create_operation cop = proposal_create_operation::genesis_proposal(db.get_global_properties().parameters, db.head_block_time());
cop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
cop.expiration_time = db.head_block_time() + *cop.review_period_seconds + 10;
global_parameters_update_operation uop;
delegate_update_global_parameters_operation uop;
uop.new_parameters.block_interval = 1;
cop.proposed_ops.emplace_back(uop);
trx.operations.push_back(cop);

View file

@ -19,7 +19,6 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>

View file

@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE( cashback_test )
transfer(account_id_type(), reggie_id, asset(100000000));
upgrade_to_lifetime_member(life_id);
upgrade_to_lifetime_member(reggie_id);
enable_fees(10000);
enable_fees();
const auto& fees = db.get_global_properties().parameters.current_fees;
#define CustomRegisterActor(actor_name, registrar_name, referrer_name, referrer_rate) \
@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( cashback_test )
op.options.memo_key = actor_name ## _private_key.get_public_key(); \
op.active = authority(1, public_key_type(actor_name ## _private_key.get_public_key()), 1); \
op.owner = op.active; \
op.fee = op.calculate_fee(fees); \
op.fee = fees->calculate_fee(op); \
trx.operations = {op}; \
trx.sign( registrar_name ## _private_key); \
actor_name ## _id = PUSH_TX( db, trx ).operation_results.front().get<object_id_type>(); \
@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( cashback_test )
CustomRegisterActor(scud, stud, ann, 80);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(10000);
enable_fees();
BOOST_CHECK_EQUAL(life_id(db).cashback_balance(db).balance.amount.value, 78000);
BOOST_CHECK_EQUAL(reggie_id(db).cashback_balance(db).balance.amount.value, 34000);
@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE( cashback_test )
generate_blocks(ann_id(db).membership_expiration_date);
generate_block();
enable_fees(10000);
enable_fees();
//ann's membership has expired, so scud's fee should go up to life instead.
transfer(scud_id, pleb_id, asset(10));

View file

@ -18,14 +18,11 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/witness_object.hpp>
@ -397,7 +394,7 @@ BOOST_AUTO_TEST_CASE( update_account )
account_upgrade_operation op;
op.account_to_upgrade = nathan.id;
op.upgrade_to_lifetime_member = true;
op.fee = op.calculate_fee(db.get_global_properties().parameters.current_fees);
op.fee = db.get_global_properties().parameters.current_fees->calculate_fee(op);
trx.operations = {op};
PUSH_TX( db, trx, ~0 );
}
@ -418,12 +415,12 @@ BOOST_AUTO_TEST_CASE( transfer_core_asset )
asset genesis_balance = db.get_balance(account_id_type(), asset_id_type());
const account_object& nathan_account = *db.get_index_type<account_index>().indices().get<by_name>().find("nathan");
trx.operations.push_back(transfer_operation({asset(),genesis_account,
nathan_account.id,
asset(10000),
memo_data()
}));
trx.visit( operation_set_fee( db.current_fee_schedule() ) );
transfer_operation top;
top.from = genesis_account;
top.to = nathan_account.id;
top.amount = asset( 10000);
trx.operations.push_back(top);
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
asset fee = trx.operations.front().get<transfer_operation>().fee;
trx.validate();
@ -436,13 +433,12 @@ BOOST_AUTO_TEST_CASE( transfer_core_asset )
BOOST_CHECK_EQUAL(get_balance(nathan_account, asset_id_type()(db)), 10000);
trx = signed_transaction();
trx.operations.push_back(transfer_operation({asset(),
nathan_account.id,
genesis_account,
asset(2000),
memo_data()
}));
trx.visit( operation_set_fee( db.current_fee_schedule() ) );
top.from = nathan_account.id;
top.to = genesis_account;
top.amount = asset(2000);
trx.operations.push_back(top);
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
fee = trx.operations.front().get<transfer_operation>().fee;
trx.validate();
@ -666,7 +662,10 @@ BOOST_AUTO_TEST_CASE( issue_uia )
const asset_object& test_asset = *db.get_index_type<asset_index>().indices().get<by_symbol>().find("TEST");
const account_object& nathan_account = *db.get_index_type<account_index>().indices().get<by_name>().find("nathan");
asset_issue_operation op({asset(),test_asset.issuer, test_asset.amount(5000000), nathan_account.id});
asset_issue_operation op;
op.issuer = test_asset.issuer;
op.asset_to_issue = test_asset.amount(5000000);
op.issue_to_account = nathan_account.id;
trx.operations.push_back(op);
REQUIRE_THROW_WITH_VALUE(op, asset_to_issue, asset(200));
@ -704,7 +703,11 @@ BOOST_AUTO_TEST_CASE( transfer_uia )
const account_object& genesis = account_id_type()(db);
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000);
trx.operations.push_back(transfer_operation({asset(),nathan.id, genesis.id, uia.amount(5000)}));
transfer_operation top;
top.to = nathan.id;
top.from = genesis.id;
top.amount = uia.amount(5000);
trx.operations.push_back(top);
PUSH_TX( db, trx, ~0 );
BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000 - 5000);
BOOST_CHECK_EQUAL(get_balance(genesis, uia), 5000);
@ -899,8 +902,12 @@ BOOST_AUTO_TEST_CASE( uia_fees )
fund_fee_pool(genesis_account, test_asset, 1000000);
BOOST_CHECK(asset_dynamic.fee_pool == 1000000);
transfer_operation op({test_asset.amount(0), nathan_account.id, genesis_account.id, test_asset.amount(100)});
op.fee = asset(op.calculate_fee(db.current_fee_schedule())) * test_asset.options.core_exchange_rate;
transfer_operation op;
op.fee = test_asset.amount(0);
op.from = nathan_account.id;
op.to = genesis_account.id;
op.amount = test_asset.amount(100);
op.fee = db.current_fee_schedule().calculate_fee( op, test_asset.options.core_exchange_rate );
BOOST_CHECK(op.fee.asset_id == test_asset.id);
asset old_balance = db.get_balance(nathan_account.get_id(), test_asset.get_id());
asset fee = op.fee;
@ -977,7 +984,11 @@ BOOST_AUTO_TEST_CASE( delegate_feeds )
try {
INVOKE( create_mia );
{
asset_update_operation uop(get_asset("BITUSD"));
auto& current = get_asset( "BITUSD" );
asset_update_operation uop;
uop.issuer = current.issuer;
uop.asset_to_update = current.id;
uop.new_options = current.options;
uop.new_issuer = account_id_type();
trx.operations.push_back(uop);
PUSH_TX( db, trx, ~0 );
@ -990,7 +1001,8 @@ BOOST_AUTO_TEST_CASE( delegate_feeds )
global_props.witness_accounts.end());
BOOST_REQUIRE_EQUAL(active_witnesses.size(), 10);
asset_publish_feed_operation op({asset(), active_witnesses[0]});
asset_publish_feed_operation op;
op.publisher = active_witnesses[0];
op.asset_id = bit_usd.get_id();
op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30));
// Accept defaults for required collateral
@ -1089,7 +1101,7 @@ BOOST_AUTO_TEST_CASE( fill_order )
{ try {
fill_order_operation o;
GRAPHENE_CHECK_THROW(o.validate(), fc::exception);
o.calculate_fee(db.current_fee_schedule());
//o.calculate_fee(db.current_fee_schedule());
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
@ -1105,11 +1117,11 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
const asset_object* core = &asset_id_type()(db);
const account_object* nathan = &get_account("nathan");
enable_fees(105000000);
BOOST_CHECK_GT(db.current_fee_schedule().membership_lifetime_fee, 0);
enable_fees();//105000000);
BOOST_CHECK_GT(db.current_fee_schedule().get<account_upgrade_operation>().membership_lifetime_fee, 0);
// Based on the size of the reserve fund later in the test, the witness budget will be set to this value
const uint64_t ref_budget =
((uint64_t( db.current_fee_schedule().membership_lifetime_fee )
((uint64_t( db.current_fee_schedule().get<account_upgrade_operation>().membership_lifetime_fee )
* GRAPHENE_CORE_ASSET_CYCLE_RATE * 30
* db.get_global_properties().parameters.block_interval
) + ((uint64_t(1) << GRAPHENE_CORE_ASSET_CYCLE_RATE_BITS)-1)
@ -1136,7 +1148,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
uop.upgrade_to_lifetime_member = true;
trx.set_expiration(db.head_block_id());
trx.operations.push_back(uop);
trx.visit(operation_set_fee(db.current_fee_schedule()));
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
trx.validate();
trx.sign(delegate_priv_key);
db.push_transaction(trx);
@ -1204,7 +1216,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
trx.set_expiration(db.head_block_time() + GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION);
// Withdraw the witness's pay
enable_fees(1);
enable_fees();//1);
witness = paid_witness;
witness_withdraw_pay_operation wop;
wop.from_witness = witness->id;
@ -1213,7 +1225,7 @@ BOOST_AUTO_TEST_CASE( witness_withdraw_pay_test )
trx.operations.push_back(wop);
REQUIRE_THROW_WITH_VALUE(wop, amount, witness->accumulated_income.value * 2);
trx.operations.back() = wop;
trx.visit(operation_set_fee(db.current_fee_schedule()));
for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op);
trx.validate();
db.push_transaction(trx, database::skip_authority_check);
trx.clear();

View file

@ -19,17 +19,16 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/worker_evaluator.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/predicate.hpp>
#include <graphene/chain/db_reflect_cmp.hpp>
#include <fc/crypto/digest.hpp>
@ -336,7 +335,8 @@ BOOST_AUTO_TEST_CASE( mia_feeds )
}
{
const asset_object& bit_usd = bit_usd_id(db);
asset_publish_feed_operation op({asset(), vikram_id});
asset_publish_feed_operation op;
op.publisher = vikram_id;
op.asset_id = bit_usd_id;
op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30));
// We'll expire margins after a month
@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE( worker_create_test )
worker_create_operation op;
op.owner = nathan_id;
op.daily_pay = 1000;
op.initializer = vesting_balance_worker_type::initializer(1);
op.initializer = vesting_balance_worker_initializer(1);
op.work_begin_date = db.head_block_time() + 10;
op.work_end_date = op.work_begin_date + fc::days(2);
trx.clear();
@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test )
worker_create_operation op;
op.owner = nathan_id;
op.daily_pay = 1000;
op.initializer = refund_worker_type::initializer();
op.initializer = refund_worker_initializer();
op.work_begin_date = db.head_block_time() + 10;
op.work_end_date = op.work_begin_date + fc::days(2);
trx.clear();
@ -757,7 +757,7 @@ BOOST_AUTO_TEST_CASE( burn_worker_test )
worker_create_operation op;
op.owner = nathan_id;
op.daily_pay = 1000;
op.initializer = burn_worker_type::initializer();
op.initializer = burn_worker_initializer();
op.work_begin_date = db.head_block_time() + 10;
op.work_end_date = op.work_begin_date + fc::days(2);
trx.clear();
@ -954,17 +954,13 @@ BOOST_AUTO_TEST_CASE( assert_op_test )
// nathan checks that his public key is equal to the given value.
op.fee_paying_account = nathan_id;
op.predicates = vector<vector<char>>();
op.predicates.push_back(
fc::raw::pack(
predicate(pred::account_name_eq_lit{ nathan_id, "nathan" })
));
op.predicates.emplace_back(account_name_eq_lit_predicate{ nathan_id, "nathan" });
trx.operations.push_back(op);
trx.sign(nathan_private_key);
PUSH_TX( db, trx );
// nathan checks that his public key is not equal to the given value (fail)
op.predicates.back() = fc::raw::pack(predicate(pred::account_name_eq_lit{ nathan_id, "dan" }));
op.predicates.back() = account_name_eq_lit_predicate{ nathan_id, "dan" };
trx.operations.back() = op;
trx.sign(nathan_private_key);
GRAPHENE_CHECK_THROW( PUSH_TX( db, trx ), fc::exception );

View file

@ -19,7 +19,6 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <fc/crypto/digest.hpp>

View file

@ -20,7 +20,6 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
@ -81,7 +80,11 @@ BOOST_AUTO_TEST_CASE( override_transfer_test )
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );
trx.operations.clear();
override_transfer_operation otrans{ asset(), advanced.issuer, dan.id, eric.id, advanced.amount(100) };
override_transfer_operation otrans;
otrans.issuer = advanced.issuer;
otrans.from = dan.id;
otrans.to = eric.id;
otrans.amount = advanced.amount(100);
trx.operations.push_back(otrans);
BOOST_TEST_MESSAGE( "Require throwing without signature" );
@ -109,7 +112,11 @@ BOOST_AUTO_TEST_CASE( override_transfer_test2 )
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );
trx.operations.clear();
override_transfer_operation otrans{ asset(), advanced.issuer, dan.id, eric.id, advanced.amount(100) };
override_transfer_operation otrans;
otrans.issuer = advanced.issuer;
otrans.from = dan.id;
otrans.to = eric.id;
otrans.amount = advanced.amount(100);
trx.operations.push_back(otrans);
BOOST_TEST_MESSAGE( "Require throwing without signature" );
@ -135,12 +142,18 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia )
upgrade_to_lifetime_member(nathan);
trx.clear();
asset_issue_operation op({asset(), advanced.issuer, advanced.amount(1000), nathan.id});
asset_issue_operation op;
op.issuer = advanced.issuer;
op.asset_to_issue = advanced.amount(1000);
op.issue_to_account = nathan.id; //({asset(), advanced.issuer, advanced.amount(1000), nathan.id});
trx.operations.emplace_back(op);
//Fail because nathan is not whitelisted.
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
account_whitelist_operation wop({asset(), account_id_type(), nathan.id, account_whitelist_operation::white_listed});
account_whitelist_operation wop;
wop.authorizing_account = account_id_type();
wop.account_to_list = nathan.id;
wop.new_listing = account_whitelist_operation::white_listed;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
@ -166,12 +179,19 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
upgrade_to_lifetime_member(dan);
trx.clear();
transfer_operation op({advanced.amount(0), nathan.id, dan.id, advanced.amount(100)});
transfer_operation op;
op.fee = advanced.amount(0);
op.from = nathan.id;
op.to = dan.id;
op.amount = advanced.amount(100); //({advanced.amount(0), nathan.id, dan.id, advanced.amount(100)});
trx.operations.push_back(op);
//Fail because dan is not whitelisted.
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_to_account_not_whitelisted );
account_whitelist_operation wop({asset(), account_id_type(), dan.id, account_whitelist_operation::white_listed});
account_whitelist_operation wop;
wop.authorizing_account = account_id_type();
wop.account_to_list = dan.id;
wop.new_listing = account_whitelist_operation::white_listed;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
trx.operations.back() = op;
@ -189,7 +209,10 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
trx.operations.back() = op;
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_from_account_not_whitelisted );
trx.operations = {asset_reserve_operation{asset(), nathan.id, advanced.amount(10)}};
asset_reserve_operation burn;
burn.payer = nathan.id;
burn.amount_to_reserve = advanced.amount(10);
trx.operations.emplace_back(burn);
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
std::swap(op.from, op.to);
@ -241,7 +264,9 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
BOOST_CHECK(!nathan.is_authorized_asset(advanced));
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
trx.operations = {asset_reserve_operation{asset(), dan.id, advanced.amount(10)}};
burn.payer = dan.id;
burn.amount_to_reserve = advanced.amount(10);
trx.operations.emplace_back(burn);
PUSH_TX(db, trx, ~0);
BOOST_CHECK_EQUAL(get_balance(dan, advanced), 40);
} catch(fc::exception& e) {