diff --git a/.gitignore b/.gitignore index 7b244ffc21f..9d6fb006349 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ *.wast.hpp /build/ /build-debug/ +/unittests/test-contracts/build/ /doxygen /*.doxygen diff --git a/scripts/daobet_build_ubuntu.sh b/scripts/daobet_build_ubuntu.sh index a6bfc40db86..fcf09aa0ac1 100755 --- a/scripts/daobet_build_ubuntu.sh +++ b/scripts/daobet_build_ubuntu.sh @@ -162,7 +162,7 @@ if [ -z $SKIP_DEPS_CHECK ]; then printf "\\n" printf "Checking Boost library (${BOOST_VERSION}) installation...\\n" - BOOSTVERSION=$( grep "#define BOOST_VERSION" "$INSTALL_PREFIX/opt/boost/include/boost/version.hpp" 2>/dev/null | tail -1 | tr -s ' ' | cut -d\ -f3 ) + BOOSTVERSION=$( grep "#define BOOST_VERSION" "$BOOST_ROOT/include/boost/version.hpp" 2>/dev/null | tail -1 | tr -s ' ' | cut -d\ -f3 ) if [ "${BOOSTVERSION}" != "${BOOST_VERSION_MAJOR}0${BOOST_VERSION_MINOR}0${BOOST_VERSION_PATCH}" ]; then printf "Installing Boost library...\\n" curl -LO https://dl.bintray.com/boostorg/release/${BOOST_VERSION_MAJOR}.${BOOST_VERSION_MINOR}.${BOOST_VERSION_PATCH}/source/boost_$BOOST_VERSION.tar.bz2 \ diff --git a/unittests/contracts.hpp.in b/unittests/contracts.hpp.in index 14717067b2a..f350238451a 100644 --- a/unittests/contracts.hpp.in +++ b/unittests/contracts.hpp.in @@ -41,6 +41,7 @@ namespace eosio { 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(rsa, rsa, test-contracts) }; } /// eosio::testing } /// eosio diff --git a/unittests/rsa_tests.cpp b/unittests/rsa_tests.cpp new file mode 100644 index 00000000000..b9315bdd628 --- /dev/null +++ b/unittests/rsa_tests.cpp @@ -0,0 +1,187 @@ +/** + * @file + * @copyright defined in eos/LICENSE.txt + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-compare" +#include +#pragma GCC diagnostic pop + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#ifdef NON_VALIDATING_TEST +#define TESTER tester +#else +#define TESTER validating_tester +#endif + +using namespace eosio; +using namespace eosio::chain; +using namespace eosio::testing; +using namespace fc; + +using mvo = fc::mutable_variant_object; +using bytes = std::vector; + +using RSA_ptr = std::unique_ptr; +using BIO_ptr = std::unique_ptr; +using EVP_PKEY_ptr = std::unique_ptr; + +class rsa_tester : public TESTER { +public: + void deploy_contract() { + create_accounts( {N(rsa)} ); + set_code( N(rsa), contracts::rsa_wasm() ); + set_abi( N(rsa), contracts::rsa_abi().data() ); + } + + RSA_ptr new_keys() { + static bool init = true; + if( init ) { + ERR_load_crypto_strings(); + init = false; + } + + auto rsa = RSA_ptr(RSA_generate_key(2048, 65537, NULL, NULL), ::RSA_free); + return rsa; + } + + std::string sign(const RSA_ptr& rsa, const sha256& digest) { + bytes signature; + signature.resize(RSA_size(rsa.get())); + uint32_t len; + RSA_sign(NID_sha256, (uint8_t*)digest.data(), 32, + (unsigned char*)signature.data(), &len, rsa.get()); + return fc::base64_encode(signature.data(), signature.size()); + } + + std::string pem_pubkey(const RSA_ptr& rsa) { + auto pkey = EVP_PKEY_ptr(EVP_PKEY_new(), ::EVP_PKEY_free); + EVP_PKEY_set1_RSA(pkey.get(), rsa.get()); + + auto mem = BIO_ptr(BIO_new(BIO_s_mem()), ::BIO_free); + PEM_write_bio_PUBKEY(mem.get(), pkey.get()); + + BUF_MEM *bio_buf; + BIO_get_mem_ptr(mem.get(), &bio_buf); + + std::stringstream ss({bio_buf->data, bio_buf->length}); + std::string pem; + + while (ss) { + std::string tmp; + std::getline(ss, tmp); + if (tmp[0] != '-') { + pem += tmp; + } + } + + return pem; + } +}; + +BOOST_AUTO_TEST_SUITE(rsa_tests) + +BOOST_FIXTURE_TEST_CASE( success, rsa_tester ) { + deploy_contract(); + + std::string message = "I'm message"; + fc::sha256 digest = fc::sha256::hash(message); + auto keys = new_keys(); + auto signature = sign(keys, digest); + + push_action(N(rsa), N(verify), N(rsa), mvo() + ("digest", digest) + ("sig", signature) + ("pubkey", pem_pubkey(keys)) + ); +} + +BOOST_FIXTURE_TEST_CASE( invalid_signature, rsa_tester ) { + deploy_contract(); + + std::string message = "I'm new message"; + fc::sha256 digest = fc::sha256::hash(message); + auto keys = new_keys(); + auto keys2 = new_keys(); + auto signature = sign(keys2, digest); // <- signature by another key + + BOOST_CHECK_THROW(push_action(N(rsa), N(verify), N(rsa), mvo() + ("digest", digest) + ("sig", signature) + ("pubkey", pem_pubkey(keys)) + ), fc::exception); +} + +BOOST_FIXTURE_TEST_CASE( invalid_key, rsa_tester ) { + deploy_contract(); + + std::string message = "I'm new message"; + fc::sha256 digest = fc::sha256::hash(message); + auto keys = new_keys(); + auto keys2 = new_keys(); + auto signature = sign(keys, digest); + auto pem = pem_pubkey(keys2); // <- another key + + BOOST_CHECK_THROW(push_action(N(rsa), N(verify), N(rsa), mvo() + ("digest", digest) + ("sig", signature) + ("pubkey", pem) + ), fc::exception); +} + +BOOST_FIXTURE_TEST_CASE( invalid_digest, rsa_tester ) { + deploy_contract(); + + std::string message = "I'm new message"; + std::string message2 = "I'm another new message"; + + fc::sha256 digest = fc::sha256::hash(message); + fc::sha256 digest2 = fc::sha256::hash(message2); // <- digest from another message + + auto keys = new_keys(); + auto signature = sign(keys, digest); + + BOOST_CHECK_THROW(push_action(N(rsa), N(verify), N(rsa), mvo() + ("digest", digest2) + ("sig", signature) + ("pubkey", pem_pubkey(keys)) + ), fc::exception); +} + +BOOST_FIXTURE_TEST_CASE( long_message, rsa_tester ) { + deploy_contract(); + + std::string message; + for (auto i = 0; i < 1024; ++i) { // <- generate long message + message += "A"; + } + + auto digest = fc::sha256::hash(message); + auto keys = new_keys(); + auto signature = sign(keys, digest); + + push_action(N(rsa), N(verify), N(rsa), mvo() + ("digest", digest) + ("sig", signature) + ("pubkey", pem_pubkey(keys)) + ); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/unittests/test-contracts/CMakeLists.txt b/unittests/test-contracts/CMakeLists.txt index 59f4ec0c28d..dcc6ddfbdea 100644 --- a/unittests/test-contracts/CMakeLists.txt +++ b/unittests/test-contracts/CMakeLists.txt @@ -1,3 +1,10 @@ +# macro add *.abi files to executable resources +macro(add_contract_with_abi CONTRACT_NAME TARGET) + add_contract( ${TARGET} ${CONTRACT_NAME} ${ARGN} ) + get_target_property(BINOUTPUT ${TARGET} BINARY_DIR) + set_target_properties( ${TARGET} PROPERTIES RESOURCE ${BINOUTPUT}/${TARGET}.abi) +endmacro() + if( EOSIO_COMPILE_TEST_CONTRACTS ) set(EOSIO_WASM_OLD_BEHAVIOR "Off") find_package( eosio.cdt REQUIRED ) @@ -18,3 +25,4 @@ add_subdirectory( test_api ) add_subdirectory( test_api_db ) add_subdirectory( test_api_multi_index ) add_subdirectory( test_ram_limit ) +add_subdirectory( rsa ) diff --git a/unittests/test-contracts/README.md b/unittests/test-contracts/README.md index 8b03cc131cd..f7056801e29 100644 --- a/unittests/test-contracts/README.md +++ b/unittests/test-contracts/README.md @@ -1,5 +1,11 @@ -test_ram_limit contract was compiled with eosio.cdt v1.4.1 +# BUILD + - Install EOSIO.CDT v1.6.1 + - ```EOSIO_CDT_CMAKE= ./build.sh``` -That contract was ported to compile with eosio.cdt v1.5.0, but the test that uses it is very sensitive to stdlib/eosiolib changes, compilation flags and linker flags. +`EOSIO_CDT_CMAKE` is path to `eosio.cdt` cmake module on your host, usually located at `/usr/lib/cmake/eosio.cdt` after install EOSIO.CDT from package manager. +If you don't specify `EOSIO_CDT_CMAKE` then script will use `/usr/lib/cmake/eosio.cdt` path. If your cmake module located at another dir than `/usr/lib/cmake/eosio.cdt` you have to explicitly set path to script. -The remaining contracts have been ported to compile with eosio.cdt v1.6.x. They were compiled with a patched version of eosio.cdt v1.6.0-rc1 (commit 1c9180ff5a1e431385180ce459e11e6a1255c1a4). + +# NOTE +`test_ram_limit` contract was compiled with eosio.cdt v1.4.1 and build.sh doesn't rebuild it. +That contract can be compiled with eosio.cdt v1.5.0, but the test that uses it is very sensitive to stdlib/eosiolib changes, compilation flags and linker flags. diff --git a/unittests/test-contracts/asserter/CMakeLists.txt b/unittests/test-contracts/asserter/CMakeLists.txt index c9c992df101..1a441e6cf21 100644 --- a/unittests/test-contracts/asserter/CMakeLists.txt +++ b/unittests/test-contracts/asserter/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( asserter asserter asserter.cpp ) + add_contract_with_abi( asserter asserter asserter.cpp ) + target_include_directories( asserter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS asserter DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/asserter.wasm ${CMAKE_CURRENT_BINARY_DIR}/asserter.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/asserter.abi ${CMAKE_CURRENT_BINARY_DIR}/asserter.abi COPYONLY ) diff --git a/unittests/test-contracts/asserter/asserter.cpp b/unittests/test-contracts/asserter/asserter.cpp index 3402e9d9940..ba13c4d8b2c 100644 --- a/unittests/test-contracts/asserter/asserter.cpp +++ b/unittests/test-contracts/asserter/asserter.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "asserter.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/asserter/asserter.wasm b/unittests/test-contracts/asserter/asserter.wasm index 050b3caf56e..ec45f36d167 100755 Binary files a/unittests/test-contracts/asserter/asserter.wasm and b/unittests/test-contracts/asserter/asserter.wasm differ diff --git a/unittests/test-contracts/build.sh b/unittests/test-contracts/build.sh new file mode 100755 index 00000000000..71480e61144 --- /dev/null +++ b/unittests/test-contracts/build.sh @@ -0,0 +1,19 @@ +#! /bin/bash +set -e + +EOSIO_CDT_CMAKE=${EOSIO_CDT_CMAKE:-/usr/lib/cmake/eosio.cdt} + +if [[ ! -d ${EOSIO_CDT_CMAKE} ]]; then + echo "Invalid EOSIO_CDT_CMAKE: dir doesn't exists" + exit 1 +fi + +EOSIO_CDT_TOOLCHAIN="${EOSIO_CDT_CMAKE}/EosioWasmToolchain.cmake" + +if [[ ! -d "./build" ]]; then + mkdir build +fi + +cd build +cmake -DEOSIO_COMPILE_TEST_CONTRACTS=1 -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_TOOLCHAIN} .. +make install diff --git a/unittests/test-contracts/deferred_test/CMakeLists.txt b/unittests/test-contracts/deferred_test/CMakeLists.txt index 9ff36a6f57f..b91dbe77a10 100644 --- a/unittests/test-contracts/deferred_test/CMakeLists.txt +++ b/unittests/test-contracts/deferred_test/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( deferred_test deferred_test deferred_test.cpp ) + add_contract_with_abi( deferred_test deferred_test deferred_test.cpp ) + target_include_directories( deferred_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS deferred_test DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/deferred_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/deferred_test.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/deferred_test.abi ${CMAKE_CURRENT_BINARY_DIR}/deferred_test.abi COPYONLY ) diff --git a/unittests/test-contracts/deferred_test/deferred_test.cpp b/unittests/test-contracts/deferred_test/deferred_test.cpp index 54c02ed4a95..b5aceddc3a0 100644 --- a/unittests/test-contracts/deferred_test/deferred_test.cpp +++ b/unittests/test-contracts/deferred_test/deferred_test.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "deferred_test.hpp" +#include #include using namespace eosio; diff --git a/unittests/test-contracts/deferred_test/deferred_test.wasm b/unittests/test-contracts/deferred_test/deferred_test.wasm index eea70b8dc6e..d2ee3c32d19 100755 Binary files a/unittests/test-contracts/deferred_test/deferred_test.wasm and b/unittests/test-contracts/deferred_test/deferred_test.wasm differ diff --git a/unittests/test-contracts/integration_test/CMakeLists.txt b/unittests/test-contracts/integration_test/CMakeLists.txt index aaf8d2115ea..7d0598a79a2 100644 --- a/unittests/test-contracts/integration_test/CMakeLists.txt +++ b/unittests/test-contracts/integration_test/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( integration_test integration_test integration_test.cpp ) + add_contract_with_abi( integration_test integration_test integration_test.cpp ) + target_include_directories( integration_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS integration_test DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/integration_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/integration_test.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/integration_test.abi ${CMAKE_CURRENT_BINARY_DIR}/integration_test.abi COPYONLY ) diff --git a/unittests/test-contracts/integration_test/integration_test.cpp b/unittests/test-contracts/integration_test/integration_test.cpp index ec8543caafb..1acbde8aad1 100644 --- a/unittests/test-contracts/integration_test/integration_test.cpp +++ b/unittests/test-contracts/integration_test/integration_test.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "integration_test.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/integration_test/integration_test.wasm b/unittests/test-contracts/integration_test/integration_test.wasm index 81e7b13d274..a5301ab3da6 100755 Binary files a/unittests/test-contracts/integration_test/integration_test.wasm and b/unittests/test-contracts/integration_test/integration_test.wasm differ diff --git a/unittests/test-contracts/noop/CMakeLists.txt b/unittests/test-contracts/noop/CMakeLists.txt index 8d93cdd3bcf..52fee7b8847 100644 --- a/unittests/test-contracts/noop/CMakeLists.txt +++ b/unittests/test-contracts/noop/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( noop noop noop.cpp ) + add_contract_with_abi( noop noop noop.cpp ) + target_include_directories( noop PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS noop DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/noop.wasm ${CMAKE_CURRENT_BINARY_DIR}/noop.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/noop.abi ${CMAKE_CURRENT_BINARY_DIR}/noop.abi COPYONLY ) diff --git a/unittests/test-contracts/noop/noop.cpp b/unittests/test-contracts/noop/noop.cpp index 94fd344495f..f1bb3be0f47 100644 --- a/unittests/test-contracts/noop/noop.cpp +++ b/unittests/test-contracts/noop/noop.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "noop.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/noop/noop.wasm b/unittests/test-contracts/noop/noop.wasm index 1dc548e7e63..42a3ab3c80d 100755 Binary files a/unittests/test-contracts/noop/noop.wasm and b/unittests/test-contracts/noop/noop.wasm differ diff --git a/unittests/test-contracts/payloadless/CMakeLists.txt b/unittests/test-contracts/payloadless/CMakeLists.txt index 6e3cd8176d0..04d84b37244 100644 --- a/unittests/test-contracts/payloadless/CMakeLists.txt +++ b/unittests/test-contracts/payloadless/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( payloadless payloadless payloadless.cpp ) + add_contract_with_abi( payloadless payloadless payloadless.cpp ) + target_include_directories( payloadless PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS payloadless DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/payloadless.wasm ${CMAKE_CURRENT_BINARY_DIR}/payloadless.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/payloadless.abi ${CMAKE_CURRENT_BINARY_DIR}/payloadless.abi COPYONLY ) diff --git a/unittests/test-contracts/payloadless/payloadless.cpp b/unittests/test-contracts/payloadless/payloadless.cpp index 70939590e50..9c4acfa93fa 100644 --- a/unittests/test-contracts/payloadless/payloadless.cpp +++ b/unittests/test-contracts/payloadless/payloadless.cpp @@ -3,7 +3,7 @@ * @copyright defined in eos/LICENSE */ -#include "payloadless.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/payloadless/payloadless.wasm b/unittests/test-contracts/payloadless/payloadless.wasm index 330682f6096..9d7deea6217 100755 Binary files a/unittests/test-contracts/payloadless/payloadless.wasm and b/unittests/test-contracts/payloadless/payloadless.wasm differ diff --git a/unittests/test-contracts/proxy/CMakeLists.txt b/unittests/test-contracts/proxy/CMakeLists.txt index 12a9d309d4c..074b187d4f2 100644 --- a/unittests/test-contracts/proxy/CMakeLists.txt +++ b/unittests/test-contracts/proxy/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( proxy proxy proxy.cpp ) + add_contract_with_abi( proxy proxy proxy.cpp ) + target_include_directories( proxy PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS proxy DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/proxy.wasm ${CMAKE_CURRENT_BINARY_DIR}/proxy.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/proxy.abi ${CMAKE_CURRENT_BINARY_DIR}/proxy.abi COPYONLY ) diff --git a/unittests/test-contracts/proxy/proxy.cpp b/unittests/test-contracts/proxy/proxy.cpp index 1a199c4a5ba..31dab34df5a 100644 --- a/unittests/test-contracts/proxy/proxy.cpp +++ b/unittests/test-contracts/proxy/proxy.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "proxy.hpp" +#include #include using namespace eosio; diff --git a/unittests/test-contracts/proxy/proxy.wasm b/unittests/test-contracts/proxy/proxy.wasm index c09311385be..4576b72548f 100755 Binary files a/unittests/test-contracts/proxy/proxy.wasm and b/unittests/test-contracts/proxy/proxy.wasm differ diff --git a/unittests/test-contracts/rsa/CMakeLists.txt b/unittests/test-contracts/rsa/CMakeLists.txt new file mode 100644 index 00000000000..a8fb653c9be --- /dev/null +++ b/unittests/test-contracts/rsa/CMakeLists.txt @@ -0,0 +1,8 @@ +if( EOSIO_COMPILE_TEST_CONTRACTS ) + add_contract_with_abi( rsa rsa rsa.cpp ) + target_include_directories( rsa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS rsa DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) +else() + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rsa.wasm ${CMAKE_CURRENT_BINARY_DIR}/rsa.wasm COPYONLY ) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/rsa.abi ${CMAKE_CURRENT_BINARY_DIR}/rsa.abi COPYONLY ) +endif() diff --git a/unittests/test-contracts/rsa/rsa.abi b/unittests/test-contracts/rsa/rsa.abi new file mode 100644 index 00000000000..45b29fa3afd --- /dev/null +++ b/unittests/test-contracts/rsa/rsa.abi @@ -0,0 +1,35 @@ +{ + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "version": "eosio::abi/1.1", + "types": [], + "structs": [ + { + "name": "verify", + "base": "", + "fields": [ + { + "name": "digest", + "type": "checksum256" + }, + { + "name": "sig", + "type": "string" + }, + { + "name": "pubkey", + "type": "string" + } + ] + } + ], + "actions": [ + { + "name": "verify", + "type": "verify", + "ricardian_contract": "" + } + ], + "tables": [], + "ricardian_clauses": [], + "variants": [] +} \ No newline at end of file diff --git a/unittests/test-contracts/rsa/rsa.cpp b/unittests/test-contracts/rsa/rsa.cpp new file mode 100644 index 00000000000..0213e37a020 --- /dev/null +++ b/unittests/test-contracts/rsa/rsa.cpp @@ -0,0 +1,8 @@ +#include + +void rsa::verify(const eosio::checksum256& digest, + const std::string& sig, + const std::string& pubkey) +{ + eosio::check( daobet::rsa_verify(digest, sig, pubkey), "invalid signature" ); +} diff --git a/unittests/test-contracts/rsa/rsa.hpp b/unittests/test-contracts/rsa/rsa.hpp new file mode 100644 index 00000000000..aa790322be4 --- /dev/null +++ b/unittests/test-contracts/rsa/rsa.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +extern "C" { + __attribute__((eosio_wasm_import)) + int rsa_verify( const capi_checksum256* digest, const char* sig, + size_t siglen, const char* pub, size_t publen ); +} + +namespace daobet { + bool rsa_verify(const eosio::checksum256& digest, const std::string& sig, const std::string& pubkey) { + auto digest_data = digest.extract_as_byte_array(); + return ::rsa_verify(reinterpret_cast(digest_data.data()), + sig.c_str(), sig.size(), pubkey.c_str(), pubkey.size()); + } +} + + +class [[eosio::contract]] rsa : public eosio::contract { +public: + using eosio::contract::contract; + + [[eosio::action]] + void verify(const eosio::checksum256& digest, const std::string& sig, const std::string& pubkey); +}; diff --git a/unittests/test-contracts/rsa/rsa.wasm b/unittests/test-contracts/rsa/rsa.wasm new file mode 100755 index 00000000000..29386a794ee Binary files /dev/null and b/unittests/test-contracts/rsa/rsa.wasm differ diff --git a/unittests/test-contracts/snapshot_test/CMakeLists.txt b/unittests/test-contracts/snapshot_test/CMakeLists.txt index a628753d325..f5f5d46e350 100644 --- a/unittests/test-contracts/snapshot_test/CMakeLists.txt +++ b/unittests/test-contracts/snapshot_test/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( snapshot_test snapshot_test snapshot_test.cpp ) + add_contract_with_abi( snapshot_test snapshot_test snapshot_test.cpp ) + target_include_directories( snapshot_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS snapshot_test DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snapshot_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/snapshot_test.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snapshot_test.abi ${CMAKE_CURRENT_BINARY_DIR}/snapshot_test.abi COPYONLY ) diff --git a/unittests/test-contracts/snapshot_test/snapshot_test.cpp b/unittests/test-contracts/snapshot_test/snapshot_test.cpp index 84e28e53ec7..5539f0cf995 100644 --- a/unittests/test-contracts/snapshot_test/snapshot_test.cpp +++ b/unittests/test-contracts/snapshot_test/snapshot_test.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "snapshot_test.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/snapshot_test/snapshot_test.wasm b/unittests/test-contracts/snapshot_test/snapshot_test.wasm index 48e05489e19..3acb9418f5f 100755 Binary files a/unittests/test-contracts/snapshot_test/snapshot_test.wasm and b/unittests/test-contracts/snapshot_test/snapshot_test.wasm differ diff --git a/unittests/test-contracts/test_api/CMakeLists.txt b/unittests/test-contracts/test_api/CMakeLists.txt index 5cc77922002..7a00cd16f36 100644 --- a/unittests/test-contracts/test_api/CMakeLists.txt +++ b/unittests/test-contracts/test_api/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) add_executable( test_api test_api.cpp ) + target_include_directories( test_api PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS test_api DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/test_api.wasm ${CMAKE_CURRENT_BINARY_DIR}/test_api.wasm COPYONLY ) endif() diff --git a/unittests/test-contracts/test_api/test_api.cpp b/unittests/test-contracts/test_api/test_api.cpp index 598990dc1a7..4c31475d643 100644 --- a/unittests/test-contracts/test_api/test_api.cpp +++ b/unittests/test-contracts/test_api/test_api.cpp @@ -5,17 +5,17 @@ #include #include -#include "test_api.hpp" - -#include "test_action.cpp" -#include "test_chain.cpp" -#include "test_checktime.cpp" -#include "test_crypto.cpp" -#include "test_datastream.cpp" -#include "test_permission.cpp" -#include "test_print.cpp" -#include "test_transaction.cpp" -#include "test_types.cpp" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include name global_receiver; diff --git a/unittests/test-contracts/test_api/test_api.wasm b/unittests/test-contracts/test_api/test_api.wasm index c7a7601ace1..99cdc4dd743 100755 Binary files a/unittests/test-contracts/test_api/test_api.wasm and b/unittests/test-contracts/test_api/test_api.wasm differ diff --git a/unittests/test-contracts/test_api_db/CMakeLists.txt b/unittests/test-contracts/test_api_db/CMakeLists.txt index 0986dc0cb6c..5724ad3e53e 100644 --- a/unittests/test-contracts/test_api_db/CMakeLists.txt +++ b/unittests/test-contracts/test_api_db/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( test_api_db test_api_db test_api_db.cpp ) + add_contract_with_abi( test_api_db test_api_db test_api_db.cpp ) + target_include_directories( test_api_db PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS test_api_db DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/test_api_db.wasm ${CMAKE_CURRENT_BINARY_DIR}/test_api_db.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/test_api_db.abi ${CMAKE_CURRENT_BINARY_DIR}/test_api_db.abi COPYONLY ) diff --git a/unittests/test-contracts/test_api_db/test_api_db.cpp b/unittests/test-contracts/test_api_db/test_api_db.cpp index 7ab5ddf9ce5..82d799825c2 100644 --- a/unittests/test-contracts/test_api_db/test_api_db.cpp +++ b/unittests/test-contracts/test_api_db/test_api_db.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "test_api_db.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/test_api_db/test_api_db.wasm b/unittests/test-contracts/test_api_db/test_api_db.wasm index 5aefa71cd1a..8d7a282ca9d 100755 Binary files a/unittests/test-contracts/test_api_db/test_api_db.wasm and b/unittests/test-contracts/test_api_db/test_api_db.wasm differ diff --git a/unittests/test-contracts/test_api_multi_index/CMakeLists.txt b/unittests/test-contracts/test_api_multi_index/CMakeLists.txt index cd1264fb473..d99d41815fb 100644 --- a/unittests/test-contracts/test_api_multi_index/CMakeLists.txt +++ b/unittests/test-contracts/test_api_multi_index/CMakeLists.txt @@ -1,5 +1,7 @@ if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( test_api_multi_index test_api_multi_index test_api_multi_index.cpp ) + add_contract_with_abi( test_api_multi_index test_api_multi_index test_api_multi_index.cpp ) + target_include_directories( test_api_multi_index PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + install( TARGETS test_api_multi_index DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} ) else() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/test_api_multi_index.wasm ${CMAKE_CURRENT_BINARY_DIR}/test_api_multi_index.wasm COPYONLY ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/test_api_multi_index.abi ${CMAKE_CURRENT_BINARY_DIR}/test_api_multi_index.abi COPYONLY ) diff --git a/unittests/test-contracts/test_api_multi_index/test_api_multi_index.cpp b/unittests/test-contracts/test_api_multi_index/test_api_multi_index.cpp index 72e7d4e6a5b..7094f8ab1f5 100644 --- a/unittests/test-contracts/test_api_multi_index/test_api_multi_index.cpp +++ b/unittests/test-contracts/test_api_multi_index/test_api_multi_index.cpp @@ -2,7 +2,7 @@ * @file * @copyright defined in eos/LICENSE */ -#include "test_api_multi_index.hpp" +#include using namespace eosio; diff --git a/unittests/test-contracts/test_api_multi_index/test_api_multi_index.wasm b/unittests/test-contracts/test_api_multi_index/test_api_multi_index.wasm index c4cbb5f2584..de024b35a0d 100755 Binary files a/unittests/test-contracts/test_api_multi_index/test_api_multi_index.wasm and b/unittests/test-contracts/test_api_multi_index/test_api_multi_index.wasm differ