Skip to content

Commit

Permalink
Merge pull request #2258 from AntelopeIO/merge-main-02-22-2024
Browse files Browse the repository at this point in the history
IF: Merge main 02-22-2024
  • Loading branch information
heifner authored Feb 22, 2024
2 parents d6db03c + ca6b561 commit a6d5a98
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 147 deletions.
17 changes: 10 additions & 7 deletions plugins/http_plugin/tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ BOOST_AUTO_TEST_CASE(test_on_loopback) {

BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
http_plugin* http_plugin = init({"--plugin=eosio::http_plugin",
"--http-server-address=127.0.0.1:8888",
"--http-server-address=127.0.0.1:8891",
"--http-max-bytes-in-flight-mb=64"});
BOOST_REQUIRE(http_plugin);

Expand All @@ -600,10 +600,10 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
//we can't control http_plugin's send buffer, but at least we can control our receive buffer size to help increase
// chance of server blocking
s.set_option(boost::asio::socket_base::receive_buffer_size(8*1024));
s.connect(resolver.resolve("127.0.0.1", "8888")->endpoint());
s.connect(resolver.resolve("127.0.0.1", "8891")->endpoint());
boost::beast::http::request<boost::beast::http::empty_body> req(boost::beast::http::verb::get, "/4megabyte", 11);
req.keep_alive(true);
req.set(http::field::host, "127.0.0.1:8888");
req.set(http::field::host, "127.0.0.1:8891");
boost::beast::http::write(s, req);
}
};
Expand Down Expand Up @@ -654,7 +654,7 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {

BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
http_plugin* http_plugin = init({"--plugin=eosio::http_plugin",
"--http-server-address=127.0.0.1:8888",
"--http-server-address=127.0.0.1:8892",
"--http-max-in-flight-requests=16"});
BOOST_REQUIRE(http_plugin);

Expand All @@ -671,10 +671,10 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
auto send_requests = [&](unsigned count) {
for(unsigned i = 0; i < count; ++i) {
boost::asio::ip::tcp::socket& s = connections.emplace_back(ctx, boost::asio::ip::tcp::v4());
boost::asio::connect(s, resolver.resolve("127.0.0.1", "8888"));
boost::asio::connect(s, resolver.resolve("127.0.0.1", "8892"));
boost::beast::http::request<boost::beast::http::empty_body> req(boost::beast::http::verb::get, "/doit", 11);
req.keep_alive(true);
req.set(http::field::host, "127.0.0.1:8888");
req.set(http::field::host, "127.0.0.1:8892");
boost::beast::http::write(s, req);
}
};
Expand Down Expand Up @@ -714,4 +714,7 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
r = scan_http_replies();
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u);
connections.clear();
}
}

//A warning for future tests: destruction of http_plugin_test_fixture sometimes does not destroy http_plugin's listeners. Tests
// added in the future should avoid reusing ports of other tests in http_plugin_unit_tests.
5 changes: 4 additions & 1 deletion plugins/trace_api_plugin/abi_data_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ namespace eosio::trace_api {
auto params = serializer_p->binary_to_variant(type_name, action.data, abi_yield);
if constexpr (std::is_same_v<T, action_trace_v1>) {
if(action.return_value.size() > 0) {
ret_data = serializer_p->binary_to_variant(type_name, action.return_value, abi_yield);
auto return_type_name = serializer_p->get_action_result_type(action_name);
if (!return_type_name.empty()) {
ret_data = serializer_p->binary_to_variant(return_type_name, action.return_value, abi_yield);
}
}
}
return {params, ret_data};
Expand Down
7 changes: 2 additions & 5 deletions plugins/trace_api_plugin/request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,22 @@ namespace {
});
for ( int index : indices) {
const auto& a = actions.at(index);
auto common_mvo = fc::mutable_variant_object();
auto action_variant = fc::mutable_variant_object();

common_mvo("global_sequence", a.global_sequence)
action_variant("global_sequence", a.global_sequence)
("receiver", a.receiver.to_string())
("account", a.account.to_string())
("action", a.action.to_string())
("authorization", process_authorizations(a.authorization))
("data", fc::to_hex(a.data.data(), a.data.size()));

auto action_variant = fc::mutable_variant_object();
if constexpr(std::is_same_v<ActionTrace, action_trace_v0>){
action_variant(std::move(common_mvo));
auto [params, return_data] = data_handler(a);
if (!params.is_null()) {
action_variant("params", params);
}
}
else if constexpr(std::is_same_v<ActionTrace, action_trace_v1>){
action_variant(std::move(common_mvo));
action_variant("return_value", fc::to_hex(a.return_value.data(),a.return_value.size())) ;
auto [params, return_data] = data_handler(a);
if (!params.is_null()) {
Expand Down
57 changes: 55 additions & 2 deletions plugins/trace_api_plugin/test/test_data_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(empty_data_v1)
Expand All @@ -36,6 +37,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(no_abi)
Expand All @@ -50,6 +52,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(no_abi_v1)
Expand All @@ -65,6 +68,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(basic_abi)
Expand Down Expand Up @@ -98,27 +102,30 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(basic_abi_v1)
{
auto action = action_trace_v1 {
{ 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}},
{0x04, 0x05, 0x06, 0x07}
{0x04, 0x05, 0x06}
};

std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;

auto abi = chain::abi_def ( {},
{
{ "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } }
{ "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } },
{ "foor", "", { {"e", "varuint32"}, {"f", "varuint32"}, {"g", "varuint32"} } }
},
{
{ "foo"_n, "foo", ""}
},
{}, {}, {}
);
abi.version = "eosio::abi/1.";
abi.action_results = { std::vector<chain::action_result_def>{ chain::action_result_def{ "foo"_n, "foor"} } };

abi_data_handler handler(exception_handler{});
handler.add_abi("alice"_n, std::move(abi));
Expand All @@ -128,10 +135,16 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
("b", 1)
("c", 2)
("d", 3);
fc::variant expected_return = fc::mutable_variant_object()
("e", 4)
("f", 5)
("g", 6);

auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(std::get<1>(actual));
BOOST_TEST(to_kv(expected_return) == to_kv(*std::get<1>(actual)), boost::test_tools::per_element());
}

BOOST_AUTO_TEST_CASE(basic_abi_wrong_type)
Expand Down Expand Up @@ -161,6 +174,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(basic_abi_wrong_type_v1)
Expand Down Expand Up @@ -190,6 +204,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}

BOOST_AUTO_TEST_CASE(basic_abi_insufficient_data)
Expand Down Expand Up @@ -221,6 +236,44 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_TEST(log_called);
BOOST_REQUIRE(!std::get<1>(actual));
}

// If no ABI provided for return type then do not attempt to decode it
BOOST_AUTO_TEST_CASE(basic_abi_no_return_abi_when_return_value_provided)
{
auto action = action_trace_v1 {
{ 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}},
{0x04, 0x05, 0x06}
};

std::variant<action_trace_v0, action_trace_v1> action_trace_t = action;

auto abi = chain::abi_def ( {},
{
{ "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } },
},
{
{ "foo"_n, "foo", ""}
},
{}, {}, {}
);
abi.version = "eosio::abi/1.";

abi_data_handler handler(exception_handler{});
handler.add_abi("alice"_n, std::move(abi));

fc::variant expected = fc::mutable_variant_object()
("a", 0)
("b", 1)
("c", 2)
("d", 3);

auto actual = handler.serialize_to_variant(action_trace_t);

BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element());
BOOST_REQUIRE(!std::get<1>(actual));
}


BOOST_AUTO_TEST_SUITE_END()
7 changes: 0 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cli_test.py ${CMAKE_CURRENT_BINARY_DI
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ship_test.py ${CMAKE_CURRENT_BINARY_DIR}/ship_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ship_streamer_test.py ${CMAKE_CURRENT_BINARY_DIR}/ship_streamer_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bridge_for_fork_test_shape.json ${CMAKE_CURRENT_BINARY_DIR}/bridge_for_fork_test_shape.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/large-lib-test.py ${CMAKE_CURRENT_BINARY_DIR}/large-lib-test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib_advance_test.py ${CMAKE_CURRENT_BINARY_DIR}/lib_advance_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/http_plugin_test.py ${CMAKE_CURRENT_BINARY_DIR}/http_plugin_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/p2p_high_latency_test.py ${CMAKE_CURRENT_BINARY_DIR}/p2p_high_latency_test.py COPYONLY)
Expand Down Expand Up @@ -331,12 +330,6 @@ set_property(TEST nodeos_retry_transaction_if_lr_test PROPERTY LABELS long_runni
add_test(NAME cli_test COMMAND tests/cli_test.py WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST cli_test PROPERTY LABELS nonparallelizable_tests)

# following test removed (both if and dpos versions) - see https://github.com/AntelopeIO/leap/issues/2232
#add_test(NAME larger_lib_test COMMAND tests/large-lib-test.py ${UNSHARE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
#set_property(TEST larger_lib_test PROPERTY LABELS nonparallelizable_tests)
#add_test(NAME larger_lib_if_test COMMAND tests/large-lib-test.py --activate-if ${UNSHARE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
#set_property(TEST larger_lib_if_test PROPERTY LABELS nonparallelizable_tests)

add_test(NAME lib_advance_test COMMAND tests/lib_advance_test.py -v ${UNSHARE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST lib_advance_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME lib_advance_if_test COMMAND tests/lib_advance_test.py --activate-if -v ${UNSHARE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
125 changes: 0 additions & 125 deletions tests/large-lib-test.py

This file was deleted.

0 comments on commit a6d5a98

Please sign in to comment.