From 5f70b4594463548318b72915e07e6a6b92854991 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Mon, 16 Jun 2025 09:30:38 -0400 Subject: [PATCH 1/4] Add retrieval functions for `array_test` contract. --- CMakeLists.txt | 2 +- modules/TestsExternalProject.txt | 2 +- tests/integration/contracts.hpp.in | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23cbcb2de..daa21d02c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.5...4.0) # Sanity check our source directory to make sure that we are not trying to # generate an in-source build, and to make diff --git a/modules/TestsExternalProject.txt b/modules/TestsExternalProject.txt index 8b6d479df..91cef2604 100644 --- a/modules/TestsExternalProject.txt +++ b/modules/TestsExternalProject.txt @@ -32,7 +32,7 @@ if (spring_FOUND) CDTIntegrationTests SOURCE_DIR "${CMAKE_SOURCE_DIR}/tests/integration" BINARY_DIR "${CMAKE_BINARY_DIR}/tests/integration" - CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_FRAMEWORK_PATH=${TEST_FRAMEWORK_PATH} -DCMAKE_MODULE_PATH=${TEST_MODULE_PATH} -Deosio_DIR=${eosio_DIR} -DLLVM_DIR=${LLVM_DIR} -DBOOST_ROOT=${BOOST_ROOT} + CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_FRAMEWORK_PATH=${TEST_FRAMEWORK_PATH} -DCMAKE_MODULE_PATH=${TEST_MODULE_PATH} -Dspring_DIR=${spring_DIR} -Deosio_DIR=${eosio_DIR} -DLLVM_DIR=${LLVM_DIR} -DBOOST_ROOT=${BOOST_ROOT} UPDATE_COMMAND "" PATCH_COMMAND "" TEST_COMMAND "" diff --git a/tests/integration/contracts.hpp.in b/tests/integration/contracts.hpp.in index b4be50e83..96838738e 100644 --- a/tests/integration/contracts.hpp.in +++ b/tests/integration/contracts.hpp.in @@ -3,6 +3,8 @@ namespace eosio::testing { struct contracts { + static std::vector array_tests_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/array_tests.wasm"); } + static std::vector array_tests_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/array_tests.abi"); } static std::vector malloc_tests_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/malloc_tests.wasm"); } static std::vector malloc_tests_abi() { return read_abi("${CMAKE_BINARY_DIR}/../unit/test_contracts/malloc_tests.abi"); } static std::vector old_malloc_tests_wasm() { return read_wasm("${CMAKE_BINARY_DIR}/../unit/test_contracts/old_malloc_tests.wasm"); } From 00f721cbc8cee5e1b332fb5d818df840f98b4456 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Mon, 16 Jun 2025 09:54:39 -0400 Subject: [PATCH 2/4] Add test for fixed size array action call. --- tests/integration/array_tests.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/integration/array_tests.cpp diff --git a/tests/integration/array_tests.cpp b/tests/integration/array_tests.cpp new file mode 100644 index 000000000..47d2f4518 --- /dev/null +++ b/tests/integration/array_tests.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include + +#include + +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(array_tests) + +BOOST_FIXTURE_TEST_CASE( array_tests, tester ) try { + create_accounts( { "test"_n } ); + produce_block(); + set_code( "test"_n, contracts::array_tests_wasm() ); + set_abi( "test"_n, contracts::array_tests_abi().data() ); + produce_blocks(); + + push_action("test"_n, "testpa"_n, "test"_n, mvo()("input", std::array{1,2,3,4})); +} FC_LOG_AND_RETHROW() + +BOOST_AUTO_TEST_SUITE_END() From 259f42785f485dec0690addc3ad8768f43761824 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Mon, 16 Jun 2025 14:56:29 -0400 Subject: [PATCH 3/4] Add more array tests. --- tests/integration/array_tests.cpp | 73 ++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/tests/integration/array_tests.cpp b/tests/integration/array_tests.cpp index 47d2f4518..c77d7f0df 100644 --- a/tests/integration/array_tests.cpp +++ b/tests/integration/array_tests.cpp @@ -16,14 +16,83 @@ using mvo = fc::mutable_variant_object; BOOST_AUTO_TEST_SUITE(array_tests) -BOOST_FIXTURE_TEST_CASE( array_tests, tester ) try { +BOOST_FIXTURE_TEST_CASE( std_array_param, tester ) try { + /* ----------- testpa action tests -------------------------------------------------- + [[eosio::action]] + void testpa(std::array input){ + std::array arr = input; + for(int i = 0; i < 4; ++i){ + eosio::cout << arr[i] << " "; + } + eosio::cout << "\n"; + } + -------------------------------------------------------------------------------------- */ create_accounts( { "test"_n } ); produce_block(); set_code( "test"_n, contracts::array_tests_wasm() ); set_abi( "test"_n, contracts::array_tests_abi().data() ); produce_blocks(); - push_action("test"_n, "testpa"_n, "test"_n, mvo()("input", std::array{1,2,3,4})); + auto trace = push_action("test"_n, "testpa"_n, "test"_n, mvo()("input", {1,2,3,4})); + auto& con = trace->action_traces[0].console; + BOOST_REQUIRE_EQUAL(con, std::string("1 2 3 4 \n")); + produce_block(); + + // size should be correct + // ---------------------- + BOOST_CHECK_EXCEPTION( push_action("test"_n, "testpa"_n, "test"_n, mvo()("input", {1,2,3})), + pack_exception, + fc_exception_message_starts_with("Incorrect number of values provided (4) for fixed-size (3) array type")); + + produce_block(); +} FC_LOG_AND_RETHROW() + + +BOOST_FIXTURE_TEST_CASE( std_array_return_value, tester ) try { + /* ----------- testre action tests -------------------------------------------------- + [[eosio::action]] + std::array testre(std::array input){ + std::array arr = input; + for(auto & v : arr) v += 1; + return arr; + } + -------------------------------------------------------------------------------------- */ + create_accounts( { "test"_n } ); + produce_block(); + set_code( "test"_n, contracts::array_tests_wasm() ); + set_abi( "test"_n, contracts::array_tests_abi().data() ); + produce_blocks(); + + auto trace = push_action("test"_n, "testre"_n, "test"_n, mvo()("input", {1, 2, 3, 4})); + auto& rv = trace->action_traces[0].return_value; + auto actual = fc::raw::unpack>(rv); + auto expected = std::array{2, 3, 4, 5}; + BOOST_REQUIRE(actual == expected); +} FC_LOG_AND_RETHROW() + + +BOOST_FIXTURE_TEST_CASE( std_vector_return_value, tester ) try { + /* ----------- testrev action tests -------------------------------------------------- + [[eosio::action]] + std::vector testrev(std::vector input){ + std::vector vec = input; + for(auto & v : vec) v += 1; + return vec; + } + -------------------------------------------------------------------------------------- */ + create_accounts( { "test"_n } ); + produce_block(); + set_code( "test"_n, contracts::array_tests_wasm() ); + set_abi( "test"_n, contracts::array_tests_abi().data() ); + produce_blocks(); + + auto trace = push_action("test"_n, "testrev"_n, "test"_n, mvo()("input", {1, 2, 3, 4})); + auto& rv = trace->action_traces[0].return_value; + auto actual = fc::raw::unpack>(rv); + auto expected = std::vector{2, 3, 4, 5}; + BOOST_REQUIRE(actual == expected); } FC_LOG_AND_RETHROW() + + BOOST_AUTO_TEST_SUITE_END() From d697c579ee69ba14458ab9444a03325dda566eb3 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Wed, 18 Jun 2025 15:10:05 -0400 Subject: [PATCH 4/4] cleanup `array_tests.cpp` and add action. --- tests/unit/test_contracts/array_tests.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_contracts/array_tests.cpp b/tests/unit/test_contracts/array_tests.cpp index bbd72050b..35c7f46e9 100644 --- a/tests/unit/test_contracts/array_tests.cpp +++ b/tests/unit/test_contracts/array_tests.cpp @@ -65,8 +65,7 @@ class [[eosio::contract]] array_tests : public contract { } } - // test parameter using std::array - // not supported so far + // test parameter using std::array [[eosio::action]] void testpa(std::array input){ std::array arr = input; @@ -76,7 +75,7 @@ class [[eosio::contract]] array_tests : public contract { eosio::cout << "\n"; } - // test return using std::array, not supported so far + // test parameter and return value using std::array [[eosio::action]] // cleos -v push action eosio testre '[[1,2,3,4]]' -p eosio@active std::array testre(std::array input){ @@ -85,6 +84,15 @@ class [[eosio::contract]] array_tests : public contract { return arr; } + // test return value using std::array + [[eosio::action]] + // cleos -v push action eosio testre2 '[[1,2,3,4]]' -p eosio@active + std::array testre2(std::vector input){ + std::array arr; + for(size_t i=0; i<4; ++i) arr[i] = input[i+1]; + return arr; + } + // test return using std::vector [[eosio::action]] // cleos -v push action eosio testrev '[[1,2,3,4]]' -p eosio@active