diff --git a/libraries/chainbase b/libraries/chainbase index d48ebabf56b4115753fcabb7648a0ffcf3b0f5e9..b7e07526feec60f887b7579ad9cae78999940fd7 160000 --- a/libraries/chainbase +++ b/libraries/chainbase @@ -1 +1 @@ -Subproject commit d48ebabf56b4115753fcabb7648a0ffcf3b0f5e9 +Subproject commit b7e07526feec60f887b7579ad9cae78999940fd7 diff --git a/libraries/fc/CMakeLists.txt b/libraries/fc/CMakeLists.txt index b6e0628cf7d142bf6b04638f52915d61ac6438a1..7ec773797dc0a2ed01b45dfd569641c58d2862e2 100644 --- a/libraries/fc/CMakeLists.txt +++ b/libraries/fc/CMakeLists.txt @@ -2,7 +2,7 @@ #INCLUDE(GetPrerequisites) #INCLUDE(VersionMacros) -SET( DEFAULT_HEADER_INSTALL_DIR include/\${target} ) +SET( DEFAULT_HEADER_INSTALL_DIR include/${target} ) SET( DEFAULT_LIBRARY_INSTALL_DIR lib/ ) SET( DEFAULT_EXECUTABLE_INSTALL_DIR bin/ ) SET( CMAKE_DEBUG_POSTFIX _debug ) @@ -112,8 +112,15 @@ set( sources #list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp") list(APPEND sources ${fc_headers}) -setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC DONT_INSTALL_LIBRARY ) +setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC ) +INSTALL( TARGETS fc + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION . ) + IF(APPLE) # As of 10.10 yosemite, the OpenSSL static libraries shipped with os x have a dependency # on zlib, so any time you link in openssl you also need to link zlib. . We really want to detect whether openssl was configured with the --no-zlib diff --git a/libraries/types/CMakeLists.txt b/libraries/types/CMakeLists.txt index 273e5ca76da5d818d7dea2964c41e1882b8d4c07..298d8041a10fa8ffad5da5b4d89fec683229bfdf 100644 --- a/libraries/types/CMakeLists.txt +++ b/libraries/types/CMakeLists.txt @@ -20,4 +20,11 @@ target_link_libraries( type_generator eos_utilities fc ${CMAKE_DL_LIBS} ${PLATFO add_custom_command( OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/include/eos/types/generated.hpp" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/type_generator ${CMAKE_CURRENT_SOURCE_DIR}/types.eos ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/types/generated.hpp DEPENDS types.eos type_generator ) +INSTALL( TARGETS + eos_types + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +INSTALL( FILES ${HEADERS} DESTINATION "include/eos/types" ) diff --git a/libraries/utilities/CMakeLists.txt b/libraries/utilities/CMakeLists.txt index e2a42327e9f1f1e6ee2c7b58a30bbe3c3aaea61e..1ca72c6500ee9065e3a6d2953970bff23a00763e 100644 --- a/libraries/utilities/CMakeLists.txt +++ b/libraries/utilities/CMakeLists.txt @@ -14,6 +14,7 @@ set(sources string_escape.cpp tempdir.cpp words.cpp + wasm.cpp ${HEADERS}) #configure_file("${CMAKE_CURRENT_SOURCE_DIR}/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY) @@ -22,9 +23,10 @@ set(sources add_library( eos_utilities ${sources} ${HEADERS} ) -target_link_libraries( eos_utilities fc ) +target_link_libraries( eos_utilities fc WAST WASM ) target_include_directories( eos_utilities - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include" ) if (USE_PCH) set_target_properties(eos_utilities PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) cotire(eos_utilities) diff --git a/libraries/utilities/include/eos/utilities/wasm.hpp b/libraries/utilities/include/eos/utilities/wasm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2620439d8729212dcbefcc50c900aed8c1afb289 --- /dev/null +++ b/libraries/utilities/include/eos/utilities/wasm.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +namespace eos { namespace utilities { +std::vector assemble_wast(const std::string& wast); +} } // namespace eos::utilities diff --git a/libraries/utilities/wasm.cpp b/libraries/utilities/wasm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..afe7d7a5c5329ab2116f97785a51f19c4d5bbc04 --- /dev/null +++ b/libraries/utilities/wasm.cpp @@ -0,0 +1,48 @@ +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace eos { namespace utilities { + +std::vector assemble_wast( const std::string& wast ) { + IR::Module module; + std::vector parseErrors; + WAST::parseModule(wast.c_str(),wast.size(),module,parseErrors); + if(parseErrors.size()) + { + // Print any parse errors; + std::cerr << "Error parsing WebAssembly text file:" << std::endl; + for(auto& error : parseErrors) + { + std::cerr << ":" << error.locus.describe() << ": " << error.message.c_str() << std::endl; + std::cerr << error.locus.sourceLine << std::endl; + std::cerr << std::setw(error.locus.column(8)) << "^" << std::endl; + } + FC_ASSERT( !"error parsing wast" ); + } + + try + { + // Serialize the WebAssembly module. + Serialization::ArrayOutputStream stream; + WASM::serialize(stream,module); + return stream.getBytes(); + } + catch(Serialization::FatalSerializationException exception) + { + std::cerr << "Error serializing WebAssembly binary file:" << std::endl; + std::cerr << exception.message << std::endl; + throw; + } +} + +} } // namespace eos::utilities diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 5f0e997091b100463cb409956f8f1e281d8a3d4f..f5fbf6d14ca62baabc58ea9d6095410db8ca4106 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -142,15 +142,22 @@ protected: */ class testing_blockchain : public chain_controller { public: - testing_blockchain(chainbase::database& db, fork_database& fork_db, block_log& blocklog, + testing_blockchain(chainbase::database& db, fork_database& fork_db, block_log& blocklog, chain_initializer_interface& initializer, testing_fixture& fixture); + /** + * @brief Publish the provided contract to the blockchain, owned by owner + * @param owner The account to publish the contract under + * @param contract_wast The WAST of the contract + */ + void set_contract(AccountName owner, const char* contract_wast); + /** * @brief Produce new blocks, adding them to the blockchain, optionally following a gap of missed blocks * @param count Number of blocks to produce * @param blocks_to_miss Number of block intervals to miss a production before producing the next block * - * Creates and adds @ref count new blocks to the blockchain, after going @ref blocks_to_miss intervals without + * Creates and adds @ref count new blocks to the blockchain, after going @ref blocks_to_miss intervals without * producing a block. */ void produce_blocks(uint32_t count = 1, uint32_t blocks_to_miss = 0); diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index 88d229f0797f0047ff996faac3469f284237c931..55572e7dc7101901b1f794ede5590db495bd0389 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -74,6 +74,18 @@ inline std::vector sort_names( std::vector&& names ) { #define MKACCT7(chain, name, creator, deposit, owner, active, recovery) \ MKACCT_IMPL(chain, name, creator, owner, active, recovery, deposit) +#define SETCODE3(chain, acct, wast) \ + { \ + auto wasm = eos::utilities::assemble_wast(wast); \ + types::setcode handler; \ + handler.account = #acct; \ + handler.code.assign(wasm.begin(), wasm.end()); \ + eos::chain::SignedTransaction trx; \ + trx.scope = sort_names({config::EosContractName, #acct}); \ + transaction_emplace_message(trx, config::EosContractName, vector{{#acct,"active"}}, \ + "setcode", handler); \ + } + #define SETAUTH5(chain, account, authname, parentname, auth) \ { \ eos::chain::SignedTransaction trx; \ diff --git a/tests/common/testing_macros.hpp b/tests/common/testing_macros.hpp index 5a7c956ce94b9e3b66f9e47de1ca58eb39118fbf..d175bd69a5701c739ea22dff3b44a4ed11ba346f 100644 --- a/tests/common/testing_macros.hpp +++ b/tests/common/testing_macros.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "macro_support.hpp" /// Some helpful macros to reduce boilerplate when making testcases @@ -170,6 +172,16 @@ */ #define Make_Account(...) BOOST_PP_OVERLOAD(MKACCT, __VA_ARGS__)(__VA_ARGS__) +/** + * @brief Shorthand way to set the code for an account + * + * @code{.cpp} + * char* wast = //... + * Set_Code(chain, codeacct, wast); + * @endcode + */ +#define Set_Code(...) BOOST_PP_OVERLOAD(SETCODE, __VA_ARGS__)(__VA_ARGS__) + /** * @brief Shorthand way to create or update named authority on an account *