diff --git a/libraries/abieos/include/eosio/abi.hpp b/libraries/abieos/include/eosio/abi.hpp index d4c692179..59bf62681 100644 --- a/libraries/abieos/include/eosio/abi.hpp +++ b/libraries/abieos/include/eosio/abi.hpp @@ -141,6 +141,13 @@ namespace eosio }; EOSIO_REFLECT(variant_def, name, types); + struct action_result_def + { + eosio::name name{}; + std::string result_type{}; + }; + EOSIO_REFLECT(action_result_def, name, result_type); + struct abi_def { std::string version{}; @@ -152,6 +159,7 @@ namespace eosio std::vector error_messages{}; abi_extensions_type abi_extensions{}; might_not_exist> variants{}; + might_not_exist> action_results{}; }; EOSIO_REFLECT(abi_def, version, @@ -162,7 +170,8 @@ namespace eosio ricardian_clauses, error_messages, abi_extensions, - variants); + variants, + action_results); struct abi_type; diff --git a/libraries/eosiolib/contracts/include/eosio/abi_generator.hpp b/libraries/eosiolib/contracts/include/eosio/abi_generator.hpp index 8faddd072..c7e3a9f6c 100644 --- a/libraries/eosiolib/contracts/include/eosio/abi_generator.hpp +++ b/libraries/eosiolib/contracts/include/eosio/abi_generator.hpp @@ -11,7 +11,7 @@ namespace eosio { struct abi_generator { - eosio::abi_def def{"eosio::abi/1.1"}; + eosio::abi_def def{"eosio::abi/1.3"}; std::map type_to_name; std::map name_to_type; @@ -179,6 +179,11 @@ namespace eosio struct_def d{struct_name}; add_action_args<0>(d, (typename decltype(wrapper)::args*)nullptr, arg_names...); def.structs.push_back(std::move(d)); + if constexpr (!std::is_same_v) + { + def.action_results.value.push_back( + {name, get_type()}); + } } template diff --git a/libraries/eosiolib/contracts/include/eosio/dispatcher.hpp b/libraries/eosiolib/contracts/include/eosio/dispatcher.hpp index 1e6ad6444..dc14c73b0 100644 --- a/libraries/eosiolib/contracts/include/eosio/dispatcher.hpp +++ b/libraries/eosiolib/contracts/include/eosio/dispatcher.hpp @@ -86,6 +86,7 @@ namespace eosio struct action_type_wrapper { using args = detail::deduced; + using return_type = typename member_fn::return_type; }; #define EOSIO_EMPTY(...) diff --git a/libraries/eosiolib/tests/CMakeLists.txt b/libraries/eosiolib/tests/CMakeLists.txt index cc7aea706..847722872 100644 --- a/libraries/eosiolib/tests/CMakeLists.txt +++ b/libraries/eosiolib/tests/CMakeLists.txt @@ -1,10 +1,16 @@ enable_testing() add_executable(get-code contracts/get-code.cpp) -target_include_directories(get-code PUBLIC include) target_link_libraries(get-code eosio-contract-simple-malloc) set_target_properties(get-code PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT_BINARY_DIR}/test-contracts) +add_executable(get-code-abigen contracts/get-code.cpp) +target_link_libraries(get-code-abigen eosio-contract-abigen) +add_custom_command(TARGET get-code-abigen POST_BUILD + COMMAND mkdir -p ${ROOT_BINARY_DIR}/test-contracts + COMMAND ${ROOT_BINARY_DIR}/cltester get-code-abigen.wasm >${ROOT_BINARY_DIR}/test-contracts/get-code.abi +) + add_executable(test-sdk test-sdk.cpp) target_include_directories(test-sdk PUBLIC include ${ROOT_SOURCE_DIR}/contracts/bios/include) target_link_libraries(test-sdk catch2 cltestlib) diff --git a/libraries/eosiolib/tests/contracts/get-code.cpp b/libraries/eosiolib/tests/contracts/get-code.cpp index d1c6fed33..fab2d1d5f 100644 --- a/libraries/eosiolib/tests/contracts/get-code.cpp +++ b/libraries/eosiolib/tests/contracts/get-code.cpp @@ -1,3 +1,4 @@ #include "get-code.hpp" EOSIO_ACTION_DISPATCHER(get_code::actions) +EOSIO_ABIGEN(actions(get_code::actions)) diff --git a/libraries/eosiolib/tests/contracts/get-code.hpp b/libraries/eosiolib/tests/contracts/get-code.hpp index 124795502..e1ec7c9f3 100644 --- a/libraries/eosiolib/tests/contracts/get-code.hpp +++ b/libraries/eosiolib/tests/contracts/get-code.hpp @@ -24,11 +24,14 @@ namespace get_code { eosio::print(eosio::format_json(eosio::get_code_hash(account))); } + + auto get(eosio::name account) { return eosio::get_code_hash(account); } }; EOSIO_ACTIONS(contract, "getcode"_n, action(shouldhave, account), action(shouldnot, account), - action(print, account)) + action(print, account), + action(get)) } // namespace get_code diff --git a/libraries/eosiolib/tests/test-sdk.cpp b/libraries/eosiolib/tests/test-sdk.cpp index ec1963b3b..ecbf0170e 100644 --- a/libraries/eosiolib/tests/test-sdk.cpp +++ b/libraries/eosiolib/tests/test-sdk.cpp @@ -8,19 +8,54 @@ using namespace eosio; +static void run_nodeos(test_chain& chain) +{ + chain.finish_block(); + chain.finish_block(); + + eosio::execute("rm -rf example_chain"); + eosio::execute("mkdir -p example_chain/blocks"); + eosio::execute("cp " + chain.get_path() + "/blocks/blocks.log example_chain/blocks"); + + eosio::execute( + "./clsdk/bin/nodeos -d example_chain " + "--config-dir example_config " + "--plugin eosio::chain_api_plugin " + "--access-control-allow-origin \"*\" " + "--access-control-allow-header \"*\" " + "--http-validate-host 0 " + "--http-server-address 0.0.0.0:8888 " + "--contracts-console " + "-e -p eosio"); +} + TEST_CASE("get_code") { test_chain chain; chain.set_code("eosio"_n, "clsdk/contracts/bios.wasm"); bios::activate(chain, { + eosio::feature::action_return_value, eosio::feature::get_code_hash, }); chain.create_code_account("getcode"_n); chain.set_code("getcode"_n, "test-contracts/get-code.wasm"); + chain.set_abi("getcode"_n, "test-contracts/get-code.abi"); chain.as("getcode"_n).act("alice"_n); chain.as("getcode"_n).act("eosio"_n); chain.as("getcode"_n).act("getcode"_n); chain.as("getcode"_n).act("eosio"_n); chain.as("getcode"_n).act("getcode"_n); chain.as("getcode"_n).act("alice"_n); + + auto result = chain.as("getcode"_n).act("getcode"_n); + std::cout << "\naction returned: " << eosio::format_json(result) << "\n"; + CHECK(result.struct_version.value == 0); + CHECK(result.code_sequence == 1); + CHECK(result.hash != eosio::checksum256{}); + CHECK(result.vm_type == 0); + CHECK(result.vm_version == 0); + + // run_nodeos(chain); + + // clsdk/bin/cleos push action getcode get '["eosio"]' -p getcode -j | jq .processed.action_traces[0].return_value_data } diff --git a/programs/cltester/main.cpp b/programs/cltester/main.cpp index 559312603..a2c8b9ba8 100644 --- a/programs/cltester/main.cpp +++ b/programs/cltester/main.cpp @@ -492,9 +492,9 @@ chain_types::action convert(const eosio::chain::action& obj) return result; } -chain_types::action_trace_v0 convert(const eosio::chain::action_trace& obj) +chain_types::action_trace_v1 convert(const eosio::chain::action_trace& obj) { - chain_types::action_trace_v0 result; + chain_types::action_trace_v1 result; result.action_ordinal.value = obj.action_ordinal.value; result.creator_action_ordinal.value = obj.creator_action_ordinal.value; if (obj.receipt) @@ -510,6 +510,7 @@ chain_types::action_trace_v0 convert(const eosio::chain::action_trace& obj) result.except = obj.except->to_string(); if (obj.error_code) result.error_code = *obj.error_code; + result.return_value = obj.return_value; return result; }