Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test contract code for existing abi/wasm and clean up libraries/testing & unittests dependencies #612

Merged
merged 20 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1c80bab
GH-54 Move eosio.bios to libraries/testing and provide ability to bui…
heifner Jan 3, 2023
bb470fa
GH-54 Remove mostly unused CORE_SYM_STR and just use CORE_SYMBOL_NAME
heifner Jan 3, 2023
c168977
GH-54 Missed a few locations where python tests refer to old eosio.bi…
heifner Jan 3, 2023
4dc4296
Revert "GH-54 Remove mostly unused CORE_SYM_STR and just use CORE_SYM…
heifner Jan 3, 2023
6c17992
GH-54 Remove mostly unused CORE_SYM_STR and just use CORE_SYMBOL
heifner Jan 3, 2023
6e0d8a0
GH-54 Move snapshot_suites out of libraries/testing as it is not need…
heifner Jan 3, 2023
b9e99f0
GH-54 Split contracts.cpp.in for libraries/testing and unittests. Rem…
heifner Jan 4, 2023
e0c9faf
GH-54 Add comment
heifner Jan 4, 2023
c3e4686
GH-54 Remove moved test_chain_plugin test
heifner Jan 4, 2023
b8fadad
GH-54 eosio.token contract moved to libraries/testing/contracts from …
heifner Jan 4, 2023
1fc40bf
GH-54 eosio.token contract moved to libraries/testing/contracts from …
heifner Jan 4, 2023
2bf719d
GH-54 Remove call to set_parameters_packed as many tests assume that …
heifner Jan 4, 2023
a9281f5
GH-54 Add contract code for eosio.msig, eosio.system, eosio.wrap. Upd…
heifner Jan 4, 2023
e83c91d
GH-54 Copy over abi/wasm compiled with latest Antelope CDT 3.2.0-dev …
heifner Jan 4, 2023
4e1d593
Merge branch 'main' into GH-54-contracts
heifner Jan 4, 2023
b3a6e00
Merge remote-tracking branch 'origin/main' into GH-54-contracts
heifner Jan 12, 2023
dd66bfc
GH-54 Now that txn_test_gen_plugin has been removed eosio.token can m…
heifner Jan 12, 2023
1e3b4a3
GH-54 Update eosio.token contract location
heifner Jan 12, 2023
759a069
GH-54 Add a print to activate so this bios contract is different then…
heifner Jan 13, 2023
20d7b80
GH-54 Update deep mind log for new bios contract
heifner Jan 13, 2023
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
41 changes: 39 additions & 2 deletions libraries/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
### Build contracts with cdt if available ###
include(ExternalProject)

if( EOSIO_COMPILE_TEST_CONTRACTS )
set(EOSIO_WASM_OLD_BEHAVIOR "Off")
if( USE_EOSIO_CDT_1_7_X OR USE_EOSIO_CDT_1_8_X )
find_package( eosio.cdt REQUIRED )
set(CMAKE_ARGS_VAL -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DEOSIO_COMPILE_TEST_CONTRACTS=${EOSIO_COMPILE_TEST_CONTRACTS} )
else()
find_package( cdt REQUIRED )
set(CMAKE_ARGS_VAL -DCMAKE_TOOLCHAIN_FILE=${CDT_ROOT}/lib/cmake/cdt/CDTWasmToolchain.cmake -DEOSIO_COMPILE_TEST_CONTRACTS=${EOSIO_COMPILE_TEST_CONTRACTS} )
endif()

if( USE_EOSIO_CDT_1_7_X )
list(APPEND CMAKE_ARGS_VAL -DUSE_EOSIO_CDT_1_7_X=${USE_EOSIO_CDT_1_7_X})
elseif( USE_EOSIO_CDT_1_8_X )
list(APPEND CMAKE_ARGS_VAL -DUSE_EOSIO_CDT_1_8_X=${USE_EOSIO_CDT_1_8_X})
endif()

message( STATUS "Building contracts in directory `./libraries/contracts/`" )
ExternalProject_Add(
testing_contracts_project
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contracts
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/contracts
CMAKE_ARGS ${CMAKE_ARGS_VAL}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
else()
message( STATUS "Not building contracts in directory `./libraries/contracts/`" )
add_subdirectory(contracts)
endif()

file(GLOB HEADERS "include/eosio/testing/*.hpp")

configure_file(contracts.hpp.in include/testing_contracts/contracts.hpp ESCAPE_QUOTES)
Expand All @@ -18,8 +54,9 @@ target_link_libraries( eosio_testing eosio_testing_contracts eosio_chain fc chai
target_include_directories( eosio_testing
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include"
"${CMAKE_BINARY_DIR}/unittests/include"
)
"${CMAKE_CURRENT_SOURCE_DIR}/contracts"
"${CMAKE_CURRENT_BINARY_DIR}/contracts"
)

set_target_properties( eosio_testing PROPERTIES PUBLIC_HEADER "${HEADERS}" )
install( TARGETS eosio_testing
Expand Down
10 changes: 5 additions & 5 deletions libraries/testing/contracts.cpp.in
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <contracts.hpp>

#include <stdint.h>
#include <cstdint>
#include <vector>

#define INCBIN_STYLE INCBIN_STYLE_SNAKE
#include <fc/io/incbin.h>

#define MAKE_EMBEDDED_WASM_ABI(CN,C, D) \
INCBIN(eosio_testing_contract_ ## CN ## _wasm, "${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".wasm"); \
INCBIN(eosio_testing_contract_ ## CN ## _abi, "${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".abi"); \
INCBIN(eosio_testing_contract_ ## CN ## _wasm, "${CMAKE_BINARY_DIR}/libraries/testing/" #D "/" #C "/" #C ".wasm"); \
INCBIN(eosio_testing_contract_ ## CN ## _abi, "${CMAKE_BINARY_DIR}/libraries/testing/" #D "/" #C "/" #C ".abi"); \
\
namespace eosio::testing { \
std::vector<uint8_t> contracts:: CN ## _wasm() { \
return std::vector<uint8_t>(geosio_testing_contract_ ## CN ## _wasm_data, geosio_testing_contract_ ## CN ## _wasm_data + geosio_testing_contract_ ## CN ## _wasm_size); \
std::vector<std::uint8_t> contracts:: CN ## _wasm() { \
return std::vector<std::uint8_t>(geosio_testing_contract_ ## CN ## _wasm_data, geosio_testing_contract_ ## CN ## _wasm_data + geosio_testing_contract_ ## CN ## _wasm_size); \
} \
std::vector<char> contracts:: CN ## _abi() { \
return std::vector<char>(geosio_testing_contract_ ## CN ## _abi_data, geosio_testing_contract_ ## CN ## _abi_data + geosio_testing_contract_ ## CN ## _abi_size); \
Expand Down
65 changes: 3 additions & 62 deletions libraries/testing/contracts.hpp.in
Original file line number Diff line number Diff line change
@@ -1,81 +1,22 @@
#pragma once

#include <cstdint>
#include <vector>

#include <eosio/chain/asset.hpp>
#include <fc/io/fstream.hpp>

#define CORE_SYM_NAME "${CORE_SYMBOL_NAME}"
#define CORE_SYM_PRECISION 4

#define _STRINGIZE1(x) #x
#define _STRINGIZE2(x) _STRINGIZE1(x)

#define CORE_SYM_STR ( _STRINGIZE2(CORE_SYM_PRECISION) "," CORE_SYM_NAME )
#define CORE_SYM ( ::eosio::chain::string_to_symbol_c( CORE_SYM_PRECISION, CORE_SYM_NAME ) )

struct core_sym {
static inline eosio::chain::asset from_string(const std::string& s) {
return eosio::chain::asset::from_string(s + " " CORE_SYM_NAME);
}
};

// CN -> contract C++ name, C -> contract name, D -> top level directory
#define MAKE_READ_WASM_ABI(CN,C, D) \
static std::vector<uint8_t> CN ## _wasm() { \
std::string s; \
fc::read_file_contents("${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".wasm", s); \
return std::vector<uint8_t>(s.begin(), s.end()); \
} \
static std::vector<char> CN ## _abi() { \
std::string s; \
fc::read_file_contents("${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".abi", s); \
return std::vector<char>(s.begin(), s.end()); \
}

//contracts that need to be available by native contract unit testing's libtester need to be embedded
// in to the library as the build directory may not exist after being 'make install'ed.
#define MAKE_EMBD_WASM_ABI(CN) \
static std::vector<uint8_t> CN ## _wasm(); \
static std::vector<std::uint8_t> CN ## _wasm(); \
static std::vector<char> CN ## _abi();

namespace eosio {
namespace testing {
struct contracts {
// Contracts in `eos/unittests/contracts' directory
// Contracts in `libraries/testing/contracts' directory
MAKE_EMBD_WASM_ABI(eosio_bios)
MAKE_READ_WASM_ABI(eosio_msig, eosio.msig, contracts)
MAKE_READ_WASM_ABI(eosio_system, eosio.system, contracts)
MAKE_READ_WASM_ABI(eosio_token, eosio.token, contracts)
MAKE_READ_WASM_ABI(eosio_wrap, eosio.wrap, contracts)

MAKE_EMBD_WASM_ABI(before_producer_authority_eosio_bios)
MAKE_EMBD_WASM_ABI(before_preactivate_eosio_bios)

// Contracts in `eos/unittests/unittests/test-contracts' directory
MAKE_READ_WASM_ABI(asserter, asserter, test-contracts)
MAKE_READ_WASM_ABI(deferred_test, deferred_test, test-contracts)
MAKE_READ_WASM_ABI(get_sender_test, get_sender_test, test-contracts)
MAKE_READ_WASM_ABI(get_table_test, get_table_test, test-contracts)
MAKE_READ_WASM_ABI(get_table_seckey_test, get_table_seckey_test, test-contracts)
MAKE_READ_WASM_ABI(noop, noop, test-contracts)
MAKE_READ_WASM_ABI(payloadless, payloadless, test-contracts)
MAKE_READ_WASM_ABI(proxy, proxy, test-contracts)
MAKE_READ_WASM_ABI(ram_restrictions_test, ram_restrictions_test, test-contracts)
MAKE_READ_WASM_ABI(reject_all, reject_all, test-contracts)
MAKE_READ_WASM_ABI(restrict_action_test, restrict_action_test, test-contracts)
MAKE_READ_WASM_ABI(snapshot_test, snapshot_test, test-contracts)
MAKE_READ_WASM_ABI(test_api, test_api, test-contracts)
MAKE_READ_WASM_ABI(test_api_db, test_api_db, test-contracts)
MAKE_READ_WASM_ABI(test_api_multi_index, test_api_multi_index, test-contracts)
MAKE_READ_WASM_ABI(test_ram_limit, test_ram_limit, test-contracts)
MAKE_READ_WASM_ABI(action_results, action_results, test-contracts)
MAKE_READ_WASM_ABI(wasm_config_bios, wasm_config_bios, test-contracts)
MAKE_READ_WASM_ABI(params_test, params_test, test-contracts)
MAKE_READ_WASM_ABI(crypto_primitives_test,crypto_primitives_test,test-contracts)
MAKE_READ_WASM_ABI(get_block_num_test, get_block_num_test, test-contracts)
MAKE_READ_WASM_ABI(nested_container_multi_index, nested_container_multi_index, test-contracts)

};
} /// eosio::testing
} /// eosio
26 changes: 26 additions & 0 deletions libraries/testing/contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required( VERSION 3.8 )
project(testing_contracts)

if( EOSIO_COMPILE_TEST_CONTRACTS )
set(EOSIO_WASM_OLD_BEHAVIOR "Off")
if(USE_EOSIO_CDT_1_7_X OR USE_EOSIO_CDT_1_8_X)
find_package( eosio.cdt REQUIRED )
else()
find_package( cdt REQUIRED )
endif()
endif()

if ("${CMAKE_GENERATOR}" STREQUAL "Ninja")
add_compile_options(-fcolor-diagnostics)
endif()

if( USE_EOSIO_CDT_1_7_X )
add_definitions(-DUSE_EOSIO_CDT_1_7_X=true)
elseif( USE_EOSIO_CDT_1_8_X )
add_definitions(-DUSE_EOSIO_CDT_1_8_X=true)
endif()

add_subdirectory(eosio.bios)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/old_versions/v1.6.0-rc3/eosio.bios/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/old_versions/v1.6.0-rc3/eosio.bios/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/old_versions/v1.7.0-develop-preactivate_feature/eosio.bios/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/old_versions/v1.7.0-develop-preactivate_feature/eosio.bios/)
6 changes: 6 additions & 0 deletions libraries/testing/contracts/eosio.bios/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if( EOSIO_COMPILE_TEST_CONTRACTS )
add_contract( eosio.bios eosio.bios eosio.bios.cpp )
else()
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/eosio.bios.wasm ${CMAKE_CURRENT_BINARY_DIR}/eosio.bios.wasm COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/eosio.bios.abi ${CMAKE_CURRENT_BINARY_DIR}/eosio.bios.abi COPYONLY )
endif()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.1",
"version": "eosio::abi/1.2",
"types": [
{
"new_type_name": "block_signing_authority",
Expand Down Expand Up @@ -362,24 +362,6 @@
}
]
},
{
"name": "setglimits",
"base": "",
"fields": [
{
"name": "ram",
"type": "uint64"
},
{
"name": "net",
"type": "uint64"
},
{
"name": "cpu",
"type": "uint64"
}
]
},
{
"name": "setparams",
"base": "",
Expand Down Expand Up @@ -473,87 +455,82 @@
{
"name": "activate",
"type": "activate",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "canceldelay",
"type": "canceldelay",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "deleteauth",
"type": "deleteauth",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "linkauth",
"type": "linkauth",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "newaccount",
"type": "newaccount",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "onerror",
"type": "onerror",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "reqactivated",
"type": "reqactivated",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "reqauth",
"type": "reqauth",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setabi",
"type": "setabi",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setalimits",
"type": "setalimits",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setcode",
"type": "setcode",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
},
{
"name": "setglimits",
"type": "setglimits",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setparams",
"type": "setparams",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setpriv",
"type": "setpriv",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "setprods",
"type": "setprods",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "unlinkauth",
"type": "unlinkauth",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
},
{
"name": "updateauth",
"type": "updateauth",
"ricardian_contract": "---\ntitle: TITLE\nsummary: SUMMARY\nicon: ICON\n---\n\nBODY"
"ricardian_contract": ""
}
],
"tables": [
Expand All @@ -571,5 +548,6 @@
"name": "variant_block_signing_authority_v0",
"types": ["block_signing_authority_v0"]
}
]
],
"action_results": []
}
Loading