Merge pull request #379 from AntelopeIO/unhide_cust_entry
Update cdt-llvm to take in customized sync call entry function export fix and add tests for it
This commit is contained in:
+1
-1
Submodule cdt-llvm updated: 7b4b208b01...34c0de5404
@@ -258,4 +258,18 @@ BOOST_AUTO_TEST_CASE(is_sync_call_test) { try {
|
||||
BOOST_REQUIRE(return_value == false);
|
||||
} FC_LOG_AND_RETHROW() }
|
||||
|
||||
// Verify customized sync call entry function, without sync call tag
|
||||
BOOST_AUTO_TEST_CASE(customized_call_entry_func_test1) { try {
|
||||
call_tester t({{"receiver"_n, contracts::cust_entry_wasm(), contracts::cust_entry_abi().data()}});
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(t.push_action("receiver"_n, "cusentrytst1"_n, "receiver"_n, {}));
|
||||
} FC_LOG_AND_RETHROW() }
|
||||
|
||||
// Verify customized sync call entry function, with sync call tag
|
||||
BOOST_AUTO_TEST_CASE(customized_call_entry_func_test2) { try {
|
||||
call_tester t({{"receiver"_n, contracts::cust_entry_wasm(), contracts::cust_entry_abi().data()}});
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(t.push_action("receiver"_n, "cusentrytst2"_n, "receiver"_n, {}));
|
||||
} FC_LOG_AND_RETHROW() }
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -54,5 +54,7 @@ namespace eosio::testing {
|
||||
static std::vector<char> addr_book_callee_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/sync_call_addr_book_callee.abi"); }
|
||||
static std::vector<uint8_t> addr_book_caller_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/sync_call_addr_book_caller.wasm"); }
|
||||
static std::vector<char> addr_book_caller_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/sync_call_addr_book_caller.abi"); }
|
||||
static std::vector<uint8_t> cust_entry_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/sync_call_cust_entry.wasm"); }
|
||||
static std::vector<char> cust_entry_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/sync_call_cust_entry.abi"); }
|
||||
};
|
||||
} //ns eosio::testing
|
||||
|
||||
@@ -19,6 +19,7 @@ add_contract(sync_call_not_supported sync_call_not_supported sync_call_not_suppo
|
||||
add_contract(sync_call_single_func sync_call_single_func sync_call_single_func.cpp)
|
||||
add_contract(sync_call_addr_book_callee sync_call_addr_book_callee sync_call_addr_book_callee.cpp)
|
||||
add_contract(sync_call_addr_book_caller sync_call_addr_book_caller sync_call_addr_book_caller.cpp)
|
||||
add_contract(sync_call_cust_entry sync_call_cust_entry sync_call_cust_entry.cpp)
|
||||
add_contract(capi_tests capi_tests capi/capi.c capi/action.c capi/chain.c capi/crypto.c capi/db.c capi/permission.c
|
||||
capi/print.c capi/privileged.c capi/system.c capi/transaction.c capi/call.c)
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This contract is used to verify customized sync_call entry function works.
|
||||
* It verifies customized sync_call entry is exported, and `call()` host function
|
||||
* can reach it.
|
||||
*/
|
||||
|
||||
#include <eosio/eosio.hpp>
|
||||
#include <eosio/call.hpp>
|
||||
|
||||
namespace eosio {
|
||||
|
||||
class [[eosio::contract]] sync_call_cust_entry : public contract {
|
||||
public:
|
||||
using contract::contract;
|
||||
|
||||
[[eosio::action]]
|
||||
void cusentrytst1() {
|
||||
// Make a sync call to "receiver"_n account, pass function ID in `data`,
|
||||
// go to `sync_call()` entry function, and dispatch the call to `get_10()`
|
||||
// based on the function ID.
|
||||
const std::vector<char> data{ eosio::pack(1) }; // function ID 1
|
||||
eosio::call("receiver"_n, 0, data.data(), data.size());
|
||||
|
||||
// Retrieve return value and unpack it
|
||||
std::vector<char> return_value(sizeof(uint32_t));
|
||||
eosio::get_call_return_value(return_value.data(), return_value.size());
|
||||
|
||||
// Verify it
|
||||
eosio::check(eosio::unpack<uint32_t>(return_value) == 10, "return value is not 10");
|
||||
}
|
||||
|
||||
[[eosio::action]]
|
||||
void cusentrytst2() {
|
||||
// Make a sync call to "receiver"_n account, pass function ID in `data`,
|
||||
// go to `sync_call()` entry function, and dispatch the call to `get_20()`
|
||||
// based on the function ID.
|
||||
const std::vector<char> data{ eosio::pack(2) }; // function ID 2
|
||||
eosio::call("receiver"_n, 0, data.data(), data.size());
|
||||
|
||||
// Retrieve return value and unpack it
|
||||
std::vector<char> return_value(sizeof(uint32_t));
|
||||
eosio::get_call_return_value(return_value.data(), return_value.size());
|
||||
|
||||
// Verify it
|
||||
eosio::check(eosio::unpack<uint32_t>(return_value) == 20, "return value is not 20");
|
||||
}
|
||||
|
||||
// `eosio::call` tag is optional
|
||||
uint32_t get_10() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
[[eosio::call]]
|
||||
uint32_t get_20() {
|
||||
return 20;
|
||||
}
|
||||
};
|
||||
} /// namespace eosio
|
||||
|
||||
extern "C" {
|
||||
[[eosio::wasm_entry]]
|
||||
int64_t sync_call(uint64_t sender, uint64_t receiver, uint32_t data_size) {
|
||||
eosio::datastream<const char*> ds(nullptr, 0); // for testing, not used
|
||||
eosio::sync_call_cust_entry obj(eosio::name{receiver}, eosio::name{receiver}, ds);
|
||||
|
||||
std::vector<char> data(sizeof(uint32_t));
|
||||
eosio::get_call_data(data.data(), data.size());
|
||||
auto func_id = eosio::unpack<uint32_t>(data);
|
||||
|
||||
// Dispatch sync calls
|
||||
uint32_t rv = 0;
|
||||
switch (func_id) {
|
||||
case 1: rv = obj.get_10(); break;
|
||||
case 2: rv = obj.get_20(); break;
|
||||
default: eosio::check(false, "wrong function ID");
|
||||
}
|
||||
|
||||
// set return value
|
||||
eosio::set_call_return_value(&rv, sizeof(uint32_t));
|
||||
|
||||
return 0; // return 0 to indicate success
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user