Skip to content

Commit 3256407

Browse files
ddylkoddylko
ddylko
authored and
ddylko
committed
utests adjustment and hforck time fix
1 parent 3095f2a commit 3256407

File tree

4 files changed

+27
-59
lines changed

4 files changed

+27
-59
lines changed

libraries/chain/account_evaluator.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
#include <algorithm>
3939
#include <tuple>
4040

41-
namespace graphene {
41+
namespace graphene {
4242
namespace protocol {
43-
void verify_cycled_authority( const account_id_type& id,
43+
void verify_cycled_authority( const account_id_type& id,
4444
const std::function<const authority*(account_id_type)>& get_active,
4545
const std::function<const authority*(account_id_type)>& get_owner,
4646
uint32_t max_recursion_depth );
4747
}
48-
namespace chain {
48+
namespace chain {
4949

5050
namespace detail {
5151

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

474-
d.push_applied_operation(account_unlock_penalty_payment_operation( acnt->get_id(), penalty ));
475474
d.adjust_balance(acnt->get_id(), -penalty);
476475
d.adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, penalty);
476+
d.push_applied_operation(account_unlock_penalty_payment_operation( acnt->get_id(), penalty ));
477477
}
478478

479479
return void_result();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// #HARDFORK_CYCLED_ACCOUNTS_TIME Prevent to create/update account authorities that locks account.
2-
#ifndef HARDFORK_CYCLED_ACCOUNTS_TIME
3-
#define HARDFORK_CYCLED_ACCOUNTS_TIME (fc::time_point_sec( 1550102400 )) // Thursday, February 14, 2019 12:00:00 AM
2+
#ifndef HARDFORK_CYCLED_ACCOUNTS_TIME
3+
#define HARDFORK_CYCLED_ACCOUNTS_TIME (fc::time_point_sec( 1600000000 )) // Sunday, September 13, 2020 12:26:40 PM
44
#endif

libraries/protocol/include/graphene/protocol/account.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ namespace graphene { namespace protocol {
207207
struct fee_parameters_type {};
208208

209209
account_unlock_penalty_payment_operation(){}
210-
account_unlock_penalty_payment_operation(
210+
account_unlock_penalty_payment_operation(
211211
account_id_type a, asset p
212212
)
213-
:account_id(a),penalty(p), fee() {}
213+
:account_id(a), penalty(p), fee() {}
214214

215215
account_id_type account_id;
216216
asset penalty;
@@ -347,7 +347,11 @@ FC_REFLECT( graphene::protocol::account_update_operation,
347347

348348
FC_REFLECT( graphene::protocol::account_unlock_operation::fee_parameters_type, (fee) )
349349
FC_REFLECT( graphene::protocol::account_unlock_operation, (fee)(account_to_unlock)(previous_authority)(extensions) )
350-
FC_REFLECT( graphene::protocol::account_upgrade_operation, (fee)(account_to_upgrade)(upgrade_to_lifetime_member)(extensions) )
350+
351+
352+
FC_REFLECT( graphene::protocol::account_upgrade_operation,
353+
(fee)(account_to_upgrade)(upgrade_to_lifetime_member)(extensions) )
354+
351355
FC_REFLECT( graphene::protocol::account_whitelist_operation, (fee)(authorizing_account)(account_to_list)(new_listing)(extensions))
352356
FC_REFLECT( graphene::protocol::account_create_operation::fee_parameters_type, (basic_fee)(premium_fee)(price_per_kbyte) )
353357
FC_REFLECT( graphene::protocol::account_whitelist_operation::fee_parameters_type, (fee) )

tests/tests/operation_tests.cpp

+14-50
Original file line numberDiff line numberDiff line change
@@ -1272,46 +1272,23 @@ BOOST_AUTO_TEST_CASE( unlock_operation_penalty_payment_test )
12721272
{
12731273
INVOKE(make_recursive_authority_test);
12741274

1275-
generate_blocks(HARDFORK_1268_TIME);
1276-
generate_block();
1277-
12781275
GET_ACTOR(bob);
12791276
fund(bob);
12801277
ACTOR(issuer);
12811278

1282-
additional_asset_options_t options;
1283-
options.value.reward_percent = 2 * GRAPHENE_1_PERCENT;
1284-
1285-
const auto usd = create_user_issued_asset(
1286-
"USD",
1287-
issuer,
1288-
charge_market_fee,
1289-
price(asset(1, asset_id_type(1)), asset(1)),
1290-
1,
1291-
20 * GRAPHENE_1_PERCENT,
1292-
options);
1279+
const auto usd = create_user_issued_asset("USD");
12931280

12941281
issue_uia(issuer, usd.amount(2000));
12951282
transfer(issuer, bob, usd.amount(200));
12961283
transfer(issuer, GRAPHENE_COMMITTEE_ACCOUNT(db), usd.amount(200));
12971284

1298-
std::map<asset_id_type, share_type> bob_balance_helper;
1299-
std::map<asset_id_type, share_type> committee_balance_helper;
1285+
auto initial_balance_bob_BTS = get_balance(bob_id, asset_id_type());
1286+
auto initial_balance_bob_USD = get_balance(bob_id, usd.get_id());
13001287

1301-
const auto& bal_idx_before = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >();
1302-
for( const auto& entry : bal_idx_before.get_account_balances( bob_id ) )
1303-
{
1304-
const auto balance = entry.second->get_balance();
1305-
bob_balance_helper.emplace(balance.asset_id, balance.amount);
1306-
BOOST_CHECK_GT(balance.amount.value, 0);
1307-
}
1308-
for( const auto& entry : bal_idx_before.get_account_balances( GRAPHENE_COMMITTEE_ACCOUNT ) )
1309-
{
1310-
const auto balance = entry.second->get_balance();
1311-
committee_balance_helper.emplace(balance.asset_id, balance.amount);
1312-
BOOST_CHECK_GT(balance.amount.value, 0);
1313-
}
1314-
1288+
auto initial_balance_committee_BTS = get_balance( GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type());
1289+
auto initial_balance_committee_USD = get_balance( GRAPHENE_COMMITTEE_ACCOUNT, usd.get_id());
1290+
1291+
generate_blocks(HARDFORK_CYCLED_ACCOUNTS_TIME);
13151292
// unlock
13161293
{
13171294
account_unlock_operation op;
@@ -1326,40 +1303,27 @@ BOOST_AUTO_TEST_CASE( unlock_operation_penalty_payment_test )
13261303
PUSH_TX( db, trx );
13271304
}
13281305

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

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

13421312
} FC_LOG_AND_RETHROW()
13431313
}
13441314

1345-
BOOST_AUTO_TEST_CASE(unloc_account_operation_failed_not_enough_BTS)
1315+
BOOST_AUTO_TEST_CASE(unlock_account_operation_failed_not_enough_BTS)
13461316
{
13471317
try
13481318
{
13491319
INVOKE(make_recursive_authority_test);
13501320

1351-
generate_blocks(HARDFORK_1268_TIME);
1321+
generate_blocks(HARDFORK_CYCLED_ACCOUNTS_TIME);
13521322
generate_block();
13531323

13541324
GET_ACTOR(bob);
13551325
enable_fees();
13561326

1357-
std::map<asset_id_type, share_type> bob_balance_helper;
1358-
std::map<asset_id_type, share_type> committee_balance_helper;
1359-
1360-
const auto& bal_idx_before = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >();
1361-
BOOST_CHECK( bal_idx_before.get_account_balances( bob_id ).size() == 0);
1362-
13631327
// unlock
13641328
account_unlock_operation op;
13651329
op.account_to_unlock = bob_id;
@@ -1371,7 +1335,7 @@ BOOST_AUTO_TEST_CASE(unloc_account_operation_failed_not_enough_BTS)
13711335
sign(trx, bob_private_key);
13721336

13731337
GRAPHENE_CHECK_THROW( PUSH_TX( db, trx ), fc::exception );
1374-
1338+
13751339
} FC_LOG_AND_RETHROW()
13761340
}
13771341

0 commit comments

Comments
 (0)