Skip to content

Commit 55efd7e

Browse files
author
ABW
committed
remove unused macros from database_fixture.hpp and fix remaining
Each call to macro with parameters now needs to be followed by semicolon.
1 parent 6516ee9 commit 55efd7e

21 files changed

Lines changed: 272 additions & 354 deletions

tests/unit/db_fixture/database_fixture.hpp

Lines changed: 14 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,11 @@ extern uint32_t HIVE_TESTING_GENESIS_TIMESTAMP;
3737
#define GENERATE_BLOCK \
3838
hive::chain::test::_generate_block
3939

40-
// See below
41-
#define REQUIRE_OP_VALIDATION_SUCCESS( op, field, value ) \
42-
{ \
43-
const auto temp = op.field; \
44-
op.field = value; \
45-
op.validate(); \
46-
op.field = temp; \
47-
}
48-
#define REQUIRE_OP_EVALUATION_SUCCESS( op, field, value ) \
49-
{ \
50-
const auto temp = op.field; \
51-
op.field = value; \
52-
trx.operations.back() = op; \
53-
op.field = temp; \
54-
push_transaction( trx, fc::ecc::private_key(), ~0 ); \
55-
}
56-
57-
/*#define HIVE_REQUIRE_THROW( expr, exc_type ) \
58-
{ \
59-
std::string req_throw_info = fc::json::to_string( \
60-
fc::mutable_variant_object() \
61-
("source_file", __FILE__) \
62-
("source_lineno", __LINE__) \
63-
("expr", #expr) \
64-
("exc_type", #exc_type) \
65-
); \
66-
if( fc::enable_record_assert_trip ) \
67-
std::cout << "HIVE_REQUIRE_THROW begin " \
68-
<< req_throw_info << std::endl; \
69-
BOOST_REQUIRE_THROW( expr, exc_type ); \
70-
if( fc::enable_record_assert_trip ) \
71-
std::cout << "HIVE_REQUIRE_THROW end " \
72-
<< req_throw_info << std::endl; \
73-
}*/
74-
7540
#define HIVE_REQUIRE_THROW( expr, exc_type ) \
76-
BOOST_REQUIRE_THROW( expr, exc_type );
41+
BOOST_REQUIRE_THROW( expr, exc_type )
7742

7843
#define HIVE_CHECK_THROW( expr, exc_type ) \
79-
{ \
44+
do { \
8045
std::string req_throw_info = fc::json::to_string( \
8146
fc::mutable_variant_object() \
8247
("source_file", __FILE__) \
@@ -91,7 +56,7 @@ extern uint32_t HIVE_TESTING_GENESIS_TIMESTAMP;
9156
if( fc::enable_record_assert_trip ) \
9257
std::cout << "HIVE_CHECK_THROW end " \
9358
<< req_throw_info << std::endl; \
94-
}
59+
} while(false)
9560

9661
#define HIVE_REQUIRE_EXCEPTION( expr, assert_test, ex_type ) \
9762
do { \
@@ -105,35 +70,6 @@ do { \
10570
#define HIVE_REQUIRE_ASSERT( expr, assert_test ) HIVE_REQUIRE_EXCEPTION( expr, assert_test, fc::assert_exception )
10671
#define HIVE_REQUIRE_CHAINBASE_ASSERT( expr, assert_msg ) HIVE_REQUIRE_EXCEPTION( expr, assert_msg, fc::exception )
10772

108-
#define REQUIRE_OP_VALIDATION_FAILURE_2( op, field, value, exc_type ) \
109-
{ \
110-
const auto temp = op.field; \
111-
op.field = value; \
112-
HIVE_REQUIRE_THROW( op.validate(), exc_type ); \
113-
op.field = temp; \
114-
}
115-
#define REQUIRE_OP_VALIDATION_FAILURE( op, field, value ) \
116-
REQUIRE_OP_VALIDATION_FAILURE_2( op, field, value, fc::exception )
117-
118-
#define REQUIRE_THROW_WITH_VALUE_2(op, field, value, exc_type) \
119-
{ \
120-
auto bak = op.field; \
121-
op.field = value; \
122-
trx.operations.back() = op; \
123-
op.field = bak; \
124-
HIVE_REQUIRE_THROW(push_transaction(trx, ~0), exc_type); \
125-
}
126-
127-
#define REQUIRE_THROW_WITH_VALUE( op, field, value ) \
128-
REQUIRE_THROW_WITH_VALUE_2( op, field, value, fc::exception )
129-
130-
///This simply resets v back to its default-constructed value. Requires v to have a working assignment operator and
131-
/// default constructor.
132-
#define RESET(v) v = decltype(v)()
133-
///This allows me to build consecutive test cases. It's pretty ugly, but it works well enough for unit tests.
134-
/// i.e. This allows a test on update_account to begin with the database at the end state of create_account.
135-
#define INVOKE(test) ((struct test*)this)->test_method(); trx.clear()
136-
13773
// Default amount of VESTS (expressed in HIVE) implicitly granted to accounts created via ACTOR(S)
13874
// macros. Most tests are not sensitive to the exact value; tests that are should pass an explicit
13975
// amount (or NO_VESTING) and verify the chosen value does not change their results.
@@ -144,55 +80,37 @@ do { \
14480
#define PREP_ACTOR(name) \
14581
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name)); \
14682
fc::ecc::private_key name ## _post_key = generate_private_key(std::string( BOOST_PP_STRINGIZE(name) ) + "_post" ); \
147-
public_key_type name ## _public_key = name ## _private_key.get_public_key();
83+
public_key_type name ## _public_key = name ## _private_key.get_public_key()
14884

14985
#define ACTOR(initial_vesting, name) \
150-
PREP_ACTOR(name) \
86+
PREP_ACTOR(name); \
15187
account_create(BOOST_PP_STRINGIZE(name), name ## _public_key, name ## _post_key.get_public_key(), initial_vesting); \
152-
account_id_type name ## _id = get_account_id(BOOST_PP_STRINGIZE(name)); (void)name ## _id;
88+
account_id_type name ## _id = get_account_id(BOOST_PP_STRINGIZE(name)); (void)name ## _id
15389

154-
#define ACTORS_IMPL(r, data, elem) ACTOR(data, elem)
90+
#define ACTORS_IMPL(r, data, elem) ACTOR(data, elem);
15591
#define ACTORS(initial_vesting, names) BOOST_PP_SEQ_FOR_EACH(ACTORS_IMPL, initial_vesting, names) \
156-
validate_database();
92+
validate_database()
15793

15894
#define PREP_ACTOR_EXT(object, name) \
15995
fc::ecc::private_key name ## _private_key = object.generate_private_key(BOOST_PP_STRINGIZE(name)); \
16096
fc::ecc::private_key name ## _post_key = object.generate_private_key(std::string( BOOST_PP_STRINGIZE(name) ) + "_post" ); \
161-
public_key_type name ## _public_key = name ## _private_key.get_public_key();
97+
public_key_type name ## _public_key = name ## _private_key.get_public_key()
16298

16399
#define ACTOR_EXT(object, initial_vesting, name) \
164-
PREP_ACTOR_EXT(object, name) \
100+
PREP_ACTOR_EXT(object, name); \
165101
object.account_create(BOOST_PP_STRINGIZE(name), name ## _public_key, name ## _post_key.get_public_key(), initial_vesting); \
166-
account_id_type name ## _id = object.get_account_id(BOOST_PP_STRINGIZE(name)); (void)name ## _id;
102+
account_id_type name ## _id = object.get_account_id(BOOST_PP_STRINGIZE(name)); (void)name ## _id
167103

168-
#define ACTORS_EXT_IMPL(r, data, elem) ACTOR_EXT(BOOST_PP_TUPLE_ELEM(2, 0, data), BOOST_PP_TUPLE_ELEM(2, 1, data), elem)
104+
#define ACTORS_EXT_IMPL(r, data, elem) ACTOR_EXT(BOOST_PP_TUPLE_ELEM(2, 0, data), BOOST_PP_TUPLE_ELEM(2, 1, data), elem);
169105
#define ACTORS_EXT(object, initial_vesting, names) BOOST_PP_SEQ_FOR_EACH(ACTORS_EXT_IMPL, (object, initial_vesting), names) \
170-
object.validate_database();
106+
object.validate_database()
171107

172108
#define ASSET( s ) \
173109
hive::protocol::legacy_asset::from_string( s ).to_asset()
174110

175111
#define ISSUE_FUNDS( account_name, _asset ) \
176112
issue_funds( account_name, _asset ); \
177-
generate_block();
178-
179-
#define OP2TX(OP,TX) \
180-
TX.operations.push_back( OP ); \
181-
TX.set_expiration( db->head_block_time() + HIVE_MAX_TIME_UNTIL_EXPIRATION );
182-
183-
#define PUSH_OP(OP,KEY) \
184-
{ \
185-
signed_transaction tx; \
186-
OP2TX(OP,tx) \
187-
push_transaction( tx, KEY ); \
188-
}
189-
190-
#define FAIL_WITH_OP(OP,KEY,EXCEPTION) \
191-
{ \
192-
signed_transaction tx; \
193-
OP2TX(OP,tx) \
194-
HIVE_REQUIRE_THROW( push_transaction( tx, KEY ), EXCEPTION ); \
195-
}
113+
generate_block()
196114

197115
namespace hive { namespace chain {
198116

tests/unit/plugin_tests/condenser_api_fixture.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void condenser_api_fixture::hf12_scenario( check_point_tester_t check_point_test
119119
db->set_hardfork( HIVE_HARDFORK_0_12 );
120120
generate_block(); // block 1
121121

122-
PREP_ACTOR( carol0ah )
122+
PREP_ACTOR( carol0ah );
123123
create_with_pow( "carol0ah", carol0ah_public_key, carol0ah_private_key );
124124
witness_plugin->add_signing_key( carol0ah_private_key );
125125

@@ -132,11 +132,11 @@ void condenser_api_fixture::hf13_scenario( check_point_tester_t check_point_1_te
132132
vest( HIVE_INIT_MINER_NAME, HIVE_asset( 1'000'000 ) );
133133
generate_block();
134134

135-
PREP_ACTOR( dan0ah )
135+
PREP_ACTOR( dan0ah );
136136
create_with_pow2( "dan0ah", dan0ah_public_key, dan0ah_private_key );
137137
witness_plugin->add_signing_key( dan0ah_private_key );
138138

139-
PREP_ACTOR( edgar0ah )
139+
PREP_ACTOR( edgar0ah );
140140
create_with_delegation( HIVE_INIT_MINER_NAME, "edgar0ah", edgar0ah_public_key, edgar0ah_post_key, VEST_asset( 100'000'000'000'000 ), init_account_priv_key );
141141

142142
post_comment("edgar0ah", "permlink1", "Title 1", "Body 1", "parentpermlink1", edgar0ah_post_key);
@@ -417,7 +417,7 @@ void condenser_api_fixture::account_scenario( check_point_tester_t check_point_t
417417
fc::optional<authority>(), fc::optional<authority>(), fc::optional<authority>(), alice8ah_private_key );
418418

419419
claim_account( "alice8ah", HIVE_asset( 0 ), alice8ah_private_key );
420-
PREP_ACTOR( ben8ah )
420+
PREP_ACTOR( ben8ah );
421421
create_claimed_account( "alice8ah", "ben8ah", ben8ah_public_key, ben8ah_post_key.get_public_key(), R"~("{"go":"now"}")~", alice8ah_private_key );
422422

423423
vest( "ben8ah", HIVE_asset( 1'000'000 ) );

tests/unit/plugin_tests/condenser_api_reversible_fixture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ condenser_api_reversible_fixture::condenser_api_reversible_fixture()
1212
generate_block();
1313

1414
ACTORS( DEFAULT_VESTING, (top1)(top2)(top3)(top4)(top5)(top6)(top7)(top8)(top9)(top10)
15-
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) )
16-
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) )
15+
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) );
16+
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) );
1717

1818
const auto create_witness = [&]( const std::string& witness_name )
1919
{
@@ -27,7 +27,7 @@ condenser_api_reversible_fixture::condenser_api_reversible_fixture()
2727
for( int i = 1; i <= 10; ++i )
2828
create_witness( "backup" + std::to_string(i) );
2929

30-
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) )
30+
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) );
3131

3232
vest( "whale", HIVE_asset( 500'000'000 ) );
3333

tests/unit/plugin_tests/condenser_api_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ BOOST_AUTO_TEST_CASE( get_witness_schedule_test )
2121
generate_block();
2222

2323
ACTORS( DEFAULT_VESTING, (top1)(top2)(top3)(top4)(top5)(top6)(top7)(top8)(top9)(top10)
24-
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) )
25-
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) )
24+
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) );
25+
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) );
2626

2727
const auto create_witness = [&]( const std::string& witness_name )
2828
{
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( get_witness_schedule_test )
3636
for( int i = 1; i <= 10; ++i )
3737
create_witness( "backup" + std::to_string(i) );
3838

39-
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) )
39+
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) );
4040

4141
vest( "whale", HIVE_asset( 500'000'000 ) );
4242

tests/unit/plugin_tests/database_api_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct database_api_fixture_basic : hived_fixture
3939
db->_log_hardforks = true;
4040

4141
ACTORS( DEFAULT_VESTING, (top1)(top2)(top3)(top4)(top5)(top6)(top7)(top8)(top9)(top10)
42-
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) )
43-
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) )
42+
(top11)(top12)(top13)(top14)(top15)(top16)(top17)(top18)(top19)(top20) );
43+
ACTORS( DEFAULT_VESTING, (backup1)(backup2)(backup3)(backup4)(backup5)(backup6)(backup7)(backup8)(backup9)(backup10) );
4444

4545
const auto create_witness = [&]( const std::string& witness_name )
4646
{
@@ -54,7 +54,7 @@ struct database_api_fixture_basic : hived_fixture
5454
for( int i = 1; i <= 10; ++i )
5555
create_witness( "backup" + std::to_string(i) );
5656

57-
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) )
57+
ACTORS( DEFAULT_VESTING, (whale)(voter1)(voter2)(voter3)(voter4)(voter5)(voter6)(voter7)(voter8)(voter9)(voter10) );
5858

5959
vest( "whale", HIVE_asset( 500'000'000 ) );
6060

tests/unit/plugin_tests/snapshots_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( additional_allocation_after_snapshot_load )
4848
const auto& index = db()->get_index<account_index>();
4949
const size_t initial_allocations = index.get_item_additional_allocation();
5050

51-
ACTOR( NO_VESTING, alice )
51+
ACTOR( NO_VESTING, alice );
5252
generate_block();
5353
ISSUE_FUNDS( "alice", HIVE_asset( 100'000'000 ) );
5454
BOOST_REQUIRE( compare_delayed_vote_count("alice", {}) );

tests/unit/tests/basic_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ BOOST_AUTO_TEST_CASE( additional_allocations )
14701470
const size_t initial_account_allocations = accountIdx.get_item_additional_allocation();
14711471
const size_t all_initial_allocations = get_all_dynamic_alloc();
14721472

1473-
ACTOR( NO_VESTING, alice )
1473+
ACTOR( NO_VESTING, alice );
14741474
generate_block();
14751475
ISSUE_FUNDS( "alice", HIVE_asset( 100'000'000 ) );
14761476
BOOST_REQUIRE_EQUAL( accountIdx.get_item_additional_allocation(), initial_account_allocations );

tests/unit/tests/comments_in_external_storage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE( basic_checks )
6666
{
6767
try
6868
{
69-
ACTORS( DEFAULT_VESTING, (alice)(bob) )
69+
ACTORS( DEFAULT_VESTING, (alice)(bob) );
7070
vest( "alice", HIVE_asset( 10'000 ) );
7171
vest( "bob", HIVE_asset( 10'000 ) );
7272

@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE( nested_comments )
144144
{
145145
try
146146
{
147-
ACTORS( DEFAULT_VESTING, (alice)(bob)(sam)(dave) )
147+
ACTORS( DEFAULT_VESTING, (alice)(bob)(sam)(dave) );
148148
vest( "alice", HIVE_asset( 10'000 ) );
149149
vest( "bob", HIVE_asset( 10'000 ) );
150150
vest( "sam", HIVE_asset( 10'000 ) );

tests/unit/tests/curation_reward_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ struct curation_rewards_handler
276276
(bob10)(bob11)(bob12)(bob13)(bob14)(bob15)(bob16)(bob17)(bob18)(bob19)
277277
(bob20)(bob21)(bob22)(bob23)(bob24)(bob25)(bob26)(bob27)(bob28)(bob29)
278278
(bob30)(bob31)(bob32)(bob33)(bob34)(bob35)(bob36)(bob37)(bob38)(bob39)
279-
)
279+
);
280280

281281
auto _voters =
282282
{
@@ -333,7 +333,7 @@ struct curation_rewards_handler
333333
(dod10)(dod11)(dod12)(dod13)(dod14)(dod15)(dod16)(dod17)(dod18)(dod19)
334334
(dod20)(dod21)(dod22)(dod23)(dod24)(dod25)(dod26)(dod27)(dod28)(dod29)
335335
(dod30)(dod31)(dod32)(dod33)(dod34)(dod35)(dod36)(dod37)(dod38)(dod39)
336-
)
336+
);
337337

338338
auto _voters =
339339
{
@@ -388,7 +388,7 @@ struct curation_rewards_handler
388388
{
389389
ACTORS_EXT( test_object, DEFAULT_VESTING,
390390
(aoa00)(aoa01)(aoa02)(aoa03)(aoa04)(aoa05)(aoa06)(aoa07)(aoa08)(aoa09)
391-
)
391+
);
392392

393393
auto _voters =
394394
{

0 commit comments

Comments
 (0)