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

Feature/action results #810

Merged
merged 7 commits into from
Feb 12, 2020
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 libraries/eosiolib/capi/eosio/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ capi_name current_receiver( void );
* @pre `return_value` is a valid pointer to an array at least `size` bytes long
*/
__attribute__((eosio_wasm_import))
void set_action_return_value(char *return_value, size_t size);
void set_action_return_value(void *return_value, size_t size);

#ifdef __cplusplus
}
Expand Down
35 changes: 10 additions & 25 deletions libraries/eosiolib/contracts/eosio/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ namespace eosio {

__attribute__((eosio_wasm_import))
uint64_t current_receiver();

__attribute__((eosio_wasm_import))
void set_action_return_value(char *return_value, size_t size);
}
};

Expand Down Expand Up @@ -153,18 +150,6 @@ namespace eosio {
return name{internal_use_do_not_use::current_receiver()};
}

/**
* Set the action return value which will be included in action_receipt
* @ingroup action
* @tparam T type of return value
* @param v the return value to set
*/
template<typename T>
inline void set_action_return_value( const T& v ) {
auto packed_value = pack( v );
internal_use_do_not_use::set_action_return_value( &packed_value[0], packed_value.size() );
}

/**
* Copy up to length bytes of current action data to the specified location
*
Expand Down Expand Up @@ -448,9 +433,9 @@ namespace eosio {
}

/**
* Wrapper for an action object.
* Wrapper for an action object.
*
* @brief Used to wrap an a particular action to simplify the process of other contracts sending inline actions to "wrapped" action.
* @brief Used to wrap an a particular action to simplify the process of other contracts sending inline actions to "wrapped" action.
* Example:
* @code
* // defined by contract writer of the actions
Expand Down Expand Up @@ -591,23 +576,23 @@ INLINE_ACTION_SENDER3( CONTRACT_CLASS, NAME, ::eosio::name(#NAME) )
* Send an inline-action from inside a contract.
*
* @brief A macro to simplify calling inline actions
* @details The send inline action macro is intended to simplify the process of calling inline actions. When calling new actions from existing actions
* @details The send inline action macro is intended to simplify the process of calling inline actions. When calling new actions from existing actions
* EOSIO supports two communication models, inline and deferred. Inline actions are executed as part of the current transaction. This macro
* creates an @ref action using the supplied parameters and automatically calls action.send() on this newly created action.
*
* Example:
* @code
* SEND_INLINE_ACTION( *this, transfer, {st.issuer,N(active)}, {st.issuer, to, quantity, memo} );
* @endcode
*
* The example above is taken from eosio.token.
* This example:
* uses the passed in, dereferenced `this` pointer, to call this.get_self() i.e. the eosio.token contract;
* calls the eosio.token::transfer() action;
*
* The example above is taken from eosio.token.
* This example:
* uses the passed in, dereferenced `this` pointer, to call this.get_self() i.e. the eosio.token contract;
* calls the eosio.token::transfer() action;
* uses the active permission of the "issuer" account;
* uses parameters st.issuer, to, quantity and memo.
* uses parameters st.issuer, to, quantity and memo.
* This macro creates an action struct used to 'send()' (call) transfer(account_name from, account_name to, asset quantity, string memo)
*
*
* @param CONTRACT - The contract to call, which contains the action being sent, maps to the @ref account
* @param NAME - The name of the action to be called, maps to a @ref name
* @param ... - The authorising permission, maps to an @ref authorization , followed by the parameters of the action, maps to a @ref data.
Expand Down
2 changes: 1 addition & 1 deletion libraries/native/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ extern "C" {
capi_name current_receiver() {
return intrinsics::get().call<intrinsics::current_receiver>();
}
void set_action_return_value( char* rv, size_t len ) {
void set_action_return_value( void* rv, size_t len ) {
intrinsics::get().call<intrinsics::set_action_return_value>(rv, len);
}
void require_recipient( capi_name name ) {
Expand Down
1 change: 0 additions & 1 deletion modules/InstallCDT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ eosio_tool_install_and_symlink(eosio-wasm2wast eosio-wasm2wast)
eosio_tool_install_and_symlink(eosio-cc eosio-cc)
eosio_tool_install_and_symlink(eosio-cpp eosio-cpp)
eosio_tool_install_and_symlink(eosio-ld eosio-ld)
eosio_tool_install_and_symlink(eosio-abigen eosio-abigen)
eosio_tool_install_and_symlink(eosio-abidiff eosio-abidiff)
eosio_tool_install_and_symlink(eosio-init eosio-init)

Expand Down
2 changes: 1 addition & 1 deletion modules/TestsExternalProject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ExternalProject_Add(
EosioWasmTests
SOURCE_DIR "${CMAKE_SOURCE_DIR}/tests/unit"
BINARY_DIR "${CMAKE_BINARY_DIR}/tests/unit"
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DEOSIO_CDT_BIN=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/ -DBASE_BINARY_DIR=${CMAKE_BINARY_DIR} -D__APPLE=${APPLE}
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DEOSIO_CDT_BIN=${CMAKE_BINARY_DIR}/lib/cmake/eosio.cdt/ -DBASE_BINARY_DIR=${CMAKE_BINARY_DIR} -D__APPLE=${APPLE} -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
Expand Down
4 changes: 2 additions & 2 deletions pipeline.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pipeline-branch": "master",
"dependencies": // dependencies to pull for cdt integration tests, by branch, tag, or commit hash
{
"eosio": "release/1.7.x"
"eosio": "develop"
}
}
}
}
12 changes: 9 additions & 3 deletions scripts/generate_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NAME=$1
CDT_PREFIX=${PREFIX}/${SUBPREFIX}
mkdir -p ${PREFIX}/bin/
mkdir -p ${PREFIX}/lib/cmake/${PROJECT}
mkdir -p ${CDT_PREFIX}/bin
mkdir -p ${CDT_PREFIX}/bin
mkdir -p ${CDT_PREFIX}/include
mkdir -p ${CDT_PREFIX}/lib/cmake/${PROJECT}
mkdir -p ${CDT_PREFIX}/cmake
Expand All @@ -13,7 +13,7 @@ mkdir -p ${CDT_PREFIX}/licenses

#echo "${PREFIX} ** ${SUBPREFIX} ** ${CDT_PREFIX}"

# install binaries
# install binaries
cp -R ${BUILD_DIR}/bin/* ${CDT_PREFIX}/bin || exit 1
cp -R ${BUILD_DIR}/licenses/* ${CDT_PREFIX}/licenses || exit 1

Expand Down Expand Up @@ -50,10 +50,16 @@ create_symlink eosio-cpp eosio-cpp
create_symlink eosio-ld eosio-ld
create_symlink eosio-pp eosio-pp
create_symlink eosio-init eosio-init
create_symlink eosio-abigen eosio-abigen
create_symlink eosio-wasm2wast eosio-wasm2wast
create_symlink eosio-wast2wasm eosio-wast2wasm
create_symlink eosio-ar eosio-ar
create_symlink eosio-abidiff eosio-abidiff
create_symlink eosio-nm eosio-nm
create_symlink eosio-objcopy eosio-objcopy
create_symlink eosio-objdump eosio-objdump
create_symlink eosio-ranlib eosio-ranlib
create_symlink eosio-readelf eosio-readelf
create_symlink eosio-strip eosio-strip

echo "Generating Tarball $NAME.tar.gz..."
tar -cvzf $NAME.tar.gz ./${PREFIX}/* || exit 1
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required( VERSION 3.5 )

set(EOSIO_VERSION_MIN "1.4")
set(EOSIO_VERSION_SOFT_MAX "2.0")
set(EOSIO_VERSION_MIN "2.0")
set(EOSIO_VERSION_SOFT_MAX "3.0")
#set(EOSIO_VERSION_HARD_MAX "")

find_package(eosio)
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/action_results_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/abi_serializer.hpp>

#include <Runtime/Runtime.h>

#include <fc/variant_object.hpp>

#include <contracts.hpp>

using namespace eosio;
using namespace eosio::testing;
using namespace eosio::chain;
using namespace eosio::testing;
using namespace fc;

using mvo = fc::mutable_variant_object;

BOOST_AUTO_TEST_SUITE(action_results_tests_suite)

BOOST_FIXTURE_TEST_CASE( action_results_tests, tester ) try {
create_accounts( { N(test) } );
produce_block();

set_code( N(test), contracts::action_results_test_wasm() );
set_abi( N(test), contracts::action_results_test_abi().data() );

produce_blocks();
auto trace = push_action(N(test), N(action1), N(test), mvo());
// need to fix this test after Kevin fixes action_return
wdump((trace));

trace = push_action(N(test), N(action2), N(test), mvo());
wdump((trace));

trace = push_action(N(test), N(action3), N(test), mvo());
wdump((trace));

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions tests/integration/capi_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BOOST_AUTO_TEST_SUITE(capi_tests)
BOOST_FIXTURE_TEST_CASE( capi_tests, tester ) try {
create_accounts( { N(test) } );
produce_block();

set_code( N(test), contracts::capi_tests_wasm() );
set_abi( N(test), contracts::capi_tests_abi().data() );
produce_blocks();
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct contracts {
static std::vector<uint8_t> capi_tests_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/capi_tests.wasm"); }
static std::vector<char> capi_tests_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/capi_tests.abi"); }

static std::vector<uint8_t> action_results_test_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/action_results_test.wasm"); }
static std::vector<char> action_results_test_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/action_results_test.abi"); }
};

}} //ns eosio::testing
52 changes: 52 additions & 0 deletions tests/toolchain/abigen-pass/action_results_test.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.2",
"types": [],
"structs": [
{
"name": "action1",
"base": "",
"fields": []
},
{
"name": "action2",
"base": "",
"fields": []
},
{
"name": "action3",
"base": "",
"fields": []
}
],
"actions": [
{
"name": "action1",
"type": "action1",
"ricardian_contract": ""
},
{
"name": "action2",
"type": "action2",
"ricardian_contract": ""
},
{
"name": "action3",
"type": "action3",
"ricardian_contract": ""
}
],
"tables": [],
"ricardian_clauses": [],
"variants": [],
"action_results": [
{
"name": "action2",
"result_type": "uint32"
},
{
"name": "action3",
"result_type": "string"
}
]
}
17 changes: 17 additions & 0 deletions tests/toolchain/abigen-pass/action_results_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <eosio/eosio.hpp>

using namespace eosio;

class [[eosio::contract]] action_results_test : public contract {
public:
using contract::contract;

[[eosio::action]]
void action1() {}

[[eosio::action]]
uint32_t action2() { return 42; }

[[eosio::action]]
std::string action3() { return "foo"; }
};
9 changes: 9 additions & 0 deletions tests/toolchain/abigen-pass/action_results_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tests" : [
{
"expected" : {
"abi-file" : "action_results_test.abi"
}
}
]
}
38 changes: 38 additions & 0 deletions tests/toolchain/abigen-pass/aliased_type_variant_template_arg.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.2",
"types": [
{
"new_type_name": "str",
"type": "string"
}
],
"structs": [
{
"name": "hi",
"base": "",
"fields": [
{
"name": "v",
"type": "variant_uint64_str"
}
]
}
],
"actions": [
{
"name": "hi",
"type": "hi",
"ricardian_contract": ""
}
],
"tables": [],
"ricardian_clauses": [],
"variants": [
{
"name": "variant_uint64_str",
"types": ["uint64","str"]
}
],
"action_results": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"tests": [
{
"expected": {
"abi": "{\n \"____comment\": \"This file was generated with eosio-abigen. DO NOT EDIT \",\n \"version\": \"eosio::abi\/1.1\",\n \"types\": [\n {\n \"new_type_name\": \"str\",\n \"type\": \"string\"\n }\n ],\n \"structs\": [\n {\n \"name\": \"hi\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"v\",\n \"type\": \"variant_uint64_str\"\n }\n ]\n }\n ],\n \"actions\": [\n {\n \"name\": \"hi\",\n \"type\": \"hi\",\n \"ricardian_contract\": \"\"\n }\n ],\n \"tables\": [],\n \"ricardian_clauses\": [],\n \"variants\": [\n {\n \"name\": \"variant_uint64_str\",\n \"types\": [\"uint64\",\"str\"]\n }\n ]\n}"
"abi-file": "aliased_type_variant_template_arg.abi"
}
}
]
}

Loading