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

embed contracts required for native contract unit testing in to libtester #680

Merged
merged 2 commits into from
Jul 19, 2022
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
3 changes: 3 additions & 0 deletions libraries/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ configure_file(contracts.hpp.in include/testing_contracts/contracts.hpp ESCAPE_Q
add_library(eosio_testing_contracts INTERFACE)
target_include_directories(eosio_testing_contracts INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/testing_contracts)

configure_file(contracts.cpp.in contracts.cpp ESCAPE_QUOTES)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a defect here. contracts.cpp depends on the various wasm/abi files it embeds and the build system is oblivious to that. Unfortunately attaching proper dependencies is going to require some reorganization due to these wasm/abi files being placed in to CMAKE_BINARY_DIR via unittests/contracts, which is currently executed after libraries/testing. I don't have a low touch fix for the reorg required to properly fix.


## SORT .cpp by most likely to change / break compile
add_library( eosio_testing
tester.cpp
tester_network.cpp
${CMAKE_CURRENT_BINARY_DIR}/contracts.cpp
${HEADERS}
)

Expand Down
24 changes: 24 additions & 0 deletions libraries/testing/contracts.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <contracts.hpp>

#include <stdint.h>
#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"); \
\
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<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); \
} \
}

MAKE_EMBEDDED_WASM_ABI(eosio_bios, eosio.bios, contracts)
MAKE_EMBEDDED_WASM_ABI(before_producer_authority_eosio_bios, eosio.bios, contracts/old_versions/v1.7.0-develop-preactivate_feature)
MAKE_EMBEDDED_WASM_ABI(before_preactivate_eosio_bios, eosio.bios, contracts/old_versions/v1.6.0-rc3)
12 changes: 9 additions & 3 deletions libraries/testing/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ struct core_sym {
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<char> CN ## _abi();

namespace eosio {
namespace testing {
struct contracts {
// Contracts in `eos/unittests/contracts' directory
MAKE_READ_WASM_ABI(eosio_bios, eosio.bios, contracts)
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_READ_WASM_ABI(before_producer_authority_eosio_bios, eosio.bios, contracts/old_versions/v1.7.0-develop-preactivate_feature)
MAKE_READ_WASM_ABI(before_preactivate_eosio_bios, eosio.bios, contracts/old_versions/v1.6.0-rc3)
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)
Expand Down
Loading