Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8822 from EOSIO/merge_minize_logging_from_develop
Browse files Browse the repository at this point in the history
Merge minimize logging changes to 2.0.x
  • Loading branch information
allenhan2 authored Mar 16, 2020
2 parents 1877644 + 4284b37 commit 941a25a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libraries/fc
6 changes: 3 additions & 3 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fc::variant bin_to_variant( const account_name& account, const action_name& acti
return abis->binary_to_variant( action_type, action_args, abi_serializer_max_time );
}

fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_type ptype = fc::json::legacy_parser)
fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_type ptype = fc::json::parse_type::legacy_parser)
{
regex r("^[ \t]*[\{\[]");
if ( !regex_search(file_or_str, r) && fc::is_regular_file(file_or_str) ) {
Expand All @@ -447,7 +447,7 @@ fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_
bytes json_or_file_to_bin( const account_name& account, const action_name& action, const string& data_or_filename ) {
fc::variant action_args_var;
if( !data_or_filename.empty() ) {
action_args_var = json_from_file_or_string(data_or_filename, fc::json::relaxed_parser);
action_args_var = json_from_file_or_string(data_or_filename, fc::json::parse_type::relaxed_parser);
}
return variant_to_bin( account, action, action_args_var );
}
Expand Down Expand Up @@ -3446,7 +3446,7 @@ int main( int argc, char** argv ) {
actionsSubcommand->set_callback([&] {
fc::variant action_args_var;
if( !data.empty() ) {
action_args_var = json_from_file_or_string(data, fc::json::relaxed_parser);
action_args_var = json_from_file_or_string(data, fc::json::parse_type::relaxed_parser);
}
auto accountPermissions = get_account_permissions(tx_permission);

Expand Down
2 changes: 1 addition & 1 deletion programs/eosio-blocklog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void blocklog::read_log() {
(pretty_output.get_object());
fc::variant v(std::move(enhanced_object));
if (no_pretty_print)
fc::json::to_stream(*out, v, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles);
fc::json::to_stream(*out, v, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles);
else
*out << fc::json::to_pretty_string(v) << "\n";
};
Expand Down
4 changes: 2 additions & 2 deletions programs/eosio-launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ launcher_def::write_logging_config_file(tn_node_def &node) {
if( gelf_enabled ) pp.appenders.push_back( "net" );
log_config.loggers.emplace_back( pp );

auto str = fc::json::to_pretty_string( log_config, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles );
auto str = fc::json::to_pretty_string( log_config, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles );
cfg.write( str.c_str(), str.size() );
cfg.close();
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ launcher_def::write_setprods_file() {
if (p.producer_name != "eosio")
no_bios.schedule.push_back(p);
}
auto str = fc::json::to_pretty_string( no_bios, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles );
auto str = fc::json::to_pretty_string( no_bios, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles );
psfile.write( str.c_str(), str.size() );
psfile.close();
}
Expand Down
59 changes: 58 additions & 1 deletion unittests/misc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ BOOST_AUTO_TEST_CASE(variant_format_string_limited)
mu( "b", string( 1024, 'b' ) );
mu( "c", string( 1024, 'c' ) );
string result = fc::format_string( format, mu, true );
BOOST_CHECK_EQUAL( result, string( 256, 'a' ) + "... " + string( 256, 'b' ) + "... " + string( 256, 'c' ) + "..." );
BOOST_CHECK_LT(0, mu.size());
BOOST_CHECK_LT(format.size(), 1024);
const size_t target_size = (1024 - format.size()) / mu.size();
BOOST_CHECK_EQUAL( result, string( target_size, 'a' ) + "... " + string( target_size, 'b' ) + "... " + string( target_size, 'c' ) + "..." );
}
{
fc::mutable_variant_object mu;
Expand All @@ -189,6 +192,60 @@ BOOST_AUTO_TEST_CASE(variant_format_string_limited)
string result = fc::format_string( format, mu, true );
BOOST_CHECK_EQUAL( result, "${a} ${b} ${c}");
}
{
// test cases for issue #8741, short version, all fields being displayed
flat_set <permission_level> provided_permissions;
for(char ch = 'a'; ch < 'c'; ++ch) {
provided_permissions.insert( {name(std::string_view(string(4, ch))), name(std::string_view(string(4, ch + 1)))});
}
flat_set <public_key_type> provided_keys;
auto fill_keys = [](const flat_set <permission_level>& provided_permissions, flat_set <public_key_type>& provided_keys) {
std::string digest = "1234567";
for (auto &permission : provided_permissions) {
digest += "1";
const std::string key_name_str = permission.actor.to_string() + permission.permission.to_string();
auto sig_digest = digest_type::hash(std::make_pair("1234", "abcd"));
const fc::crypto::signature sig = private_key_type::regenerate<fc::ecc::private_key_shim>(
fc::sha256::hash(key_name_str + "active")).sign(sig_digest);
provided_keys.insert(public_key_type{sig, fc::sha256{digest}, true});
}
};
fill_keys(provided_permissions, provided_keys);
const string format = "transaction declares authority '${auth}', provided permissions ${provided_permissions}, provided keys ${provided_keys}";
fc::mutable_variant_object mu;
mu("auth", *provided_permissions.begin());
mu("provided_permissions", provided_permissions);
mu("provided_keys", provided_keys);
BOOST_CHECK_LT(0, mu.size());
const auto arg_limit_size = (1024 - format.size()) / mu.size();
const string result = fc::format_string(format, mu, true);
BOOST_CHECK(provided_permissions.begin() != provided_permissions.end());
const string auth_str = fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum());
string target_str = "transaction declares authority '" + fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum());
target_str += "', provided permissions " + fc::json::to_string(provided_permissions, fc::time_point::maximum());
target_str += ", provided keys " + fc::json::to_string(provided_keys, fc::time_point::maximum()).substr(0, arg_limit_size);
BOOST_CHECK_EQUAL(result, target_str);
BOOST_CHECK_LT(result.size(), 1024 + 3 * mu.size());

// test cases for issue #8741, longer version, permission and keys field being folded
provided_permissions.clear();
provided_keys.clear();
for(char ch = 'c'; ch < 'z'; ++ch) {
provided_permissions.insert( {name(std::string_view(string(5, ch))), name(std::string_view(string(5, ch + 1)))});
}
fill_keys(provided_permissions, provided_keys);
fc::mutable_variant_object mu_fold;
mu_fold("auth", *provided_permissions.begin());
mu_fold("provided_permissions", provided_permissions);
mu_fold("provided_keys", provided_keys);
BOOST_CHECK_LT(0, mu_fold.size());
string target_fold_str = "transaction declares authority '" + fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum());
target_fold_str += "', provided permissions ${provided_permissions}";
target_fold_str += ", provided keys ${provided_keys}";
const string result_fold = fc::format_string(format, mu_fold, true);
BOOST_CHECK_EQUAL(result_fold, target_fold_str);
BOOST_CHECK_LT(result_fold.size(), 1024 + 3 * mu.size());
}
}

// Test overflow handling in asset::from_string
Expand Down

0 comments on commit 941a25a

Please sign in to comment.