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

[2.0.x] epe-37 fixed test-contracts build #9101

Closed
wants to merge 2 commits into from
Closed
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
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
5 changes: 4 additions & 1 deletion unittests/test-contracts/snapshot_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
if( EOSIO_COMPILE_TEST_CONTRACTS )
if( EOSIO_COMPILE_TEST_CONTRACTS AND 0 )
# This contract should not be rebuilt, because the saved snapshots in
# unittests/snapshots/ contain a copy of the current version of the contract
# and snapshot_tests requires it to be identical.
add_contract( snapshot_test snapshot_test snapshot_test.cpp )
else()
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snapshot_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/snapshot_test.wasm COPYONLY )
Expand Down
46 changes: 21 additions & 25 deletions unittests/test-contracts/test_api/test_action.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#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"

Expand Down Expand Up @@ -56,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 @@ -79,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 @@ -100,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 @@ -137,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" );
}

Expand Down Expand Up @@ -181,7 +175,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 @@ -207,7 +201,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 @@ -234,7 +230,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