Skip to content

Commit 614c1e1

Browse files
author
Andrianto Lie
committed
Fix unit tests
1 parent e27c304 commit 614c1e1

File tree

7 files changed

+55
-62
lines changed

7 files changed

+55
-62
lines changed

libraries/chain/include/eosio/chain/block_timestamp.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <fc/variant.hpp>
77
#include <fc/string.hpp>
88
#include <fc/optional.hpp>
9-
#include <eosio/chain/exceptions.hpp>
9+
#include <fc/exception/exception.hpp>
1010

1111
namespace eosio { namespace chain {
1212

@@ -32,7 +32,7 @@ namespace eosio { namespace chain {
3232
static block_timestamp min() { return block_timestamp(0); }
3333

3434
block_timestamp next() const {
35-
EOS_ASSERT( std::numeric_limits<uint32_t>::max() - slot >= 1, overflow_exception, "block timestamp overflow" );
35+
EOS_ASSERT( std::numeric_limits<uint32_t>::max() - slot >= 1, fc::overflow_exception, "block timestamp overflow" );
3636
auto result = block_timestamp(*this);
3737
result.slot += 1;
3838
return result;

libraries/chain/include/eosio/chain/exceptions.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,10 @@ namespace eosio { namespace chain {
297297
3100005, "Extracted genesis state from blocks.log" )
298298
FC_DECLARE_DERIVED_EXCEPTION( subjective_block_production_exception, misc_exception,
299299
3100006, "Subjective exception thrown during block production" )
300-
FC_DECLARE_DERIVED_EXCEPTION( overflow_exception, misc_exception,
301-
3100007, "Oveflow" )
302300
FC_DECLARE_DERIVED_EXCEPTION( multiple_voter_info, misc_exception,
303-
3100008, "Multiple voter info detected" )
301+
3100007, "Multiple voter info detected" )
304302
FC_DECLARE_DERIVED_EXCEPTION( unsupported_feature, misc_exception,
305-
3100009, "Feature is currently unsupported" )
303+
3100008, "Feature is currently unsupported" )
306304

307305

308306

unittests/abi_tests.cpp

+14-17
Original file line numberDiff line numberDiff line change
@@ -2048,14 +2048,14 @@ BOOST_AUTO_TEST_CASE(abi_cycle)
20482048

20492049
auto abi = eosio_contract_abi(fc::json::from_string(typedef_cycle_abi).as<abi_def>());
20502050

2051-
auto is_assert_exception = [](fc::assert_exception const & e) -> bool {
2051+
auto is_assert_exception = [](const auto& e) -> bool {
20522052
wlog(e.to_string()); return true;
20532053
};
2054-
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), fc::assert_exception, is_assert_exception );
2054+
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), duplicate_abi_type_def_exception, is_assert_exception);
20552055

20562056
abi = fc::json::from_string(struct_cycle_abi).as<abi_def>();
20572057
abi_serializer abis;
2058-
BOOST_CHECK_EXCEPTION( abis.set_abi(abi, max_serialization_time), fc::assert_exception, is_assert_exception );
2058+
BOOST_CHECK_EXCEPTION( abis.set_abi(abi, max_serialization_time), abi_circular_def_exception, is_assert_exception );
20592059

20602060
} FC_LOG_AND_RETHROW() }
20612061

@@ -2895,8 +2895,8 @@ BOOST_AUTO_TEST_CASE(abi_type_repeat)
28952895
)=====";
28962896

28972897
auto abi = eosio_contract_abi(fc::json::from_string(repeat_abi).as<abi_def>());
2898-
auto is_table_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
2899-
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), fc::assert_exception, is_table_exception );
2898+
auto is_table_exception = [](fc::exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
2899+
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), duplicate_abi_type_def_exception, is_table_exception );
29002900
} FC_LOG_AND_RETHROW() }
29012901

29022902
BOOST_AUTO_TEST_CASE(abi_struct_repeat)
@@ -2952,8 +2952,7 @@ BOOST_AUTO_TEST_CASE(abi_struct_repeat)
29522952
)=====";
29532953

29542954
auto abi = eosio_contract_abi(fc::json::from_string(repeat_abi).as<abi_def>());
2955-
auto is_table_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("structs.size") != std::string::npos; };
2956-
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), fc::assert_exception, is_table_exception );
2955+
BOOST_CHECK_THROW( abi_serializer abis(abi, max_serialization_time), duplicate_abi_struct_def_exception );
29572956
} FC_LOG_AND_RETHROW() }
29582957

29592958
BOOST_AUTO_TEST_CASE(abi_action_repeat)
@@ -3012,8 +3011,7 @@ BOOST_AUTO_TEST_CASE(abi_action_repeat)
30123011
)=====";
30133012

30143013
auto abi = eosio_contract_abi(fc::json::from_string(repeat_abi).as<abi_def>());
3015-
auto is_table_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("actions.size") != std::string::npos; };
3016-
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), fc::assert_exception, is_table_exception );
3014+
BOOST_CHECK_THROW( abi_serializer abis(abi, max_serialization_time), duplicate_abi_action_def_exception );
30173015
} FC_LOG_AND_RETHROW() }
30183016

30193017
BOOST_AUTO_TEST_CASE(abi_table_repeat)
@@ -3075,8 +3073,7 @@ BOOST_AUTO_TEST_CASE(abi_table_repeat)
30753073
)=====";
30763074

30773075
auto abi = eosio_contract_abi(fc::json::from_string(repeat_abi).as<abi_def>());
3078-
auto is_table_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("tables.size") != std::string::npos; };
3079-
BOOST_CHECK_EXCEPTION( abi_serializer abis(abi, max_serialization_time), fc::assert_exception, is_table_exception );
3076+
BOOST_CHECK_THROW( abi_serializer abis(abi, max_serialization_time), duplicate_abi_table_def_exception );
30803077
} FC_LOG_AND_RETHROW() }
30813078

30823079
BOOST_AUTO_TEST_CASE(abi_type_def)
@@ -3169,8 +3166,8 @@ BOOST_AUTO_TEST_CASE(abi_type_loop)
31693166
}
31703167
)=====";
31713168

3172-
auto is_type_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
3173-
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), fc::assert_exception, is_type_exception );
3169+
auto is_type_exception = [](fc::exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
3170+
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), duplicate_abi_type_def_exception, is_type_exception );
31743171

31753172
} FC_LOG_AND_RETHROW() }
31763173

@@ -3209,8 +3206,8 @@ BOOST_AUTO_TEST_CASE(abi_type_redefine)
32093206
}
32103207
)=====";
32113208

3212-
auto is_type_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("invalid type") != std::string::npos; };
3213-
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), fc::assert_exception, is_type_exception );
3209+
auto is_type_exception = [](fc::exception const & e) -> bool { return e.to_detail_string().find("invalid type") != std::string::npos; };
3210+
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), invalid_type_inside_abi, is_type_exception );
32143211

32153212
} FC_LOG_AND_RETHROW() }
32163213

@@ -3230,8 +3227,8 @@ BOOST_AUTO_TEST_CASE(abi_type_redefine_to_name)
32303227
}
32313228
)=====";
32323229

3233-
auto is_type_exception = [](fc::assert_exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
3234-
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), fc::assert_exception, is_type_exception );
3230+
auto is_type_exception = [](fc::exception const & e) -> bool { return e.to_detail_string().find("type already exists") != std::string::npos; };
3231+
BOOST_CHECK_EXCEPTION( abi_serializer abis(fc::json::from_string(repeat_abi).as<abi_def>(), max_serialization_time), duplicate_abi_type_def_exception, is_type_exception );
32353232

32363233
} FC_LOG_AND_RETHROW() }
32373234

unittests/api_tests.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try {
426426
CALL_TEST_FUNCTION( *this, "test_action", "test_publication_time", fc::raw::pack(pub_time) );
427427

428428
// test test_abort
429-
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "test_abort", {} ), assert_exception,
429+
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_action", "test_abort", {} ), abort_called,
430430
[](const fc::exception& e) {
431431
return expect_assert_message(e, "abort() called");
432432
}
@@ -496,7 +496,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try {
496496
set_transaction_headers(trx);
497497
// run (dummy_action.b = 200) case looking for invalid use of context_free api
498498
sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id());
499-
BOOST_CHECK_EXCEPTION(push_transaction(trx), assert_exception,
499+
BOOST_CHECK_EXCEPTION(push_transaction(trx), unaccessible_api,
500500
[](const fc::exception& e) {
501501
return expect_assert_message(e, "this API may only be called from context_free apply");
502502
}
@@ -521,7 +521,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try {
521521
trx.signatures.clear();
522522
set_transaction_headers(trx);
523523
sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id());
524-
BOOST_CHECK_EXCEPTION(push_transaction(trx), assert_exception,
524+
BOOST_CHECK_EXCEPTION(push_transaction(trx), unaccessible_api,
525525
[](const fc::exception& e) {
526526
return expect_assert_message(e, "only context free api's can be used in this context" );
527527
}
@@ -872,7 +872,7 @@ BOOST_FIXTURE_TEST_CASE(compiler_builtins_tests, TESTER) { try {
872872
CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_divti3", {});
873873

874874
// test test_divti3_by_0
875-
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_divti3_by_0", {}), assert_exception,
875+
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_divti3_by_0", {}), arithmetic_exception,
876876
[](const fc::exception& e) {
877877
return expect_assert_message(e, "divide by zero");
878878
}
@@ -882,7 +882,7 @@ BOOST_FIXTURE_TEST_CASE(compiler_builtins_tests, TESTER) { try {
882882
CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_udivti3", {});
883883

884884
// test test_udivti3_by_0
885-
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_udivti3_by_0", {}), assert_exception,
885+
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_udivti3_by_0", {}), arithmetic_exception,
886886
[](const fc::exception& e) {
887887
return expect_assert_message(e, "divide by zero");
888888
}
@@ -892,7 +892,7 @@ BOOST_FIXTURE_TEST_CASE(compiler_builtins_tests, TESTER) { try {
892892
CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_modti3", {});
893893

894894
// test test_modti3_by_0
895-
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_modti3_by_0", {}), assert_exception,
895+
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_compiler_builtins", "test_modti3_by_0", {}), arithmetic_exception,
896896
[](const fc::exception& e) {
897897
return expect_assert_message(e, "divide by zero");
898898
}
@@ -946,9 +946,9 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, TESTER) { try {
946946
CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_empty", {});
947947

948948
// test send_action_large
949-
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_large", {}), assert_exception,
949+
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_large", {}), inline_action_too_big,
950950
[](const fc::exception& e) {
951-
return expect_assert_message(e, "data_len < context.control.get_global_properties().configuration.max_inline_action_size: inline action too big");
951+
return expect_assert_message(e, "inline action too big");
952952
}
953953
);
954954

@@ -1417,7 +1417,7 @@ BOOST_FIXTURE_TEST_CASE(crypto_tests, TESTER) { try {
14171417
CALL_TEST_FUNCTION( *this, "test_crypto", "test_recover_key_assert_true", payload );
14181418
payload[payload.size()-1] = 0;
14191419
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_crypto", "test_recover_key_assert_false", payload ),
1420-
fc::assert_exception, fc_assert_exception_message_is("Error expected key different than recovered key") );
1420+
crypto_api_exception, fc_exception_message_is("Error expected key different than recovered key") );
14211421
}
14221422

14231423
CALL_TEST_FUNCTION( *this, "test_crypto", "test_sha1", {} );
@@ -1430,22 +1430,22 @@ BOOST_FIXTURE_TEST_CASE(crypto_tests, TESTER) { try {
14301430
CALL_TEST_FUNCTION( *this, "test_crypto", "ripemd160_no_data", {} );
14311431

14321432
CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION( *this, "test_crypto", "assert_sha256_false", {},
1433-
assert_exception, "hash mismatch" );
1433+
crypto_api_exception, "hash mismatch" );
14341434

14351435
CALL_TEST_FUNCTION( *this, "test_crypto", "assert_sha256_true", {} );
14361436

14371437
CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION( *this, "test_crypto", "assert_sha1_false", {},
1438-
assert_exception, "hash mismatch" );
1438+
crypto_api_exception, "hash mismatch" );
14391439

14401440
CALL_TEST_FUNCTION( *this, "test_crypto", "assert_sha1_true", {} );
14411441

14421442
CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION( *this, "test_crypto", "assert_sha512_false", {},
1443-
assert_exception, "hash mismatch" );
1443+
crypto_api_exception, "hash mismatch" );
14441444

14451445
CALL_TEST_FUNCTION( *this, "test_crypto", "assert_sha512_true", {} );
14461446

14471447
CALL_TEST_FUNCTION_AND_CHECK_EXCEPTION( *this, "test_crypto", "assert_ripemd160_false", {},
1448-
assert_exception, "hash mismatch" );
1448+
crypto_api_exception, "hash mismatch" );
14491449

14501450
CALL_TEST_FUNCTION( *this, "test_crypto", "assert_ripemd160_true", {} );
14511451

@@ -1886,15 +1886,15 @@ BOOST_FIXTURE_TEST_CASE(new_api_feature_tests, TESTER) { try {
18861886
produce_blocks(1);
18871887

18881888
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "new_feature", {} ),
1889-
assert_exception,
1889+
unaccessible_api,
18901890
[](const fc::exception& e) {
1891-
return expect_assert_message(e, "context.privileged: testapi does not have permission to call this API");
1891+
return expect_assert_message(e, "testapi does not have permission to call this API");
18921892
});
18931893

18941894
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "active_new_feature", {} ),
1895-
assert_exception,
1895+
unaccessible_api,
18961896
[](const fc::exception& e) {
1897-
return expect_assert_message(e, "context.privileged: testapi does not have permission to call this API");
1897+
return expect_assert_message(e, "testapi does not have permission to call this API");
18981898
});
18991899

19001900
// change privilege
@@ -1919,7 +1919,7 @@ BOOST_FIXTURE_TEST_CASE(new_api_feature_tests, TESTER) { try {
19191919
CALL_TEST_FUNCTION( *this, "test_transaction", "new_feature", {} );
19201920

19211921
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "active_new_feature", {} ),
1922-
assert_exception,
1922+
unsupported_feature,
19231923
[](const fc::exception& e) {
19241924
return expect_assert_message(e, "Unsupported Hardfork Detected");
19251925
});

unittests/auth_tests.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,15 @@ BOOST_AUTO_TEST_CASE( linkauth_special ) { try {
499499
);
500500

501501
auto validate_disallow = [&] (const char *type) {
502-
BOOST_REQUIRE_EXCEPTION(
503-
chain.push_action(config::system_account_name, linkauth::get_name(), tester_account, fc::mutable_variant_object()
504-
("account", "tester")
505-
("code", "eosio")
506-
("type", type)
507-
("requirement", "first")),
508-
action_validate_exception,
509-
[] (const action_validate_exception &ex)->bool {
510-
BOOST_REQUIRE_EQUAL(std::string("action exception"), ex.what());
511-
return true;
512-
});
502+
BOOST_REQUIRE_EXCEPTION(
503+
chain.push_action(config::system_account_name, linkauth::get_name(), tester_account, fc::mutable_variant_object()
504+
("account", "tester")
505+
("code", "eosio")
506+
("type", type)
507+
("requirement", "first")),
508+
action_validate_exception,
509+
fc_exception_message_is(std::string("Cannot link eosio::") + std::string(type) + std::string(" to a minimum permission"))
510+
);
513511
};
514512

515513
validate_disallow("linkauth");

unittests/currency_tests.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
298298
// from empty string
299299
{
300300
BOOST_CHECK_EXCEPTION(symbol::from_string(""),
301-
fc::assert_exception, fc_assert_exception_message_is("creating symbol from empty string"));
301+
symbol_type_exception, fc_exception_message_is("creating symbol from empty string"));
302302
}
303303

304304
// precision part missing
305305
{
306306
BOOST_CHECK_EXCEPTION(symbol::from_string("RND"),
307-
fc::assert_exception, fc_assert_exception_message_is("missing comma in symbol"));
307+
symbol_type_exception, fc_exception_message_is("missing comma in symbol"));
308308
}
309309

310310
// 0 decimals part
@@ -317,13 +317,13 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
317317
// invalid - contains lower case characters, no validation
318318
{
319319
BOOST_CHECK_EXCEPTION(symbol malformed(SY(6,EoS)),
320-
fc::assert_exception, fc_assert_exception_message_is("invalid symbol: EoS"));
320+
symbol_type_exception, fc_exception_message_is("invalid symbol: EoS"));
321321
}
322322

323323
// invalid - contains lower case characters, exception thrown
324324
{
325325
BOOST_CHECK_EXCEPTION(symbol(5,"EoS"),
326-
fc::assert_exception, fc_assert_exception_message_is("invalid character in symbol name"));
326+
symbol_type_exception, fc_exception_message_is("invalid character in symbol name"));
327327
}
328328

329329
// Missing decimal point, should create asset with 0 decimals

unittests/misc_tests.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
110110
asset a;
111111

112112
// precision = 19, magnitude < 2^61
113-
BOOST_CHECK_EXCEPTION( asset::from_string("0.1000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
113+
BOOST_CHECK_EXCEPTION( asset::from_string("0.1000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
114114
return expect_assert_message(e, "precision 19 should be <= 18");
115115
});
116-
BOOST_CHECK_EXCEPTION( asset::from_string("-0.1000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
116+
BOOST_CHECK_EXCEPTION( asset::from_string("-0.1000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
117117
return expect_assert_message(e, "precision 19 should be <= 18");
118118
});
119-
BOOST_CHECK_EXCEPTION( asset::from_string("1.0000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
119+
BOOST_CHECK_EXCEPTION( asset::from_string("1.0000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
120120
return expect_assert_message(e, "precision 19 should be <= 18");
121121
});
122-
BOOST_CHECK_EXCEPTION( asset::from_string("-1.0000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
122+
BOOST_CHECK_EXCEPTION( asset::from_string("-1.0000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
123123
return expect_assert_message(e, "precision 19 should be <= 18");
124124
});
125125

@@ -188,10 +188,10 @@ BOOST_AUTO_TEST_CASE(asset_from_string_overflow)
188188
});
189189

190190
// precision = 20, magnitude > 2^142
191-
BOOST_CHECK_EXCEPTION( asset::from_string("100000000000000000000000.00000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
191+
BOOST_CHECK_EXCEPTION( asset::from_string("100000000000000000000000.00000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
192192
return expect_assert_message(e, "precision 20 should be <= 18");
193193
});
194-
BOOST_CHECK_EXCEPTION( asset::from_string("-100000000000000000000000.00000000000000000000 CUR") , assert_exception, [](const assert_exception& e) {
194+
BOOST_CHECK_EXCEPTION( asset::from_string("-100000000000000000000000.00000000000000000000 CUR") , symbol_type_exception, [](const auto& e) {
195195
return expect_assert_message(e, "precision 20 should be <= 18");
196196
});
197197
}

0 commit comments

Comments
 (0)