Skip to content

Commit

Permalink
utests adjustment and hforck time fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ddylko authored and ddylko committed Aug 1, 2019
1 parent 3095f2a commit 3256407
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 59 deletions.
8 changes: 4 additions & 4 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
#include <algorithm>
#include <tuple>

namespace graphene {
namespace graphene {
namespace protocol {
void verify_cycled_authority( const account_id_type& id,
void verify_cycled_authority( const account_id_type& id,
const std::function<const authority*(account_id_type)>& get_active,
const std::function<const authority*(account_id_type)>& get_owner,
uint32_t max_recursion_depth );
}
namespace chain {
namespace chain {

namespace detail {

Expand Down Expand Up @@ -471,9 +471,9 @@ void_result account_unlock_evaluator::do_apply( const account_unlock_operation&
const auto unlock_cost = balance.amount / 10;
const auto penalty = asset(unlock_cost, balance.asset_id);

d.push_applied_operation(account_unlock_penalty_payment_operation( acnt->get_id(), penalty ));
d.adjust_balance(acnt->get_id(), -penalty);
d.adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, penalty);
d.push_applied_operation(account_unlock_penalty_payment_operation( acnt->get_id(), penalty ));
}

return void_result();
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/hardfork.d/CYCLED_ACCOUNTS_HF.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #HARDFORK_CYCLED_ACCOUNTS_TIME Prevent to create/update account authorities that locks account.
#ifndef HARDFORK_CYCLED_ACCOUNTS_TIME
#define HARDFORK_CYCLED_ACCOUNTS_TIME (fc::time_point_sec( 1550102400 )) // Thursday, February 14, 2019 12:00:00 AM
#ifndef HARDFORK_CYCLED_ACCOUNTS_TIME
#define HARDFORK_CYCLED_ACCOUNTS_TIME (fc::time_point_sec( 1600000000 )) // Sunday, September 13, 2020 12:26:40 PM
#endif
10 changes: 7 additions & 3 deletions libraries/protocol/include/graphene/protocol/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ namespace graphene { namespace protocol {
struct fee_parameters_type {};

account_unlock_penalty_payment_operation(){}
account_unlock_penalty_payment_operation(
account_unlock_penalty_payment_operation(
account_id_type a, asset p
)
:account_id(a),penalty(p), fee() {}
:account_id(a), penalty(p), fee() {}

account_id_type account_id;
asset penalty;
Expand Down Expand Up @@ -347,7 +347,11 @@ FC_REFLECT( graphene::protocol::account_update_operation,

FC_REFLECT( graphene::protocol::account_unlock_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::protocol::account_unlock_operation, (fee)(account_to_unlock)(previous_authority)(extensions) )
FC_REFLECT( graphene::protocol::account_upgrade_operation, (fee)(account_to_upgrade)(upgrade_to_lifetime_member)(extensions) )


FC_REFLECT( graphene::protocol::account_upgrade_operation,
(fee)(account_to_upgrade)(upgrade_to_lifetime_member)(extensions) )

FC_REFLECT( graphene::protocol::account_whitelist_operation, (fee)(authorizing_account)(account_to_list)(new_listing)(extensions))
FC_REFLECT( graphene::protocol::account_create_operation::fee_parameters_type, (basic_fee)(premium_fee)(price_per_kbyte) )
FC_REFLECT( graphene::protocol::account_whitelist_operation::fee_parameters_type, (fee) )
Expand Down
64 changes: 14 additions & 50 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,46 +1272,23 @@ BOOST_AUTO_TEST_CASE( unlock_operation_penalty_payment_test )
{
INVOKE(make_recursive_authority_test);

generate_blocks(HARDFORK_1268_TIME);
generate_block();

GET_ACTOR(bob);
fund(bob);
ACTOR(issuer);

additional_asset_options_t options;
options.value.reward_percent = 2 * GRAPHENE_1_PERCENT;

const auto usd = create_user_issued_asset(
"USD",
issuer,
charge_market_fee,
price(asset(1, asset_id_type(1)), asset(1)),
1,
20 * GRAPHENE_1_PERCENT,
options);
const auto usd = create_user_issued_asset("USD");

issue_uia(issuer, usd.amount(2000));
transfer(issuer, bob, usd.amount(200));
transfer(issuer, GRAPHENE_COMMITTEE_ACCOUNT(db), usd.amount(200));

std::map<asset_id_type, share_type> bob_balance_helper;
std::map<asset_id_type, share_type> committee_balance_helper;
auto initial_balance_bob_BTS = get_balance(bob_id, asset_id_type());
auto initial_balance_bob_USD = get_balance(bob_id, usd.get_id());

const auto& bal_idx_before = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >();
for( const auto& entry : bal_idx_before.get_account_balances( bob_id ) )
{
const auto balance = entry.second->get_balance();
bob_balance_helper.emplace(balance.asset_id, balance.amount);
BOOST_CHECK_GT(balance.amount.value, 0);
}
for( const auto& entry : bal_idx_before.get_account_balances( GRAPHENE_COMMITTEE_ACCOUNT ) )
{
const auto balance = entry.second->get_balance();
committee_balance_helper.emplace(balance.asset_id, balance.amount);
BOOST_CHECK_GT(balance.amount.value, 0);
}

auto initial_balance_committee_BTS = get_balance( GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type());
auto initial_balance_committee_USD = get_balance( GRAPHENE_COMMITTEE_ACCOUNT, usd.get_id());

generate_blocks(HARDFORK_CYCLED_ACCOUNTS_TIME);
// unlock
{
account_unlock_operation op;
Expand All @@ -1326,40 +1303,27 @@ BOOST_AUTO_TEST_CASE( unlock_operation_penalty_payment_test )
PUSH_TX( db, trx );
}

const auto& bal_idx_after = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >();
for( const auto& entry : bal_idx_after.get_account_balances( bob_id ) )
{
const auto balance = entry.second->get_balance();
BOOST_CHECK_EQUAL(balance.amount.value, bob_balance_helper.at(balance.asset_id).value * 0.9);
}
BOOST_CHECK_EQUAL( get_balance(bob_id, asset_id_type()), initial_balance_bob_BTS * 0.9);
BOOST_CHECK_EQUAL( get_balance(bob_id, usd.get_id()), initial_balance_bob_USD * 0.9);

for( const auto& entry : bal_idx_after.get_account_balances( GRAPHENE_COMMITTEE_ACCOUNT ) )
{
const auto balance = entry.second->get_balance();
BOOST_CHECK_EQUAL(balance.amount.value - committee_balance_helper.at(balance.asset_id).value, bob_balance_helper.at(balance.asset_id).value * 0.1 );
}
BOOST_CHECK_EQUAL( get_balance(GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type()), initial_balance_committee_BTS + initial_balance_bob_BTS * 0.1);
BOOST_CHECK_EQUAL( get_balance(GRAPHENE_COMMITTEE_ACCOUNT, usd.get_id()), initial_balance_committee_USD + initial_balance_bob_USD * 0.1);

} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE(unloc_account_operation_failed_not_enough_BTS)
BOOST_AUTO_TEST_CASE(unlock_account_operation_failed_not_enough_BTS)
{
try
{
INVOKE(make_recursive_authority_test);

generate_blocks(HARDFORK_1268_TIME);
generate_blocks(HARDFORK_CYCLED_ACCOUNTS_TIME);
generate_block();

GET_ACTOR(bob);
enable_fees();

std::map<asset_id_type, share_type> bob_balance_helper;
std::map<asset_id_type, share_type> committee_balance_helper;

const auto& bal_idx_before = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >();
BOOST_CHECK( bal_idx_before.get_account_balances( bob_id ).size() == 0);

// unlock
account_unlock_operation op;
op.account_to_unlock = bob_id;
Expand All @@ -1371,7 +1335,7 @@ BOOST_AUTO_TEST_CASE(unloc_account_operation_failed_not_enough_BTS)
sign(trx, bob_private_key);

GRAPHENE_CHECK_THROW( PUSH_TX( db, trx ), fc::exception );

} FC_LOG_AND_RETHROW()
}

Expand Down

0 comments on commit 3256407

Please sign in to comment.