Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

[develop] Epe 37 fix test contracts build #9114

Merged
merged 6 commits into from
Jun 5, 2020
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
6 changes: 5 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ if( EOSIO_COMPILE_TEST_CONTRACTS )
set(EOSIO_WASM_OLD_BEHAVIOR "Off")
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} )
if( USE_EOSIO_CDT_1_7_X)
list(APPEND CMAKE_ARGS_VAL -DUSE_EOSIO_CDT_1_7_X=${USE_EOSIO_CDT_1_7_X})
endif()
message( STATUS "Building contracts in directory `eos/unittests/test-contracts/`" )
ExternalProject_Add(
test_contracts_project
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test-contracts
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/test-contracts
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake -DEOSIO_COMPILE_TEST_CONTRACTS=${EOSIO_COMPILE_TEST_CONTRACTS}
CMAKE_ARGS ${CMAKE_ARGS_VAL}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
Expand Down
4 changes: 4 additions & 0 deletions unittests/test-contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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)
endif()

add_subdirectory( asserter )
add_subdirectory( deferred_test )
add_subdirectory( get_sender_test )
Expand Down
15 changes: 0 additions & 15 deletions unittests/test-contracts/get_sender_test/get_sender_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@

#include <eosio/eosio.hpp>

namespace eosio {
namespace internal_use_do_not_use {
extern "C" {
__attribute__((eosio_wasm_import))
uint64_t get_sender();
}
}
}

namespace eosio {
name get_sender() {
return name( internal_use_do_not_use::get_sender() );
}
}

class [[eosio::contract]] get_sender_test : public eosio::contract {
public:
using eosio::contract::contract;
Expand Down
4 changes: 4 additions & 0 deletions unittests/test-contracts/kv_bios/kv_bios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
extern "C" __attribute__((eosio_wasm_import)) void set_resource_limit(int64_t, int64_t, int64_t);
extern "C" __attribute__((eosio_wasm_import)) uint32_t get_kv_parameters_packed(uint64_t db, void* params, uint32_t size, uint32_t max_version);
extern "C" __attribute__((eosio_wasm_import)) void set_kv_parameters_packed(uint64_t db, const void* params, uint32_t size);
#ifdef USE_EOSIO_CDT_1_7_X
extern "C" __attribute__((eosio_wasm_import)) uint32_t read_action_data( void* msg, uint32_t len );
extern "C" __attribute__((eosio_wasm_import)) uint32_t action_data_size();
#endif

using namespace eosio;

Expand Down
51 changes: 21 additions & 30 deletions unittests/test-contracts/test_api/test_action.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#include <eosiolib/action.hpp>
#include <eosiolib/chain.h>
#include <eosiolib/crypto.h>
#include <eosiolib/datastream.hpp>
#include <eosiolib/db.h>
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/privileged.h>
#include <eosiolib/transaction.hpp>
#include <eosio/action.hpp>
#include <eosio/crypto.hpp>
#include <eosio/datastream.hpp>
#include <eosio/eosio.hpp>
#include <eosio/print.hpp>
#include <eosio/transaction.hpp>

#include "test_api.hpp"

extern "C" {
__attribute__((eosio_wasm_import))
void set_action_return_value(const char*, size_t);
}

using namespace eosio;

void test_action::read_action_normal() {
Expand Down Expand Up @@ -61,7 +53,7 @@ void test_action::test_dummy_action() {

if ( dum13.b == 200 ) {
// attempt to access context free only api
get_context_free_data( 0, nullptr, 0 );
eosio::get_context_free_data( 0, nullptr, 0 );
eosio_assert( false, "get_context_free_data() not allowed in non-context free action" );
} else {
eosio_assert( dum13.a == DUMMY_ACTION_DEFAULT_A, "dum13.a == DUMMY_ACTION_DEFAULT_A" );
Expand All @@ -84,19 +76,18 @@ void test_action::test_cf_action() {
cf_action cfa = act.data_as<cf_action>();
if ( cfa.payload == 100 ) {
// verify read of get_context_free_data, also verifies system api access
int size = get_context_free_data( cfa.cfd_idx, nullptr, 0 );
int size = eosio::get_context_free_data( cfa.cfd_idx, nullptr, 0 );
eosio_assert( size > 0, "size determination failed" );
std::vector<char> cfd( static_cast<size_t>(size) );
size = get_context_free_data( cfa.cfd_idx, &cfd[0], static_cast<size_t>(size) );
size = eosio::get_context_free_data( cfa.cfd_idx, &cfd[0], static_cast<size_t>(size) );
eosio_assert(static_cast<size_t>(size) == cfd.size(), "get_context_free_data failed" );
uint32_t v = eosio::unpack<uint32_t>( &cfd[0], cfd.size() );
eosio_assert( v == cfa.payload, "invalid value" );

// verify crypto api access
capi_checksum256 hash;
char test[] = "test";
sha256( test, sizeof(test), &hash );
assert_sha256( test, sizeof(test), &hash );
auto hash = sha256( test, sizeof(test) );
eosio::assert_sha256( test, sizeof(test), hash );
// verify action api access
action_data_size();
// verify console api access
Expand All @@ -105,7 +96,7 @@ void test_action::test_cf_action() {
uint32_t i = 42;
memccpy( &v, &i, sizeof(i), sizeof(i) );
// verify transaction api access
eosio_assert(transaction_size() > 0, "transaction_size failed");
eosio_assert(eosio::transaction_size() > 0, "transaction_size failed");
// verify softfloat api access
float f1 = 1.0f, f2 = 2.0f;
float f3 = f1 + f2;
Expand Down Expand Up @@ -142,20 +133,18 @@ void test_action::test_cf_action() {
} else if ( cfa.payload == 206 ) {
eosio::require_auth("test"_n);
eosio_assert( false, "authorization_api should not be allowed" );
} else if ( cfa.payload == 207 ) {
now();
eosio_assert( false, "system_api should not be allowed" );
} else if ( cfa.payload == 208 ) {
} else if ( cfa.payload == 207 || cfa.payload == 208 ) {
// 207 is obsolete as now() is removed from system.h
current_time();
eosio_assert( false, "system_api should not be allowed" );
} else if ( cfa.payload == 209 ) {
publication_time();
eosio_assert( false, "system_api should not be allowed" );
} else if ( cfa.payload == 210 ) {
send_inline( (char*)"hello", 6 );
eosio::internal_use_do_not_use::send_inline( (char*)"hello", 6 );
eosio_assert( false, "transaction_api should not be allowed" );
} else if ( cfa.payload == 211 ) {
send_deferred( "testapi"_n.value, "testapi"_n.value, "hello", 6, 0 );
eosio::send_deferred( "testapi"_n.value, "testapi"_n, "hello", 6, 0 );
eosio_assert( false, "transaction_api should not be allowed" );
} else if ( cfa.payload == 212 ) {
set_action_return_value("hi", 2);
Expand Down Expand Up @@ -189,7 +178,7 @@ void test_action::require_notice_tests( uint64_t receiver, uint64_t code, uint64
}

void test_action::require_auth() {
prints("require_auth");
print("require_auth");
eosio::require_auth("acc3"_n);
eosio::require_auth("acc4"_n);
}
Expand All @@ -215,7 +204,9 @@ void test_action::test_publication_time() {
uint64_t pub_time = 0;
uint32_t total = read_action_data( &pub_time, sizeof(uint64_t) );
eosio_assert( total == sizeof(uint64_t), "total == sizeof(uint64_t)" );
eosio_assert( pub_time == publication_time(), "pub_time == publication_time()" );
time_point msec{ microseconds{static_cast<int64_t>(pub_time)}};
eosio_assert( msec == publication_time(), "pub_time == publication_time()" );

}

void test_action::test_current_receiver( uint64_t receiver, uint64_t code, uint64_t action ) {
Expand All @@ -242,7 +233,7 @@ void test_action::test_assert_code() {

void test_action::test_ram_billing_in_notify( uint64_t receiver, uint64_t code, uint64_t action ) {
uint128_t tmp = 0;
uint32_t total = read_action_data( &tmp, sizeof(uint128_t) );
uint32_t total = eosio::read_action_data( &tmp, sizeof(uint128_t) );
eosio_assert( total == sizeof(uint128_t), "total == sizeof(uint128_t)" );

uint64_t to_notify = tmp >> 64;
Expand Down
4 changes: 2 additions & 2 deletions unittests/test-contracts/test_api/test_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <eosiolib/eosio.hpp>
#include <eosiolib/transaction.hpp>
#include <eosio/eosio.hpp>
#include <eosio/transaction.hpp>

#include "test_api.hpp"

Expand Down
46 changes: 45 additions & 1 deletion unittests/test-contracts/test_api/test_api.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <string>

#include "../capi/eosio/types.h"
#include "test_api_common.hpp"

namespace eosio { class transaction; }
Expand All @@ -27,6 +27,50 @@ namespace eosio { class transaction; }
return; \
}

extern "C" {
__attribute__((eosio_wasm_import))
void set_action_return_value(const char*, size_t);

__attribute__((eosio_wasm_import))
void eosio_assert( uint32_t test, const char* msg );

__attribute__((eosio_wasm_import))
void eosio_assert_code( uint32_t test, uint64_t code );

__attribute__((eosio_wasm_import))
uint64_t current_time();

__attribute__((eosio_wasm_import))
int get_action( uint32_t type, uint32_t index, char* buff, size_t size );

//db.h
__attribute__((eosio_wasm_import))
int32_t db_store_i64(uint64_t scope, capi_name table, capi_name payer, uint64_t id, const void* data, uint32_t len);

__attribute__((eosio_wasm_import))
int32_t db_find_i64(capi_name code, uint64_t scope, capi_name table, uint64_t id);

__attribute__((eosio_wasm_import))
int32_t db_idx64_store(uint64_t scope, capi_name table, capi_name payer, uint64_t id, const uint64_t* secondary);

__attribute__((eosio_wasm_import))
void db_remove_i64(int32_t iterator);

__attribute__((eosio_wasm_import))
int32_t db_lowerbound_i64(capi_name code, uint64_t scope, capi_name table, uint64_t id);

__attribute__((eosio_wasm_import))
void db_update_i64(int32_t iterator, capi_name payer, const void* data, uint32_t len);

//privilege.h
__attribute__((eosio_wasm_import))
bool is_privileged( capi_name account );

// chain.h
__attribute__((eosio_wasm_import))
uint32_t get_active_producers( capi_name* producers, uint32_t datalen );
}

struct test_types {
static void types_size();
static void char_to_symbol();
Expand Down
3 changes: 1 addition & 2 deletions unittests/test-contracts/test_api/test_api_common.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <eosiolib/serialize.hpp>

#include <eosio/serialize.hpp>

static constexpr unsigned int DJBH( const char* cp )
{
Expand Down
5 changes: 2 additions & 3 deletions unittests/test-contracts/test_api/test_chain.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <eosiolib/action.h>
#include <eosiolib/chain.h>
#include <eosiolib/eosio.hpp>
#include <eosio/action.hpp>
#include <eosio/eosio.hpp>

#include "test_api.hpp"

Expand Down
35 changes: 16 additions & 19 deletions unittests/test-contracts/test_api/test_checktime.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <vector>

#include <eosiolib/crypto.h>
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.h>
#include <eosio/crypto.hpp>
#include <eosio/eosio.hpp>
#include <eosio/print.hpp>

#include "test_api.hpp"
using namespace eosio;

void test_checktime::checktime_pass() {
int p = 0;
Expand All @@ -31,48 +32,44 @@ constexpr size_t size = 20000000;

void test_checktime::checktime_sha1_failure() {
char* ptr = new char[size];
capi_checksum160 res;
sha1( ptr, size, &res );
auto res = sha1( ptr, size );
}

void test_checktime::checktime_assert_sha1_failure() {
char* ptr = new char[size];
capi_checksum160 res;
assert_sha1( ptr, size, &res );
checksum160 res;
assert_sha1( ptr, size, res );
}

void test_checktime::checktime_sha256_failure() {
char* ptr = new char[size];
capi_checksum256 res;
sha256( ptr, size, &res );
auto res = sha256( ptr, size );
}

void test_checktime::checktime_assert_sha256_failure() {
char* ptr = new char[size];
capi_checksum256 res;
assert_sha256( ptr, size, &res );
checksum256 res;
assert_sha256( ptr, size, res );
}

void test_checktime::checktime_sha512_failure() {
char* ptr = new char[size];
capi_checksum512 res;
sha512( ptr, size, &res );
auto res = sha512( ptr, size );
}

void test_checktime::checktime_assert_sha512_failure() {
char* ptr = new char[size];
capi_checksum512 res;
assert_sha512( ptr, size, &res );
checksum512 res;
assert_sha512( ptr, size, res );
}

void test_checktime::checktime_ripemd160_failure() {
char* ptr = new char[size];
capi_checksum160 res;
ripemd160( ptr, size, &res );
auto res = ripemd160( ptr, size );
}

void test_checktime::checktime_assert_ripemd160_failure() {
char* ptr = new char[size];
capi_checksum160 res;
assert_ripemd160( ptr, size, &res );
checksum160 res;
assert_ripemd160( ptr, size, res );
}
Loading