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 4 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
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"
}
}
}
}
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
67 changes: 67 additions & 0 deletions tests/integration/action_results_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#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();

const auto& pfm = control->get_protocol_feature_manager();

set_code( N(test), contracts::action_results_test_wasm() );
set_abi( N(test), contracts::action_results_test_abi().data() );
auto d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value)
schedule_protocol_features( {*d} );

produce_blocks();
const auto& trace = push_action(N(test), N(action1), N(test), mvo());

/*
BOOST_CHECK_THROW(push_action(N(test), N(test1), N(test), mvo()("nm", "notbucky")),
fc::exception);

push_action(N(test), N(test2), N(test),
mvo()
("arg0", 33)
("arg1", "some string"));
BOOST_CHECK_THROW(push_action(N(test), N(test2), N(test), mvo() ("arg0", 30)("arg1", "some string")), fc::exception);
BOOST_CHECK_THROW(push_action(N(test), N(test2), N(test), mvo() ("arg0", 33)("arg1", "not some string")), fc::exception);

set_abi( N(test), contracts::simple_wrong_abi().data() );
produce_blocks();

BOOST_CHECK_THROW(push_action(N(test), N(test3), N(test), mvo() ("arg0", 33) ("arg1", "some string")), fc::exception);

set_abi( N(test), contracts::simple_abi().data() );
produce_blocks();

push_action(N(test), N(test4), N(test), mvo() ("to", "someone"));
push_action(N(test), N(test5), N(test), mvo() ("to", "someone"));
push_action(N(test), N(testa), N(test), mvo() ("to", "someone"));
BOOST_CHECK_THROW(push_action(N(test), N(testb), N(test), mvo() ("to", "someone")), fc::exception);

// test that the pre_dispatch will short circuit dispatching if false
push_action(N(test), N(testc), N(test), mvo() ("nm", "bucky"));
BOOST_CHECK_THROW(push_action(N(test), N(testc), N(test), mvo() ("nm", "someone")), fc::exception);
push_action(N(test), N(testc), N(test), mvo() ("nm", "quit"));
*/

} FC_LOG_AND_RETHROW()

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

const auto& pfm = control->get_protocol_feature_manager();

auto d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value)
schedule_protocol_features( {*d} );

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"
}
}
]
}

48 changes: 48 additions & 0 deletions tests/toolchain/abigen-pass/struct_base_typedefd.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.2",
"types": [
{
"new_type_name": "bar",
"type": "foo"
}
],
"structs": [
{
"name": "baz",
"base": "bar",
"fields": []
},
{
"name": "foo",
"base": "",
"fields": [
{
"name": "value",
"type": "int32"
}
]
},
{
"name": "hi",
"base": "",
"fields": [
{
"name": "b",
"type": "baz"
}
]
}
],
"actions": [
{
"name": "hi",
"type": "hi",
"ricardian_contract": ""
}
],
"tables": [],
"ricardian_clauses": [],
"variants": [],
"action_results": []
}
Loading