Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/trace_api_plugin/abi_data_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ namespace eosio::trace_api_plugin {
}
}

return fc::to_hex(action.data.data(), action.data.size());
return {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace eosio {
*
* @param action - trace of the action including metadata necessary for finding the ABI
* @param deadline - deadline for processing
* @return variant representing the `data` field of the action
* @return variant representing the `data` field of the action interpreted by known ABIs OR an empty variant
*/
fc::variant process_data( const action_trace_v0& action, const fc::time_point& deadline);

Expand Down
20 changes: 13 additions & 7 deletions plugins/trace_api_plugin/request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ namespace {
for ( const auto& a: actions) {
yield();

result.emplace_back(fc::mutable_variant_object()
("receiver", a.receiver.to_string())
("account", a.account.to_string())
("action", a.action.to_string())
("authorization", process_authorizations(a.authorization, std::forward<Yield>(yield)))
("data", data_handler(a))
);
auto action_variant = fc::mutable_variant_object()
("receiver", a.receiver.to_string())
("account", a.account.to_string())
("action", a.action.to_string())
("authorization", process_authorizations(a.authorization, std::forward<Yield>(yield)))
("data", fc::to_hex(a.data.data(), a.data.size()));

auto params = data_handler(a);
if (!params.is_null()) {
action_variant("params", params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be parameters ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

}

result.emplace_back( std::move(action_variant) );
}

return result;
Expand Down
8 changes: 4 additions & 4 deletions plugins/trace_api_plugin/test/test_data_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
};
abi_data_handler handler;

auto expected = fc::variant("");
auto expected = fc::variant();
auto actual = handler.process_data(action, fc::time_point::maximum());

BOOST_TEST(to_kv(expected) == to_kv(actual), boost::test_tools::per_element());
Expand All @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
};
abi_data_handler handler;

auto expected = fc::variant("00010203");
auto expected = fc::variant();
auto actual = handler.process_data(action, fc::time_point::maximum());

BOOST_TEST(to_kv(expected) == to_kv(actual), boost::test_tools::per_element());
Expand Down Expand Up @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
abi_data_handler handler;
handler.add_abi("alice"_n, abi);

auto expected = fc::variant("00010203");
auto expected = fc::variant();

auto actual = handler.process_data(action, fc::time_point::maximum());

Expand Down Expand Up @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests)
abi_data_handler handler([&log_called](const exception_with_context& ){log_called = true;});
handler.add_abi("alice"_n, abi);

auto expected = fc::variant("000102");
auto expected = fc::variant();

auto actual = handler.process_data(action, fc::time_point::maximum());

Expand Down
89 changes: 86 additions & 3 deletions plugins/trace_api_plugin/test/test_responses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,29 @@ struct response_test_fixture {
response_test_fixture& fixture;
};

constexpr static auto default_mock_data_handler = [](const action_trace_v0& a, const fc::time_point&) -> fc::variant {
return fc::mutable_variant_object()("hex" , fc::to_hex(a.data.data(), a.data.size()));
};


struct mock_data_handler_provider {
fc::variant process_data(const action_trace_v0& action, const fc::time_point&) {
return fc::to_hex(action.data.data(), action.data.size());
mock_data_handler_provider(response_test_fixture& fixture)
:fixture(fixture)
{}

fc::variant process_data(const action_trace_v0& action, const fc::time_point& deadline) {
return fixture.mock_data_handler(action, deadline);
}

response_test_fixture& fixture;
};

using response_impl_type = request_handler<mock_logfile_provider, mock_data_handler_provider>;
/**
* TODO: initialize extraction implementation here with `mock_logfile_provider` as template param
*/
response_test_fixture()
: response_impl(mock_logfile_provider(*this), mock_data_handler_provider(), [this]()->fc::time_point { return mock_now(); })
: response_impl(mock_logfile_provider(*this), mock_data_handler_provider(*this), [this]()->fc::time_point { return mock_now(); })
{

}
Expand All @@ -98,6 +109,7 @@ struct response_test_fixture {
std::vector<fc::static_variant<std::exception_ptr, metadata_log_entry>> metadata_log = {};
std::map<uint64_t, fc::static_variant<std::exception_ptr, data_log_entry>> data_log = {};
std::function<fc::time_point()> mock_now = []() -> fc::time_point { return fc::time_point::now(); };
std::function<fc::variant(const action_trace_v0&, const fc::time_point&)> mock_data_handler = default_mock_data_handler;

response_impl_type response_impl;

Expand Down Expand Up @@ -194,6 +206,8 @@ BOOST_AUTO_TEST_SUITE(trace_responses)
("permission", "active")
}))
("data", "00010203")
("params", fc::mutable_variant_object()
("hex", "00010203"))
}))
}))
;
Expand All @@ -203,6 +217,75 @@ BOOST_AUTO_TEST_SUITE(trace_responses)
BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
}

BOOST_FIXTURE_TEST_CASE(basic_block_response_no_params, response_test_fixture)
{
metadata_log = decltype(metadata_log){
metadata_log_entry { block_entry_v0 { "b000000000000000000000000000000000000000000000000000000000000001"_h, 1, 0 } }
};

data_log = decltype(data_log) {
{
0,
data_log_entry{ block_trace_v0 {
"b000000000000000000000000000000000000000000000000000000000000001"_h,
1,
"0000000000000000000000000000000000000000000000000000000000000000"_h,
chain::block_timestamp_type(0),
"bp.one"_n,
{
{
"0000000000000000000000000000000000000000000000000000000000000001"_h,
chain::transaction_receipt_header::executed,
{
{
0,
"receiver"_n, "contract"_n, "action"_n,
{{ "alice"_n, "active"_n }},
{ 0x00, 0x01, 0x02, 0x03 }
}
}
}
}
}}
}
};

fc::variant expected_response = fc::mutable_variant_object()
("id", "b000000000000000000000000000000000000000000000000000000000000001")
("number", 1)
("previous_id", "0000000000000000000000000000000000000000000000000000000000000000")
("status", "pending")
("timestamp", "2000-01-01T00:00:00.000Z")
("producer", "bp.one")
("transactions", fc::variants({
fc::mutable_variant_object()
("id", "0000000000000000000000000000000000000000000000000000000000000001")
("status", "executed")
("actions", fc::variants({
fc::mutable_variant_object()
("receiver", "receiver")
("account", "contract")
("action", "action")
("authorization", fc::variants({
fc::mutable_variant_object()
("account", "alice")
("permission", "active")
}))
("data", "00010203")
}))
}))
;

// simulate an inability to parse the parameters
mock_data_handler = [](const action_trace_v0&, const fc::time_point&) -> fc::variant {
return {};
};

fc::variant actual_response = get_block_trace( 1 );

BOOST_TEST(to_kv(expected_response) == to_kv(actual_response), boost::test_tools::per_element());
}

BOOST_FIXTURE_TEST_CASE(lib_edge_response, response_test_fixture)
{
metadata_log = decltype(metadata_log){
Expand Down