提交 f87cb717 编写于 作者: B Bucky Kittinger

Fixing up structure and moving tests back out to contracts

上级 0401bbb0
......@@ -3,8 +3,8 @@
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/account.hpp>
#include <eoslib/eos.hpp>
#include <eoslib/account.hpp>
#include <eoslib/system.h>
#include "test_api.hpp"
......@@ -18,15 +18,26 @@ unsigned int test_account::test_balance_acc1()
eosio::account::account_balance b;
b.account = N(acc1);
WASM_ASSERT(eosio::account::get(b), "account_balance_get should have found \"acc1\"");
WASM_ASSERT(b.account == N(acc1), "account_balance_get should not change the account");
WASM_ASSERT(b.eos_balance.amount == 24, "account_balance_get should have set a balance of 24");
WASM_ASSERT(b.eos_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a balance symbol of EOS");
WASM_ASSERT(b.staked_balance.amount == 23, "account_balance_get should have set a staked balance of 23");
WASM_ASSERT(b.staked_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a staked balance symbol of EOS");
WASM_ASSERT(b.unstaking_balance.amount == 14, "account_balance_get should have set a unstaking balance of 14");
WASM_ASSERT(b.unstaking_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a unstaking balance symbol of EOS");
WASM_ASSERT(b.last_unstaking_time == 55, "account_balance_get should have set a last unstaking time of 55");
return WASM_TEST_PASS;
assert(eosio::account::get(b), "account_balance_get should have found \"acc1\"");
assert(b.account == N(acc1), "account_balance_get should not change the account");
assert(b.eos_balance.amount == 24, "account_balance_get should have set a balance of 24");
assert(b.eos_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a balance symbol of EOS");
assert(b.staked_balance.amount == 23, "account_balance_get should have set a staked balance of 23");
assert(b.staked_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a staked balance symbol of EOS");
assert(b.unstaking_balance.amount == 14, "account_balance_get should have set a unstaking balance of 14");
assert(b.unstaking_balance.symbol == EOS_SYMBOL, "account_balance_get should have a set a unstaking balance symbol of EOS");
assert(b.last_unstaking_time == 55, "account_balance_get should have set a last unstaking time of 55");
return 0;
}
/*
extern "C" {
void init() {
}
void apply( unsigned long long code, unsigned long long action ) {
WASM_TEST_HANDLER(test_account, test_balance_acc1);
}
}
*/
/**
* @file
* @copyright defined in eos/LICENSE.txt
* @file action_test.cpp
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/action.hpp>
#include <eoslib/eos.hpp>
#include "test_api.hpp"
void test_action::read_action_normal() {
......@@ -12,7 +12,6 @@ void test_action::read_action_normal() {
uint32_t total = 0;
assert( current_receiver() == N(testapi), "current_receiver() == N(testapi)" );
assert(action_size() == sizeof(dummy_action), "action_size() == sizeof(dummy_action)");
total = read_action(buffer, 30);
......@@ -35,30 +34,36 @@ void test_action::read_action_normal() {
}
void test_action::read_action_to_0() {
uint32_t total = read_action((void *)0, 0x7FFFFFFF);
prints("made it here\n");
uint32_t total = read_action((void *)0, 0x7FFFFFFF); //0x7FFFFFFF);
prints("made it out\n");
// assert(false, "WHY YOU NO FAIL!");
}
void test_action::read_action_to_64k() {
uint32_t total = read_action( (void *)((1<<16)-1), 0x7FFFFFFF);
}
//unsigned int test_action::require_notice() {
// if( current_receiver() == N(testapi) ) {
// eosio::require_recipient( N(acc1) );
// eosio::require_recipient( N(acc2) );
// eosio::require_recipient( N(acc1), N(acc2) );
// return WASM_TEST_FAIL;
// } else if ( current_receiver() == N(acc1) || current_receiver() == N(acc2) ) {
// return WASM_TEST_PASS;
// }
// return WASM_TEST_FAIL;
//}
//
//unsigned int test_action::require_auth() {
// eosio::require_auth( N(acc3) );
// eosio::require_auth( N(acc4) );
// return WASM_TEST_PASS;
//}
unsigned int test_action::require_notice() {
if( current_receiver() == N(testapi) ) {
eosio::require_recipient( N(acc1) );
eosio::require_recipient( N(acc2) );
eosio::require_recipient( N(acc1), N(acc2) );
assert(false, "Should've failed");
return 1;
} else if ( current_receiver() == N(acc1) || current_receiver() == N(acc2) ) {
return 0;
}
assert(false, "Should've failed");
return 1;
}
unsigned int test_action::require_auth() {
prints("require_auth");
eosio::require_auth( N(acc3) );
eosio::require_auth( N(acc4) );
return 0;
}
void test_action::assert_false() {
assert(false, "test_action::assert_false");
......@@ -75,4 +80,18 @@ void test_action::assert_true() {
// WASM_ASSERT( tmp == ::now(), "tmp == now()" );
// return WASM_TEST_PASS;
//}
//
/*
extern "C" {
void init() {
}
void apply( unsigned long long code, unsigned long long action ) {
WASM_TEST_HANDLER(test_action, read_action_normal);
WASM_TEST_HANDLER(test_action, read_action_to_0);
WASM_TEST_HANDLER(test_action, require_auth);
WASM_TEST_HANDLER(test_action, assert_false);
WASM_TEST_HANDLER(test_action, assert_true);
}
}
*/
......@@ -5,18 +5,20 @@
#include <eoslib/eos.hpp>
#include "test_api.hpp"
#include "test_action.cpp"
#include "test_extended_memory.cpp"
#include "test_memory.cpp"
#include "test_print.cpp"
#include "test_types.cpp"
//#include "test_fixedpoint.cpp"
//#include "test_math.cpp"
//#include "test_account.cpp"
//#include "test_chain.cpp"
//#include "test_crypto.cpp"
//#include "test_db.cpp"
//#include "test_math.cpp"
#include "test_action.cpp"
#include "test_print.cpp"
//#include "test_string.cpp"
//#include "test_fixedpoint.cpp"
//#include "test_real.cpp"
//#include "test_transaction.cpp"
//#include "test_types.cpp"
extern "C" {
......@@ -28,18 +30,39 @@ extern "C" {
//eosio::print("==> CONTRACT: ", code, " ", action, "\n");
#if 1
//test_types
// WASM_TEST_HANDLER(test_types, types_size);
// WASM_TEST_HANDLER(test_types, char_to_symbol);
// WASM_TEST_HANDLER(test_types, string_to_name);
// WASM_TEST_HANDLER(test_types, name_class);
//
// //test_action
WASM_TEST_HANDLER(test_types, types_size);
WASM_TEST_HANDLER(test_types, char_to_symbol);
WASM_TEST_HANDLER(test_types, string_to_name);
WASM_TEST_HANDLER(test_types, name_class);
#endif
#if 1
//test_extended_memory
WASM_TEST_HANDLER(test_extended_memory, test_initial_buffer);
WASM_TEST_HANDLER(test_extended_memory, test_page_memory);
WASM_TEST_HANDLER(test_extended_memory, test_page_memory_exceeded);
WASM_TEST_HANDLER(test_extended_memory, test_page_memory_negative_bytes);
#endif
#if 1
//test_memory
WASM_TEST_HANDLER(test_memory, test_memory_allocs);
WASM_TEST_HANDLER(test_memory, test_memory_hunk);
WASM_TEST_HANDLER(test_memory, test_memory_hunks);
WASM_TEST_HANDLER(test_memory, test_memory_hunks_disjoint);
WASM_TEST_HANDLER(test_memory, test_memset_memcpy);
WASM_TEST_HANDLER(test_memory, test_memcpy_overlap_start);
WASM_TEST_HANDLER(test_memory, test_memcpy_overlap_end);
WASM_TEST_HANDLER(test_memory, test_memcmp);
#endif
//test_action
WASM_TEST_HANDLER(test_action, read_action_normal);
WASM_TEST_HANDLER(test_action, read_action_to_0);
WASM_TEST_HANDLER(test_action, read_action_to_64k);
// WASM_TEST_HANDLER(test_action, require_notice);
// WASM_TEST_HANDLER(test_action, require_auth);
WASM_TEST_HANDLER(test_action, require_notice);
WASM_TEST_HANDLER(test_action, require_auth);
WASM_TEST_HANDLER(test_action, assert_false);
WASM_TEST_HANDLER(test_action, assert_true);
// WASM_TEST_HANDLER(test_action, now);
......@@ -50,109 +73,126 @@ extern "C" {
WASM_TEST_HANDLER(test_print, test_printi128);
WASM_TEST_HANDLER(test_print, test_printn);
// //test_math
// WASM_TEST_HANDLER(test_math, test_multeq_i128);
// WASM_TEST_HANDLER(test_math, test_diveq_i128);
// WASM_TEST_HANDLER(test_math, test_diveq_i128_by_0);
// WASM_TEST_HANDLER(test_math, test_double_api);
// WASM_TEST_HANDLER(test_math, test_double_api_div_0);
//
//
// //test db
// WASM_TEST_HANDLER(test_db, key_i64_general);
// WASM_TEST_HANDLER(test_db, key_i64_remove_all);
// WASM_TEST_HANDLER(test_db, key_i64_small_load);
// WASM_TEST_HANDLER(test_db, key_i64_small_store);
// WASM_TEST_HANDLER(test_db, key_i64_store_scope);
// WASM_TEST_HANDLER(test_db, key_i64_remove_scope);
// WASM_TEST_HANDLER(test_db, key_i64_not_found);
// WASM_TEST_HANDLER(test_db, key_i64_front_back);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_general);
// WASM_TEST_HANDLER(test_db, key_i128i128_general);
// WASM_TEST_HANDLER(test_db, key_str_general);
// WASM_TEST_HANDLER(test_db, key_str_table);
// WASM_TEST_HANDLER(test_db, key_str_setup_limit);
// WASM_TEST_HANDLER(test_db, key_str_min_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_str_under_limit);
// WASM_TEST_HANDLER(test_db, key_str_available_space_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_str_another_under_limit);
// WASM_TEST_HANDLER(test_db, key_i64_setup_limit);
// WASM_TEST_HANDLER(test_db, key_i64_min_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i64_under_limit);
// WASM_TEST_HANDLER(test_db, key_i64_available_space_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i64_another_under_limit);
// WASM_TEST_HANDLER(test_db, key_i128i128_setup_limit);
// WASM_TEST_HANDLER(test_db, key_i128i128_min_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i128i128_under_limit);
// WASM_TEST_HANDLER(test_db, key_i128i128_available_space_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i128i128_another_under_limit);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_setup_limit);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_min_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_under_limit);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_available_space_exceed_limit);
// WASM_TEST_HANDLER(test_db, key_i64i64i64_another_under_limit);
//
// //test crypto
// WASM_TEST_HANDLER(test_crypto, test_sha256);
// WASM_TEST_HANDLER(test_crypto, sha256_no_data);
// WASM_TEST_HANDLER(test_crypto, asert_sha256_false);
// WASM_TEST_HANDLER(test_crypto, asert_sha256_true);
// WASM_TEST_HANDLER(test_crypto, asert_no_data);
//
// //test transaction
// WASM_TEST_HANDLER(test_transaction, send_message);
// WASM_TEST_HANDLER(test_transaction, send_message_empty);
// WASM_TEST_HANDLER(test_transaction, send_message_max);
// WASM_TEST_HANDLER(test_transaction, send_message_large);
// WASM_TEST_HANDLER(test_transaction, send_message_recurse);
// WASM_TEST_HANDLER(test_transaction, send_message_inline_fail);
// WASM_TEST_HANDLER(test_transaction, send_transaction);
// WASM_TEST_HANDLER(test_transaction, send_transaction_empty);
// WASM_TEST_HANDLER(test_transaction, send_transaction_max);
// WASM_TEST_HANDLER(test_transaction, send_transaction_large);
//
// //test chain
// WASM_TEST_HANDLER(test_chain, test_activeprods);
//
// // test string
// WASM_TEST_HANDLER(test_string, construct_with_size);
// WASM_TEST_HANDLER(test_string, construct_with_data);
// WASM_TEST_HANDLER(test_string, construct_with_data_copied);
// WASM_TEST_HANDLER(test_string, construct_with_data_partially);
// WASM_TEST_HANDLER(test_string, copy_constructor);
// WASM_TEST_HANDLER(test_string, assignment_operator);
// WASM_TEST_HANDLER(test_string, index_operator);
// WASM_TEST_HANDLER(test_string, index_out_of_bound);
// WASM_TEST_HANDLER(test_string, substring);
// WASM_TEST_HANDLER(test_string, substring_out_of_bound);
// WASM_TEST_HANDLER(test_string, concatenation_null_terminated);
// WASM_TEST_HANDLER(test_string, concatenation_non_null_terminated);
// WASM_TEST_HANDLER(test_string, assign);
// WASM_TEST_HANDLER(test_string, comparison_operator);
// WASM_TEST_HANDLER(test_string, print_null_terminated);
// WASM_TEST_HANDLER(test_string, print_non_null_terminated);
// WASM_TEST_HANDLER(test_string, print_unicode);
// WASM_TEST_HANDLER(test_string, valid_utf8);
// WASM_TEST_HANDLER(test_string, invalid_utf8);
// WASM_TEST_HANDLER(test_string, string_literal);
//
// // test fixed_point
// WASM_TEST_HANDLER(test_fixedpoint, create_instances);
// WASM_TEST_HANDLER(test_fixedpoint, test_addition);
// WASM_TEST_HANDLER(test_fixedpoint, test_subtraction);
// WASM_TEST_HANDLER(test_fixedpoint, test_multiplication);
// WASM_TEST_HANDLER(test_fixedpoint, test_division);
//
//
// // test double
// WASM_TEST_HANDLER(test_real, create_instances);
// WASM_TEST_HANDLER(test_real, test_addition);
// WASM_TEST_HANDLER(test_real, test_multiplication);
// WASM_TEST_HANDLER(test_real, test_division);
//
// // test account
// WASM_TEST_HANDLER(test_account, test_balance_acc1);
//
#if 0
//test_math
WASM_TEST_HANDLER(test_math, test_multeq);
WASM_TEST_HANDLER(test_math, test_diveq);
WASM_TEST_HANDLER(test_math, test_diveq_by_0);
WASM_TEST_HANDLER(test_math, test_double_api);
WASM_TEST_HANDLER(test_math, test_double_api_div_0);
#endif
#if 0
//test db
WASM_TEST_HANDLER(test_db, key_i64_general);
WASM_TEST_HANDLER(test_db, key_i64_remove_all);
WASM_TEST_HANDLER(test_db, key_i64_small_load);
WASM_TEST_HANDLER(test_db, key_i64_small_store);
WASM_TEST_HANDLER(test_db, key_i64_store_scope);
WASM_TEST_HANDLER(test_db, key_i64_remove_scope);
WASM_TEST_HANDLER(test_db, key_i64_not_found);
WASM_TEST_HANDLER(test_db, key_i64_front_back);
WASM_TEST_HANDLER(test_db, key_i64i64i64_general);
WASM_TEST_HANDLER(test_db, key_i128i128_general);
WASM_TEST_HANDLER(test_db, key_str_general);
WASM_TEST_HANDLER(test_db, key_str_table);
WASM_TEST_HANDLER(test_db, key_str_setup_limit);
WASM_TEST_HANDLER(test_db, key_str_min_exceed_limit);
WASM_TEST_HANDLER(test_db, key_str_under_limit);
WASM_TEST_HANDLER(test_db, key_str_available_space_exceed_limit);
WASM_TEST_HANDLER(test_db, key_str_another_under_limit);
WASM_TEST_HANDLER(test_db, key_i64_setup_limit);
WASM_TEST_HANDLER(test_db, key_i64_min_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i64_under_limit);
WASM_TEST_HANDLER(test_db, key_i64_available_space_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i64_another_under_limit);
WASM_TEST_HANDLER(test_db, key_i128i128_setup_limit);
WASM_TEST_HANDLER(test_db, key_i128i128_min_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i128i128_under_limit);
WASM_TEST_HANDLER(test_db, key_i128i128_available_space_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i128i128_another_under_limit);
WASM_TEST_HANDLER(test_db, key_i64i64i64_setup_limit);
WASM_TEST_HANDLER(test_db, key_i64i64i64_min_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i64i64i64_under_limit);
WASM_TEST_HANDLER(test_db, key_i64i64i64_available_space_exceed_limit);
WASM_TEST_HANDLER(test_db, key_i64i64i64_another_under_limit);
#endif
#if 0
//test crypto
WASM_TEST_HANDLER(test_crypto, test_sha256);
WASM_TEST_HANDLER(test_crypto, sha256_no_data);
WASM_TEST_HANDLER(test_crypto, asert_sha256_false);
WASM_TEST_HANDLER(test_crypto, asert_sha256_true);
WASM_TEST_HANDLER(test_crypto, asert_no_data);
#endif
#if 0
//test transaction
WASM_TEST_HANDLER(test_transaction, send_message);
WASM_TEST_HANDLER(test_transaction, send_message_empty);
WASM_TEST_HANDLER(test_transaction, send_message_max);
WASM_TEST_HANDLER(test_transaction, send_message_large);
WASM_TEST_HANDLER(test_transaction, send_message_recurse);
WASM_TEST_HANDLER(test_transaction, send_message_inline_fail);
WASM_TEST_HANDLER(test_transaction, send_transaction);
WASM_TEST_HANDLER(test_transaction, send_transaction_empty);
WASM_TEST_HANDLER(test_transaction, send_transaction_max);
WASM_TEST_HANDLER(test_transaction, send_transaction_large);
#endif
#if 0
//test chain
WASM_TEST_HANDLER(test_chain, test_activeprods);
#endif
#if 0
// test string
WASM_TEST_HANDLER(test_string, construct_with_size);
WASM_TEST_HANDLER(test_string, construct_with_data);
WASM_TEST_HANDLER(test_string, construct_with_data_copied);
WASM_TEST_HANDLER(test_string, construct_with_data_partially);
WASM_TEST_HANDLER(test_string, copy_constructor);
WASM_TEST_HANDLER(test_string, assignment_operator);
WASM_TEST_HANDLER(test_string, index_operator);
WASM_TEST_HANDLER(test_string, index_out_of_bound);
WASM_TEST_HANDLER(test_string, substring);
WASM_TEST_HANDLER(test_string, substring_out_of_bound);
WASM_TEST_HANDLER(test_string, concatenation_null_terminated);
WASM_TEST_HANDLER(test_string, concatenation_non_null_terminated);
WASM_TEST_HANDLER(test_string, assign);
WASM_TEST_HANDLER(test_string, comparison_operator);
WASM_TEST_HANDLER(test_string, print_null_terminated);
WASM_TEST_HANDLER(test_string, print_non_null_terminated);
WASM_TEST_HANDLER(test_string, print_unicode);
WASM_TEST_HANDLER(test_string, valid_utf8);
WASM_TEST_HANDLER(test_string, invalid_utf8);
WASM_TEST_HANDLER(test_string, string_literal);
#endif
#if 0
// test fixed_point
WASM_TEST_HANDLER(test_fixedpoint, create_instances);
WASM_TEST_HANDLER(test_fixedpoint, test_addition);
WASM_TEST_HANDLER(test_fixedpoint, test_subtraction);
WASM_TEST_HANDLER(test_fixedpoint, test_multiplication);
WASM_TEST_HANDLER(test_fixedpoint, test_division);
#endif
#if 0
// test double
WASM_TEST_HANDLER(test_real, create_instances);
WASM_TEST_HANDLER(test_real, test_addition);
WASM_TEST_HANDLER(test_real, test_multiplication);
WASM_TEST_HANDLER(test_real, test_division);
#endif
#if 0
// test account
WASM_TEST_HANDLER(test_account, test_balance_acc1);
#endif
//unhandled test call
assert(false, "Unknown Test");
}
......
......@@ -24,7 +24,7 @@ static constexpr u64 WASM_TEST_ACTION(const char* cls, const char* method)
CLASS::METHOD(); \
return; \
}
#pragma pack(push, 1)
struct dummy_action {
char a; //1
......@@ -72,9 +72,9 @@ struct test_action {
};
struct test_math {
static unsigned int test_multeq_i128();
static unsigned int test_diveq_i128();
static unsigned int test_diveq_i128_by_0();
static unsigned int test_multeq();
static unsigned int test_diveq();
static unsigned int test_diveq_by_0();
static unsigned int test_double_api();
static unsigned int test_double_api_div_0();
};
......@@ -186,3 +186,21 @@ struct test_real {
struct test_account {
static unsigned int test_balance_acc1();
};
struct test_extended_memory {
static void test_initial_buffer();
static void test_page_memory();
static void test_page_memory_exceeded();
static void test_page_memory_negative_bytes();
};
struct test_memory {
static void test_memory_allocs();
static void test_memory_hunk();
static void test_memory_hunks();
static void test_memory_hunks_disjoint();
static void test_memset_memcpy();
static void test_memcpy_overlap_start();
static void test_memcpy_overlap_end();
static void test_memcmp();
};
......@@ -18,14 +18,14 @@ unsigned int test_chain::test_activeprods() {
producers msg_prods;
read_action(&msg_prods, sizeof(producers));
WASM_ASSERT(msg_prods.len == 21, "producers.len != 21");
assert(msg_prods.len == 21, "producers.len != 21");
producers api_prods;
get_active_producers(api_prods.producers, sizeof(account_name)*21);
for( int i = 0; i < 21 ; ++i ) {
WASM_ASSERT(api_prods.producers[i] == msg_prods.producers[i], "Active producer");
assert(api_prods.producers[i] == msg_prods.producers[i], "Active producer");
}
return WASM_TEST_PASS;
return 0;
}
......@@ -6,6 +6,7 @@
#include <eoslib/crypto.h>
#include "test_api.hpp"
#define WASM_TEST_FAIL 1
static const char test1[] = "abc";
static const unsigned char test1_ok[] = {
......@@ -73,18 +74,18 @@ unsigned int test_crypto::test_sha256() {
checksum tmp;
sha256( (char *)test1, my_strlen(test1), &tmp );
WASM_ASSERT( my_memcmp((void *)test1_ok, &tmp, sizeof(checksum)), "sha256 test1" );
assert( my_memcmp((void *)test1_ok, &tmp, sizeof(checksum)), "sha256 test1" );
sha256( (char *)test3, my_strlen(test3), &tmp );
WASM_ASSERT( my_memcmp((void *)test3_ok, &tmp, sizeof(checksum)), "sha256 test3" );
assert( my_memcmp((void *)test3_ok, &tmp, sizeof(checksum)), "sha256 test3" );
sha256( (char *)test4, my_strlen(test4), &tmp );
WASM_ASSERT( my_memcmp((void *)test4_ok, &tmp, sizeof(checksum)), "sha256 test4" );
assert( my_memcmp((void *)test4_ok, &tmp, sizeof(checksum)), "sha256 test4" );
sha256( (char *)test5, my_strlen(test5), &tmp );
WASM_ASSERT( my_memcmp((void *)test5_ok, &tmp, sizeof(checksum)), "sha256 test5" );
assert( my_memcmp((void *)test5_ok, &tmp, sizeof(checksum)), "sha256 test5" );
return WASM_TEST_PASS;
return 0;
}
unsigned int test_crypto::sha256_no_data() {
......@@ -92,9 +93,9 @@ unsigned int test_crypto::sha256_no_data() {
checksum tmp;
sha256( (char *)test2, my_strlen(test2), &tmp );
WASM_ASSERT( my_memcmp((void *)test2_ok, &tmp, sizeof(checksum)), "sha256 test2" );
assert( my_memcmp((void *)test2_ok, &tmp, sizeof(checksum)), "sha256 test2" );
return WASM_TEST_PASS;
return 0;
}
unsigned int test_crypto::asert_sha256_false() {
......@@ -104,7 +105,8 @@ unsigned int test_crypto::asert_sha256_false() {
sha256( (char *)test1, my_strlen(test1), &tmp );
tmp.hash[0] ^= (uint64_t)(-1);
assert_sha256( (char *)test1, my_strlen(test1), &tmp);
assert(false, "sha256 failed");
return WASM_TEST_FAIL;
}
......@@ -124,13 +126,13 @@ unsigned int test_crypto::asert_sha256_true() {
sha256( (char *)test5, my_strlen(test5), &tmp );
assert_sha256( (char *)test5, my_strlen(test5), &tmp);
return WASM_TEST_PASS;
return 0;
}
unsigned int test_crypto::asert_no_data() {
checksum *tmp = (checksum*)test2_ok;
assert_sha256( (char *)test2, my_strlen(test2), tmp);
assert(false, "Has no data");
return WASM_TEST_FAIL;
}
\ No newline at end of file
}
此差异已折叠。
#include <eoslib/eos.hpp>
#include "test_api.hpp"
#include <eoslib/memory.hpp>
using namespace eosio;
void verify( const void* const ptr, const uint32_t val, const uint32_t size) {
const char* char_ptr = (const char*)ptr;
for (uint32_t i = 0; i < size; ++i)
assert(static_cast<uint32_t>(static_cast<unsigned char>(char_ptr[i])) == val, "buffer slot doesn't match");
}
#define PRINT_PTR(x) prints("PTR : "); print((uint32_t)x, 4); prints("\n");
void test_extended_memory::test_page_memory() {
constexpr uint32_t _64K = 64*1024;
/*
* Test test_extended_memory::test_page_memory `ensure initial page size`
* Given I have not tried to increase the "program break" yet,
* when I call sbrk(0), then I should get the end of the first page, which should be 64K.
*/
auto prev = sbrk(0);
assert(reinterpret_cast<uint32_t>(prev) == _64K, "Should initially have 1 64K page allocated");
/*
* Test test_extended_memory::test_page_memory `ensure sbrk returns previous end of program break`
* Given I have not tried to increase memory,
* when I call sbrk(1), then I should get the end of the first page, which should be 64K.
*/
prev = sbrk(1);
assert(reinterpret_cast<uint32_t>(prev) == _64K, "Should still be pointing to the end of the 1st 64K page");
/*
* Test test_extended_memory::test_page_memory `ensure sbrk aligns allocations`
* Given that I allocated 1 byte via sbrk,
* when I call sbrk(2), then I should get 8 bytes past the previous end because of maintaining 8 byte alignment.
*/
prev = sbrk(2);
assert(reinterpret_cast<uint32_t>(prev) == _64K+8, "Should point to 8 past the end of 1st 64K page");
/*
* Test test_extended_memory::test_page_memory `ensure sbrk aligns allocations 2`
* Given that I allocated 2 bytes via sbrk,
* when I call sbrk(_64K-17), then I should get 8 bytes past the previous end because of maintaining 8 byte alignment.
*/
prev = sbrk(_64K - 17);
assert(reinterpret_cast<uint32_t>(prev) == _64K+16, "Should point to 16 past the end of the 1st 64K page");
prev = sbrk(1);
assert(reinterpret_cast<uint32_t>(prev) == 2*_64K, "Should point to the end of the 2nd 64K page");
prev = sbrk(_64K);
assert(reinterpret_cast<uint32_t>(prev) == 2*_64K+8, "Should point to 8 past the end of the 2nd 64K page");
prev = sbrk(_64K - 15);
assert(reinterpret_cast<uint32_t>(prev) == 3*_64K+8, "Should point to 8 past the end of the 3rd 64K page");
prev = sbrk(2*_64K-1);
assert(reinterpret_cast<uint32_t>(prev) == 4*_64K, "Should point to the end of the 4th 64K page");
prev = sbrk(2*_64K);
assert(reinterpret_cast<uint32_t>(prev) == 6*_64K, "Should point to the end of the 6th 64K page");
prev = sbrk(2*_64K+1);
assert(reinterpret_cast<uint32_t>(prev) == 8*_64K, "Should point to the end of the 8th 64K page");
prev = sbrk(6*_64K-15);
assert(reinterpret_cast<uint32_t>(prev) == 10*_64K+8, "Should point to 8 past the end of the 10th 64K page");
prev = sbrk(0);
assert(reinterpret_cast<uint32_t>(prev) == 16*_64K, "Should point to 8 past the end of the 16th 64K page");
}
void test_extended_memory::test_page_memory_exceeded() {
/*
* Test test_extended_memory::test_page_memory_exceeded `ensure sbrk won't allocation more than 1M of memory`
* Given that I have not tried to increase allocated memory,
* when I increase allocated memory with sbrk(15*64K), then I should get the end of the first page.
*/
auto prev = sbrk(15*64*1024);
assert(reinterpret_cast<uint32_t>(prev) == 64*1024, "Should have allocated 1M of memory");
/*
* Test test_extended_memory::test_page_memory_exceeded `ensure sbrk won't allocation more than 1M of memory 2`
*/
prev = sbrk(0);
assert(reinterpret_cast<uint32_t>(prev) == (1024*1024), "Should have allocated 1M of memory");
sbrk(1);
assert(0, "Should have thrown exception for trying to allocate too much memory");
}
void test_extended_memory::test_page_memory_negative_bytes() {
sbrk(-1);
assert(0, "Should have thrown exception for trying to remove memory");
}
void test_extended_memory::test_initial_buffer() {
// initial buffer should be exhausted at 8192 bytes
// 8176 left ( 12 + ptr header )
char* ptr1 = (char*)eosio::malloc(12);
assert(ptr1 != nullptr, "should have allocated 12 char buffer");
char* ptr2 = (char*)eosio::malloc(8159);
assert(ptr2 != nullptr, "should have allocate 8159 char buffer");
// should overrun initial heap, allocated in 2nd heap
char* ptr3 = (char*)eosio::malloc(20);
assert(ptr3 != nullptr, "should have allocated a 20 char buffer");
verify(ptr3, 0, 20);
}
......@@ -10,8 +10,8 @@ unsigned int test_fixedpoint::create_instances()
fixed_point128<18> a(12345667);
fixed_point128<18> b(12345667);
fixed_point128<16> c(12345667);
WASM_ASSERT(b == a, "fixed_point128 instances comparison with same number of decimals");
WASM_ASSERT(c == a, "fixed_point128 instances with different number of decimals");
assert(b == a, "fixed_point128 instances comparison with same number of decimals");
assert(c == a, "fixed_point128 instances with different number of decimals");
}
{
......@@ -19,8 +19,8 @@ unsigned int test_fixedpoint::create_instances()
fixed_point64<5> a(12345667);
fixed_point64<5> b(12345667);
fixed_point64<5> c(12345667);
WASM_ASSERT(b == a, "fixed_point64 instances comparison with same number of decimals");
WASM_ASSERT(c == a, "fixed_point64 instances with different number of decimals");
assert(b == a, "fixed_point64 instances comparison with same number of decimals");
assert(c == a, "fixed_point64 instances with different number of decimals");
}
{
......@@ -28,12 +28,12 @@ unsigned int test_fixedpoint::create_instances()
fixed_point32<18> a(12345667);
fixed_point32<18> b(12345667);
fixed_point32<16> c(12345667);
WASM_ASSERT(b == a, "fixed_point32 instances comparison with same number of decimals");
WASM_ASSERT(c == a, "fixed_point32 instances with different number of decimals");
assert(b == a, "fixed_point32 instances comparison with same number of decimals");
assert(c == a, "fixed_point32 instances with different number of decimals");
}
return WASM_TEST_PASS;
return 0;
}
unsigned int test_fixedpoint::test_addition()
......@@ -44,7 +44,7 @@ unsigned int test_fixedpoint::test_addition()
fixed_point32<0> b(100);
fixed_point32<0> c = a + b;
fixed_point32<0> d = 200;
WASM_ASSERT(c == d, "fixed_point32 instances addition with zero decmimals");
assert(c == d, "fixed_point32 instances addition with zero decmimals");
}
{
// Various ways to create fixed_point64
......@@ -52,10 +52,10 @@ unsigned int test_fixedpoint::test_addition()
fixed_point64<0> b(100);
fixed_point64<0> c = a + b;
fixed_point64<0> d = 200;
WASM_ASSERT(c == d, "fixed_point64 instances addition with zero decmimals");
assert(c == d, "fixed_point64 instances addition with zero decmimals");
}
return WASM_TEST_PASS;
return 0;
};
unsigned int test_fixedpoint::test_subtraction()
......@@ -66,7 +66,7 @@ unsigned int test_fixedpoint::test_subtraction()
fixed_point64<0> b(100);
fixed_point64<0> c = a - b;
fixed_point64<0> d = 0;
WASM_ASSERT(c == d, "fixed_point64 instances subtraction with zero decmimals");
assert(c == d, "fixed_point64 instances subtraction with zero decmimals");
}
{
// Various ways to create fixed_point32
......@@ -74,10 +74,10 @@ unsigned int test_fixedpoint::test_subtraction()
fixed_point32<0> b(100);
fixed_point32<0> c = a - b;
fixed_point32<0> d = 0;
WASM_ASSERT(c == d, "fixed_point32 instances subtraction with zero decmimals");
assert(c == d, "fixed_point32 instances subtraction with zero decmimals");
}
return WASM_TEST_PASS;
return 0;
};
unsigned int test_fixedpoint::test_multiplication()
......@@ -88,7 +88,7 @@ unsigned int test_fixedpoint::test_multiplication()
fixed_point64<0> b(200);
fixed_point128<0> c = a * b;
fixed_point128<0> d(200*100);
WASM_ASSERT(c == d, "fixed_point64 instances multiplication result in fixed_point128");
assert(c == d, "fixed_point64 instances multiplication result in fixed_point128");
}
{
......@@ -97,9 +97,9 @@ unsigned int test_fixedpoint::test_multiplication()
fixed_point32<0> b(200);
fixed_point64<0> c = a * b;
fixed_point64<0> d(200*100);
WASM_ASSERT(c == d, "fixed_point32 instances multiplication result in fixed_point64");
assert(c == d, "fixed_point32 instances multiplication result in fixed_point64");
}
return WASM_TEST_PASS;
return 0;
}
......@@ -114,7 +114,7 @@ unsigned int test_fixedpoint::test_division()
fixed_point128<5> c = a / b;
fixed_point128<5> e = fixed_divide<5>(lhs, rhs);
WASM_ASSERT(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128");
assert(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128");
}
......@@ -127,10 +127,10 @@ unsigned int test_fixedpoint::test_division()
fixed_point64<5> c = a / b;
fixed_point64<5> e = fixed_divide<5>(lhs, rhs);
WASM_ASSERT(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128");
assert(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128");
}
return WASM_TEST_PASS;
return 0;
}
......
#include <eoslib/types.hpp>
#include <eoslib/action.hpp>
#include <eoslib/math.hpp>
#include <eoslib/eos.hpp>
#include "test_api.hpp"
unsigned int test_math::test_multeq_i128() {
using namespace eosio;
unsigned int test_math::test_multeq() {
u128_msg msg;
auto n = read_action(&msg, sizeof(u128_msg));
WASM_ASSERT( n == sizeof(u128_msg), "test_multeq_i128 n == sizeof(u128_msg)" );
multeq_i128(msg.values, msg.values+1);
WASM_ASSERT( msg.values[0] == msg.values[2], "test_multeq_i128 msg.values[0] == msg.values[2]" );
return WASM_TEST_PASS;
assert( n == sizeof(u128_msg), "test_multeq n == sizeof(u128_msg)" );
uint128_t self = *(msg.values);
uint128_t other = *(msg.values+1);
eosio::multeq(self, other);
assert( self == msg.values[2], "test_multeq msg.values[0] == msg.values[2]" );
return 0;
}
unsigned int test_math::test_diveq_i128() {
unsigned int test_math::test_diveq() {
u128_msg msg;
auto n = read_action(&msg, sizeof(u128_msg));
WASM_ASSERT( n == sizeof(u128_msg), "test_diveq_i128 n == sizeof(u128_msg)" );
diveq_i128(msg.values, msg.values+1);
WASM_ASSERT( msg.values[0] == msg.values[2], "test_diveq_i128 msg.values[0] == msg.values[2]" );
return WASM_TEST_PASS;
assert( n == sizeof(u128_msg), "test_diveq n == sizeof(u128_msg)" );
uint128_t self = *(msg.values);
uint128_t other = *(msg.values+1);
eosio::diveq(self, other);
assert( msg.values[0] == msg.values[2], "test_diveq msg.values[0] == msg.values[2]" );
return 0;
}
unsigned int test_math::test_diveq_i128_by_0() {
unsigned int test_math::test_diveq_by_0() {
unsigned __int128 a = 100;
unsigned __int128 b = 0;
diveq_i128(&a, &b);
return WASM_TEST_PASS;
eosio::diveq(a, b);
return 0;
}
unsigned int test_math::test_double_api() {
uint64_t res = double_mult(
......@@ -36,30 +43,30 @@ unsigned int test_math::test_double_api() {
double_add( i64_to_double(3), i64_to_double(2) )
);
WASM_ASSERT( double_to_i64(res) == 1, "double funcs");
assert( double_to_i64(res) == 1, "double funcs");
res = double_eq(
double_div( i64_to_double(5), i64_to_double(9) ),
double_div( i64_to_double(5), i64_to_double(9) )
);
WASM_ASSERT(res == 1, "double_eq");
assert(res == 1, "double_eq");
res = double_gt(
double_div( i64_to_double(9999999), i64_to_double(7777777) ),
double_div( i64_to_double(9999998), i64_to_double(7777777) )
);
WASM_ASSERT(res == 1, "double_gt");
assert(res == 1, "double_gt");
res = double_lt(
double_div( i64_to_double(9999998), i64_to_double(7777777) ),
double_div( i64_to_double(9999999), i64_to_double(7777777) )
);
WASM_ASSERT(res == 1, "double_lt");
assert(res == 1, "double_lt");
return WASM_TEST_PASS;
return 0;
}
unsigned int test_math::test_double_api_div_0() {
......@@ -70,5 +77,5 @@ unsigned int test_math::test_double_api_div_0() {
)
);
return WASM_TEST_PASS;
return 0;
}
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/message.h>
//#include <eoslib/types.hpp>
#include <eoslib/memory.hpp>
using namespace eosio;
void verify_mem(const void* const ptr, const uint32_t val, const uint32_t size)
{
const char* char_ptr = (const char*)ptr;
for (uint32_t i = 0; i < size; ++i)
{
assert(static_cast<uint32_t>(static_cast<unsigned char>(char_ptr[i])) == val, "buf slot doesn't match");
}
}
/*
void print(const void* const ptr, const uint32_t size)
{
const char* char_ptr = (const char*)ptr;
eosio::print("\n{ ");
for (uint32_t i = 0; i < size; ++i)
{
const char* delim = (i % 8 == 7) ? ", " : " ";
eosio::print("", static_cast<uint32_t>(static_cast<unsigned char>(char_ptr[i])), delim);
}
eosio::print("}\n");
}
*/
/*
* malloc and realloc always allocate on 8 byte boundaries based off of total allocation, so
* if the requested size + the 2 byte header is not divisible by 8, then the allocated space
* will be larger than the requested size
*/
void test_memory::test_memory_allocs()
{
char* ptr1 = (char*)eosio::malloc(0);
assert(ptr1 == nullptr, "should not have allocated a 0 char buf");
// 20 chars - 20 + 4(header) which is divisible by 8
ptr1 = (char*)eosio::malloc(20);
assert(ptr1 != nullptr, "should have allocated a 20 char buf");
verify_mem(ptr1, 0, 20);
// existing memory layout -> |24|
// 36 chars allocated - 30 + 4 plus an extra 6 to be divisible by 8
char* ptr1_realloc = (char*)eosio::realloc(ptr1, 30);
assert(ptr1_realloc != nullptr, "should have returned a 30 char buf");
assert(ptr1_realloc == ptr1, "should have enlarged the 20 char buf");
// existing memory layout -> |40|
// 20 chars allocated
char* ptr2 = (char*)eosio::malloc(20);
assert(ptr2 != nullptr, "should have allocated another 20 char buf");
assert(ptr1 + 36 < ptr2, "20 char buf should have been created after ptr1"); // test specific to implementation (can remove for refactor)
verify_mem(ptr1, 0, 36);
assert(ptr1[36] != 0, "should not have empty bytes following since block allocated"); // test specific to implementation (can remove for refactor)
// existing memory layout -> |40|24|
//shrink the buffer
ptr1[14] = 0x7e;
// 20 chars allocated (still)
ptr1_realloc = (char*)eosio::realloc(ptr1, 15);
assert(ptr1_realloc != nullptr, "should have returned a 15 char buf");
assert(ptr1_realloc == ptr1, "should have shrunk the reallocated 30 char buf");
verify_mem(ptr1, 0, 14); // test specific to implementation (can remove for refactor)
assert(ptr1[14] == 0x7e, "remaining 15 chars of buf should be untouched");
// existing memory layout -> |24(shrunk)|16(freed)|24|
//same size the buffer (verify corner case)
// 20 chars allocated (still)
ptr1_realloc = (char*)eosio::realloc(ptr1, 15);
assert(ptr1_realloc != nullptr, "should have returned a reallocated 15 char buf");
assert(ptr1_realloc == ptr1, "should have reallocated 15 char buf as the same buf");
assert(ptr1[14] == 0x7e, "remaining 15 chars of buf should be untouched for unchanged buf");
//same size as max allocated buffer -- test specific to implementation (can remove for refactor)
ptr1_realloc = (char*)eosio::realloc(ptr1, 30);
assert(ptr1_realloc != nullptr, "should have returned a 30 char buf");
assert(ptr1_realloc == ptr1, "should have increased the buf back to orig max"); //test specific to implementation (can remove for refactor)
assert(ptr1[14] == 0x7e, "remaining 15 chars of buf should be untouched for expanded buf");
//increase buffer beyond (indicated) allocated space
// 36 chars allocated (still)
ptr1_realloc = (char*)eosio::realloc(ptr1, 36);
assert(ptr1_realloc != nullptr, "should have returned a 36 char buf");
assert(ptr1_realloc == ptr1, "should have increased char buf to actual size"); // test specific to implementation (can remove for refactor)
//increase buffer beyond allocated space
ptr1[35] = 0x7f;
// 44 chars allocated - 37 + 4 plus an extra 7 to be divisible by 8
ptr1_realloc = (char*)eosio::realloc(ptr1, 37);
assert(ptr1_realloc != nullptr, "should have returned a 37 char buf");
assert(ptr1_realloc != ptr1, "should have had to create new 37 char buf from 36 char buf");
assert(ptr2 < ptr1_realloc, "should have been created after ptr2"); // test specific to implementation (can remove for refactor)
assert(ptr1_realloc[14] == 0x7e, "orig 36 char buf's content should be copied");
assert(ptr1_realloc[35] == 0x7f, "orig 36 char buf's content should be copied");
//realloc with nullptr
char* nullptr_realloc = (char*)eosio::realloc(nullptr, 50);
assert(nullptr_realloc != nullptr, "should have returned a 50 char buf and ignored nullptr");
assert(ptr1_realloc < nullptr_realloc, "should have created after ptr1_realloc"); // test specific to implementation (can remove for refactor)
//realloc with invalid ptr
char* invalid_ptr_realloc = (char*)eosio::realloc(nullptr_realloc + 4, 10);
assert(invalid_ptr_realloc != nullptr, "should have returned a 10 char buf and ignored invalid ptr");
assert(nullptr_realloc < invalid_ptr_realloc, "should have created invalid_ptr_realloc after nullptr_realloc"); // test specific to implementation (can remove for refactor)
}
// this test verifies that malloc can allocate 15 64K pages and treat them as one big heap space (if sbrk is not called in the mean time)
void test_memory::test_memory_hunk()
{
// try to allocate the largest buffer we can, which is 15 contiguous 64K pages (with the 4 char space for the ptr header)
char* ptr1 = (char*)eosio::malloc(15 * 64 * 1024 - 4);
assert(ptr1 != nullptr, "should have allocated a ~983K char buf");
}
void test_memory::test_memory_hunks()
{
// leave 784 bytes of initial buffer to allocate later (rounds up to nearest 8 byte boundary,
// 16 bytes bigger than remainder left below in 15 64K page heap))
char* ptr1 = (char*)eosio::malloc(7404);
assert(ptr1 != nullptr, "should have allocated a 7404 char buf");
char* last_ptr = nullptr;
// 96 * (10 * 1024 - 15) => 15 ~64K pages with 768 byte buffer left to allocate
for (int i = 0; i < 96; ++i)
{
char* ptr2 = (char*)eosio::malloc(10 * 1024 - 15);
assert(ptr2 != nullptr, "should have allocated a ~10K char buf");
if (last_ptr != nullptr)
{
// - 15 rounds to -8
assert(last_ptr + 10 * 1024 - 8 == ptr2, "should allocate the very next ptr"); // test specific to implementation (can remove for refactor)
}
last_ptr = ptr2;
}
// try to allocate a buffer slightly larger than the remaining buffer| 765 + 4 rounds to 776
char* ptr3 = (char*)eosio::malloc(765);
assert(ptr3 != nullptr, "should have allocated a 772 char buf");
assert(ptr1 + 7408 == ptr3, "should allocate the very next ptr after ptr1 in initial heap"); // test specific to implementation (can remove for refactor)
// use all but 8 chars
char* ptr4 = (char*)eosio::malloc(764);
assert(ptr4 != nullptr, "should have allocated a 764 char buf");
assert(last_ptr + 10 * 1024 - 8 == ptr4, "should allocate the very next ptr after last_ptr at end of contiguous heap"); // test specific to implementation (can remove for refactor)
// use up remaining 8 chars
char* ptr5 = (char*)eosio::malloc(4);
assert(ptr5 != nullptr, "should have allocated a 4 char buf");
assert(ptr3 + 776 == ptr5, "should allocate the very next ptr after ptr3 in initial heap"); // test specific to implementation (can remove for refactor)
// nothing left to allocate
char* ptr6 = (char*)eosio::malloc(4);
assert(ptr6 == nullptr, "should not have allocated a char buf");
}
void test_memory::test_memory_hunks_disjoint()
{
// leave 8 bytes of initial buffer to allocate later
char* ptr1 = (char*)eosio::malloc(8 * 1024 - 12);
assert(ptr1 != nullptr, "should have allocated a 8184 char buf");
// can only make 14 extra (64K) heaps for malloc, since calls to sbrk will eat up part
char* loop_ptr1[14];
// 14 * (64 * 1024 - 28) => 14 ~64K pages with each page having 24 bytes left to allocate
for (int i = 0; i < 14; ++i)
{
// allocates a new heap for each request, since sbrk call doesn't allow contiguous heaps to grow
loop_ptr1[i] = (char*)eosio::malloc(64 * 1024 - 28);
assert(loop_ptr1[i] != nullptr, "should have allocated a 64K char buf");
assert(sbrk(4) != nullptr, "should be able to allocate 8 bytes");
}
// the 15th extra heap is reduced in size because of the 14 * 8 bytes allocated by sbrk calls
// will leave 8 bytes to allocate later (verifying that we circle back in the list
char* ptr2 = (char*)eosio::malloc(65412);
assert(ptr2 != nullptr, "should have allocated a 65412 char buf");
char* loop_ptr2[14];
for (int i = 0; i < 14; ++i)
{
// 12 char buffer to leave 8 bytes for another pass
loop_ptr2[i] = (char*)eosio::malloc(12);
assert(loop_ptr2[i] != nullptr, "should have allocated a 12 char buf");
assert(loop_ptr1[i] + 64 * 1024 - 24 == loop_ptr2[i], "loop_ptr2[i] should be very next pointer after loop_ptr1[i]");
}
// this shows that searching for free ptrs starts at the last loop to find free memory, not at the begining
char* ptr3 = (char*)eosio::malloc(4);
assert(ptr3 != nullptr, "should have allocated a 4 char buf");
assert(loop_ptr2[13] + 16 == ptr3, "should allocate the very next ptr after loop_ptr2[13]"); // test specific to implementation (can remove for refactor)
char* ptr4 = (char*)eosio::malloc(4);
assert(ptr4 != nullptr, "should have allocated a 4 char buf");
assert(ptr2 + 65416 == ptr4, "should allocate the very next ptr after ptr2 in last heap"); // test specific to implementation (can remove for refactor)
char* ptr5 = (char*)eosio::malloc(4);
assert(ptr5 != nullptr, "should have allocated a 4 char buf");
assert(ptr1 + 8184 == ptr5, "should allocate the very next ptr after ptr1 in last heap"); // test specific to implementation (can remove for refactor)
// will eat up remaining memory (14th heap already used up)
char* loop_ptr3[13];
for (int i = 0; i < 13; ++i)
{
// 4 char buffer to use up buffer
loop_ptr3[i] = (char*)eosio::malloc(4);
assert(loop_ptr3[i] != nullptr, "should have allocated a 4 char buf");
assert(loop_ptr2[i] + 16 == loop_ptr3[i], "loop_ptr3[i] should be very next pointer after loop_ptr2[i]");
}
char* ptr6 = (char*)eosio::malloc(4);
assert(ptr6 == nullptr, "should not have allocated a char buf");
eosio::free(loop_ptr1[3]);
eosio::free(loop_ptr2[3]);
eosio::free(loop_ptr3[3]);
char* slot3_ptr[64];
for (int i = 0; i < 64; ++i)
{
slot3_ptr[i] = (char*)eosio::malloc(1020);
assert(slot3_ptr[i] != nullptr, "should have allocated a 1020 char buf");
if (i == 0)
assert(loop_ptr1[3] == slot3_ptr[0], "loop_ptr1[3] should be very next pointer after slot3_ptr[0]");
else
assert(slot3_ptr[i - 1] + 1024 == slot3_ptr[i], "slot3_ptr[i] should be very next pointer after slot3_ptr[i-1]");
}
char* ptr7 = (char*)eosio::malloc(4);
assert(ptr7 == nullptr, "should not have allocated a char buf");
}
void test_memory::test_memset_memcpy()
{
char buf1[40] = {};
char buf2[40] = {};
verify_mem(buf1, 0, 40);
verify_mem(buf2, 0, 40);
memset(buf1, 0x22, 20);
verify_mem(buf1, 0x22, 20);
verify_mem(&buf1[20], 0, 20);
memset(&buf2[20], 0xff, 20);
verify_mem(buf2, 0, 20);
verify_mem(&buf2[20], 0xff, 20);
memcpy(&buf1[10], &buf2[10], 20);
verify_mem(buf1, 0x22, 10);
verify_mem(&buf1[10], 0, 10);
verify_mem(&buf1[20], 0xff, 10);
verify_mem(&buf1[30], 0, 10);
memset(&buf1[1], 1, 1);
verify_mem(buf1, 0x22, 1);
verify_mem(&buf1[1], 1, 1);
verify_mem(&buf1[2], 0x22, 8);
// verify adjacent non-overlapping buffers
char buf3[50] = {};
memset(&buf3[25], 0xee, 25);
verify_mem(buf3, 0, 25);
memcpy(buf3, &buf3[25], 25);
verify_mem(buf3, 0xee, 50);
memset(buf3, 0, 25);
verify_mem(&buf3[25], 0xee, 25);
memcpy(&buf3[25], buf3, 25);
verify_mem(buf3, 0, 50);
}
void test_memory::test_memcpy_overlap_start()
{
char buf3[99] = {};
memset(buf3, 0xee, 50);
memset(&buf3[50], 0xff, 49);
memcpy(&buf3[49], buf3, 50);
}
void test_memory::test_memcpy_overlap_end()
{
char buf3[99] = {};
memset(buf3, 0xee, 50);
memset(&buf3[50], 0xff, 49);
memcpy(buf3, &buf3[49], 50);
}
void test_memory::test_memcmp()
{
char buf1[] = "abcde";
char buf2[] = "abcde";
int32_t res1 = memcmp(buf1, buf2, 6);
assert(res1 == 0, "first data should be equal to second data");
char buf3[] = "abcde";
char buf4[] = "fghij";
int32_t res2 = memcmp(buf3, buf4, 6);
assert(res2 < 0, "first data should be smaller than second data");
char buf5[] = "fghij";
char buf6[] = "abcde";
int32_t res3 = memcmp(buf5, buf6, 6);
assert(res3 > 0, "first data should be larger than second data");
}
......@@ -5,8 +5,8 @@
using namespace eosio;
unsigned int test_real::create_instances() {
real lhs1(5);
WASM_ASSERT(lhs1.value() == 5, "real instance value is wrong");
return WASM_TEST_PASS;
assert(lhs1.value() == 5, "real instance value is wrong");
return 0;
}
unsigned int test_real::test_division() {
......@@ -15,8 +15,8 @@ unsigned int test_real::test_division() {
real result1 = lhs1 / rhs1;
uint64_t a = double_div(i64_to_double(5), i64_to_double(10));
WASM_ASSERT(a == result1.value(), "real division result is wrong");
return WASM_TEST_PASS;
assert(a == result1.value(), "real division result is wrong");
return 0;
}
unsigned int test_real::test_multiplication() {
......@@ -24,8 +24,8 @@ unsigned int test_real::test_multiplication() {
real rhs1(10);
real result1 = lhs1 * rhs1;
uint64_t res = double_mult( 5, 10 );
WASM_ASSERT(res == result1.value(), "real multiplication result is wrong");
return WASM_TEST_PASS;
assert(res == result1.value(), "real multiplication result is wrong");
return 0;
}
unsigned int test_real::test_addition()
......@@ -43,9 +43,9 @@ unsigned int test_real::test_addition()
real sum = result1+result2;
uint64_t c = double_add( a, b );
WASM_ASSERT(sum.value() == c, "real addition operation result is wrong");
assert(sum.value() == c, "real addition operation result is wrong");
return WASM_TEST_PASS;
return 0;
}
......@@ -8,17 +8,17 @@ unsigned int test_string::construct_with_size() {
size_t size1 = 100;
eosio::string str1(size1);
WASM_ASSERT( str1.get_size() == size1, "str1.get_size() == size1" );
WASM_ASSERT( str1.is_own_memory() == true, "str1.is_own_memory() == true" );
assert( str1.get_size() == size1, "str1.get_size() == size1" );
assert( str1.is_own_memory() == true, "str1.is_own_memory() == true" );
size_t size2 = 0;
eosio::string str2(size2);
WASM_ASSERT( str2.get_size() == size2, "str2.get_size() == size2" );
WASM_ASSERT( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
WASM_ASSERT( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
assert( str2.get_size() == size2, "str2.get_size() == size2" );
assert( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
assert( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
......@@ -28,17 +28,17 @@ unsigned int test_string::construct_with_data() {
eosio::string str1(data, size, false);
WASM_ASSERT( str1.get_size() == size, "str1.get_size() == size" );
WASM_ASSERT( str1.get_data() == data, "str1.get_data() == data" );
WASM_ASSERT( str1.is_own_memory() == false, "str1.is_own_memory() == false" );
assert( str1.get_size() == size, "str1.get_size() == size" );
assert( str1.get_data() == data, "str1.get_data() == data" );
assert( str1.is_own_memory() == false, "str1.is_own_memory() == false" );
eosio::string str2(data, 0, false);
WASM_ASSERT( str2.get_size() == 0, "str2.get_size() == 0" );
WASM_ASSERT( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
WASM_ASSERT( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
assert( str2.get_size() == 0, "str2.get_size() == 0" );
assert( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
assert( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::construct_with_data_partially() {
......@@ -48,14 +48,14 @@ unsigned int test_string::construct_with_data_partially() {
eosio::string str(data + offset, substr_size, false);
WASM_ASSERT( str.get_size() == substr_size, "str.get_size() == substr_size" );
WASM_ASSERT( str.get_data() == data + offset, "str.get_data() == data + offset" );
assert( str.get_size() == substr_size, "str.get_size() == substr_size" );
assert( str.get_data() == data + offset, "str.get_data() == data + offset" );
for (uint8_t i = offset; i < substr_size; i++) {
WASM_ASSERT( str[i] == data[offset + i], "str[i] == data[offset + i]" );
assert( str[i] == data[offset + i], "str[i] == data[offset + i]" );
}
WASM_ASSERT( str.is_own_memory() == false, "str.is_own_memory() == false" );
assert( str.is_own_memory() == false, "str.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::construct_with_data_copied() {
......@@ -64,20 +64,20 @@ unsigned int test_string::construct_with_data_copied() {
eosio::string str1(data, size, true);
WASM_ASSERT( str1.get_size() == size, "str1.get_size() == size" );
WASM_ASSERT( str1.get_data() != data, "str1.get_data() != data" );
assert( str1.get_size() == size, "str1.get_size() == size" );
assert( str1.get_data() != data, "str1.get_data() != data" );
for (uint8_t i = 0; i < size; i++) {
WASM_ASSERT( str1[i] == data[i], "str1[i] == data[i]" );
assert( str1[i] == data[i], "str1[i] == data[i]" );
}
WASM_ASSERT( str1.is_own_memory() == true, "str.is_own_memory() == true" );
assert( str1.is_own_memory() == true, "str.is_own_memory() == true" );
eosio::string str2(data, 0, true);
WASM_ASSERT( str2.get_size() == 0, "str2.get_size() == 0" );
WASM_ASSERT( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
WASM_ASSERT( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
assert( str2.get_size() == 0, "str2.get_size() == 0" );
assert( str2.get_data() == nullptr, "str2.get_data() == nullptr" );
assert( str2.is_own_memory() == false, "str2.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::copy_constructor() {
......@@ -88,13 +88,13 @@ unsigned int test_string::copy_constructor() {
eosio::string str2 = str1;
WASM_ASSERT( str1.get_size() == str2.get_size(), "str1.get_size() == str2.get_size()" );
WASM_ASSERT( str1.get_data() == str2.get_data(), "str1.get_data() == str2.getget_data_size()" );
WASM_ASSERT( str1.is_own_memory() == str2.is_own_memory(), "str1.is_own_memory() == str2.is_own_memory()" );
WASM_ASSERT( str1.get_refcount() == str2.get_refcount(), "str1.get_refcount() == str2.get_refcount()" );
WASM_ASSERT( str1.get_refcount() == 2, "str1.refcount() == 2" );
assert( str1.get_size() == str2.get_size(), "str1.get_size() == str2.get_size()" );
assert( str1.get_data() == str2.get_data(), "str1.get_data() == str2.getget_data_size()" );
assert( str1.is_own_memory() == str2.is_own_memory(), "str1.is_own_memory() == str2.is_own_memory()" );
assert( str1.get_refcount() == str2.get_refcount(), "str1.get_refcount() == str2.get_refcount()" );
assert( str1.get_refcount() == 2, "str1.refcount() == 2" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::assignment_operator() {
......@@ -106,13 +106,13 @@ unsigned int test_string::assignment_operator() {
eosio::string str2;
str2 = str1;
WASM_ASSERT( str1.get_size() == str2.get_size(), "str1.get_size() == str2.get_size()" );
WASM_ASSERT( str1.get_data() == str2.get_data(), "str1.get_data() == str2.getget_data_size()" );
WASM_ASSERT( str1.is_own_memory() == str2.is_own_memory(), "str1.is_own_memory() == str2.is_own_memory()" );
WASM_ASSERT( str1.get_refcount() == str2.get_refcount(), "str1.get_refcount() == str2.get_refcount()" );
WASM_ASSERT( str1.get_refcount() == 2, "str1.refcount() == 2" );
assert( str1.get_size() == str2.get_size(), "str1.get_size() == str2.get_size()" );
assert( str1.get_data() == str2.get_data(), "str1.get_data() == str2.getget_data_size()" );
assert( str1.is_own_memory() == str2.is_own_memory(), "str1.is_own_memory() == str2.is_own_memory()" );
assert( str1.get_refcount() == str2.get_refcount(), "str1.get_refcount() == str2.get_refcount()" );
assert( str1.get_refcount() == 2, "str1.refcount() == 2" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::index_operator() {
......@@ -122,10 +122,10 @@ unsigned int test_string::index_operator() {
eosio::string str(data, size, false);
for (uint8_t i = 0; i < size; i++) {
WASM_ASSERT( str[i] == data[i], "str[i] == data[i]" );
assert( str[i] == data[i], "str[i] == data[i]" );
}
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::index_out_of_bound() {
......@@ -135,7 +135,7 @@ unsigned int test_string::index_out_of_bound() {
eosio::string str(data, size, false);
char c = str[size];
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::substring() {
......@@ -148,14 +148,14 @@ unsigned int test_string::substring() {
size_t offset = 2;
eosio::string substr = str.substr(offset, substr_size, false);
WASM_ASSERT( substr.get_size() == substr_size, "str.get_size() == substr_size" );
WASM_ASSERT( substr.get_data() == str.get_data() + offset, "substr.get_data() == str.get_data() + offset" );
assert( substr.get_size() == substr_size, "str.get_size() == substr_size" );
assert( substr.get_data() == str.get_data() + offset, "substr.get_data() == str.get_data() + offset" );
for (uint8_t i = offset; i < substr_size; i++) {
WASM_ASSERT( substr[i] == str[offset + i], "substr[i] == str[offset + i]" );
assert( substr[i] == str[offset + i], "substr[i] == str[offset + i]" );
}
WASM_ASSERT( substr.is_own_memory() == false, "substr.is_own_memory() == false" );
assert( substr.is_own_memory() == false, "substr.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::substring_out_of_bound() {
......@@ -168,7 +168,7 @@ unsigned int test_string::substring_out_of_bound() {
size_t offset = 1;
eosio::string substr = str.substr(offset, substr_size, false);
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::concatenation_null_terminated() {
......@@ -183,16 +183,16 @@ unsigned int test_string::concatenation_null_terminated() {
str1 += str2;
WASM_ASSERT( str1.get_data() != data1, "str1.get_data() != data1" );
WASM_ASSERT( str1.get_size() == size1 + size2 - 1, "str1.get_size == size1 + size2 - 1" );
assert( str1.get_data() != data1, "str1.get_data() != data1" );
assert( str1.get_size() == size1 + size2 - 1, "str1.get_size == size1 + size2 - 1" );
for (uint8_t i = 0; i < size1 - 1; i++) {
WASM_ASSERT( str1[i] == data1[i], "str1[i] == data1[i]" );
assert( str1[i] == data1[i], "str1[i] == data1[i]" );
}
for (uint8_t i = 0; i < size2; i++) {
WASM_ASSERT( str1[size1 - 1 + i] == data2[i], "str1[i] == data2[i]" );
assert( str1[size1 - 1 + i] == data2[i], "str1[i] == data2[i]" );
}
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::concatenation_non_null_terminated() {
......@@ -207,16 +207,16 @@ unsigned int test_string::concatenation_non_null_terminated() {
str1 += str2;
WASM_ASSERT( str1.get_data() != data1, "str1.get_data() != data1" );
WASM_ASSERT( str1.get_size() == size1 + size2, "str1.get_size == size1 + size2" );
assert( str1.get_data() != data1, "str1.get_data() != data1" );
assert( str1.get_size() == size1 + size2, "str1.get_size == size1 + size2" );
for (uint8_t i = 0; i < size1; i++) {
WASM_ASSERT( str1[i] == data1[i], "str1[i] == data1[i]" );
assert( str1[i] == data1[i], "str1[i] == data1[i]" );
}
for (uint8_t i = 0; i < size2; i++) {
WASM_ASSERT( str1[size1 + i] == data2[i], "str1[i] == data2[i]" );
assert( str1[size1 + i] == data2[i], "str1[i] == data2[i]" );
}
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::assign() {
......@@ -226,20 +226,20 @@ unsigned int test_string::assign() {
eosio::string str(100);
str.assign(data, size, true);
WASM_ASSERT( str.get_size() == size, "str.get_size() == size" );
WASM_ASSERT( str.get_data() != data, "str.get_data() != data" );
assert( str.get_size() == size, "str.get_size() == size" );
assert( str.get_data() != data, "str.get_data() != data" );
for (uint8_t i = 0; i < size; i++) {
WASM_ASSERT( str[i] == data[i], "str[i] == data[i]" );
assert( str[i] == data[i], "str[i] == data[i]" );
}
WASM_ASSERT( str.is_own_memory() == true, "str.is_own_memory() == true" );
assert( str.is_own_memory() == true, "str.is_own_memory() == true" );
str.assign(data, 0, true);
WASM_ASSERT( str.get_size() == 0, "str.get_size() == 0" );
WASM_ASSERT( str.get_data() == nullptr, "str.get_data() == nullptr" );
WASM_ASSERT( str.is_own_memory() == false, "str.is_own_memory() == false" );
assert( str.get_size() == 0, "str.get_size() == 0" );
assert( str.get_data() == nullptr, "str.get_data() == nullptr" );
assert( str.is_own_memory() == false, "str.is_own_memory() == false" );
return WASM_TEST_PASS;
return 0;;
}
......@@ -276,17 +276,17 @@ unsigned int test_string::comparison_operator() {
size_t size8 = sizeof(data8)/sizeof(char);
eosio::string str8(data8, size8, false);
WASM_ASSERT( str1 == str2, "str1 == str2" );
WASM_ASSERT( str1 != str3, "str1 != str3" );
WASM_ASSERT( str1 < str3, "str1 < str3" );
WASM_ASSERT( str2 > str4, "str2 > str4" );
WASM_ASSERT( str1.compare(str2) == 0, "str1.compare(str2) == 0" );
WASM_ASSERT( str1.compare(str3) < 0, "str1.compare(str3) < 0" );
WASM_ASSERT( str1.compare(str4) > 0, "str1.compare(str4) > 0" );
WASM_ASSERT( str5.compare(str6) < 0, "st5.compare(str6) < 0" );
WASM_ASSERT( str7.compare(str8) > 0, "str7.compare(str8) > 0" );
return WASM_TEST_PASS;
assert( str1 == str2, "str1 == str2" );
assert( str1 != str3, "str1 != str3" );
assert( str1 < str3, "str1 < str3" );
assert( str2 > str4, "str2 > str4" );
assert( str1.compare(str2) == 0, "str1.compare(str2) == 0" );
assert( str1.compare(str3) < 0, "str1.compare(str3) < 0" );
assert( str1.compare(str4) > 0, "str1.compare(str4) > 0" );
assert( str5.compare(str6) < 0, "st5.compare(str6) < 0" );
assert( str7.compare(str8) > 0, "str7.compare(str8) > 0" );
return 0;;
}
unsigned int test_string::print_null_terminated() {
......@@ -297,7 +297,7 @@ unsigned int test_string::print_null_terminated() {
eosio::print(str);
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::print_non_null_terminated() {
......@@ -308,7 +308,7 @@ unsigned int test_string::print_non_null_terminated() {
eosio::print(str);
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::print_unicode() {
......@@ -319,7 +319,7 @@ unsigned int test_string::print_unicode() {
eosio::print(str);
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::valid_utf8() {
......@@ -347,7 +347,7 @@ unsigned int test_string::valid_utf8() {
eosio::string valid_chinese_str2(chinese_str_data2, chinese_str_size2, false);
assert_is_utf8(valid_chinese_str2.get_data(), valid_chinese_str2.get_size(), "the string should be a valid utf8 string");
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::invalid_utf8() {
......@@ -358,10 +358,8 @@ unsigned int test_string::invalid_utf8() {
eosio::string invalid_chinese_str(chinese_str_data, 5, false);
assert_is_utf8(invalid_chinese_str.get_data(), invalid_chinese_str.get_size(), "the string should be a valid utf8 string");
return WASM_TEST_PASS;
return 0;;
}
unsigned int test_string::string_literal() {
// Construct
char data1[] = "abcdefghij";
......@@ -369,19 +367,19 @@ unsigned int test_string::string_literal() {
eosio::string str = "abcdefghij";
WASM_ASSERT( str.get_size() == 11, "data1 str.get_size() == 11" );
assert( str.get_size() == 11, "data1 str.get_size() == 11" );
for (uint8_t i = 0; i < 11; i++) {
WASM_ASSERT( str[i] == data1[i], "data1 str[i] == data1[i]" );
assert( str[i] == data1[i], "data1 str[i] == data1[i]" );
}
WASM_ASSERT( str.is_own_memory() == true, "data1 str.is_own_memory() == true" );
assert( str.is_own_memory() == true, "data1 str.is_own_memory() == true" );
str = "klmnopqrstuvwxyz";
WASM_ASSERT( str.get_size() == 17, "data2 str.get_size() == 17" );
assert( str.get_size() == 17, "data2 str.get_size() == 17" );
for (uint8_t i = 0; i < 17; i++) {
WASM_ASSERT( str[i] == data2[i], "data2 str[i] == data2[i]" );
assert( str[i] == data2[i], "data2 str[i] == data2[i]" );
}
WASM_ASSERT( str.is_own_memory() == true, "data2 str.is_own_memory() == true" );
assert( str.is_own_memory() == true, "data2 str.is_own_memory() == true" );
return WASM_TEST_PASS;
return 0;;
}
......@@ -7,17 +7,19 @@
#include "test_api.hpp"
#define WASM_TEST_FAIL 1
unsigned int test_transaction::send_message() {
dummy_action payload = {DUMMY_MESSAGE_DEFAULT_A, DUMMY_MESSAGE_DEFAULT_B, DUMMY_MESSAGE_DEFAULT_C};
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), &payload, sizeof(dummy_action));
message_send(msg);
return WASM_TEST_PASS;
return 0;
}
unsigned int test_transaction::send_message_empty() {
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_action", "assert_true"), nullptr, 0);
message_send(msg);
return WASM_TEST_PASS;
return 0;
}
/**
......@@ -28,7 +30,7 @@ unsigned int test_transaction::send_message_max() {
for (int i = 0; i < 10; i++) {
message_create(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), &payload, sizeof(dummy_action));
}
assert(false, "send_message_max() should've thrown an error");
return WASM_TEST_FAIL;
}
......@@ -38,6 +40,8 @@ unsigned int test_transaction::send_message_max() {
unsigned int test_transaction::send_message_large() {
char large_message[8 * 1024];
message_create(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), large_message, sizeof(large_message));
assert(false, "send_message_large() should've thrown an error");
return WASM_TEST_FAIL;
}
......@@ -49,7 +53,7 @@ unsigned int test_transaction::send_message_recurse() {
uint32_t size = read_action(buffer, 1024);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_transaction", "send_message_recurse"), buffer, size);
message_send(msg);
return WASM_TEST_PASS;
return 0;
}
/**
......@@ -58,7 +62,7 @@ unsigned int test_transaction::send_message_recurse() {
unsigned int test_transaction::send_message_inline_fail() {
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_action", "assert_false"), nullptr, 0);
message_send(msg);
return WASM_TEST_PASS;
return 0;
}
unsigned int test_transaction::send_transaction() {
......@@ -70,13 +74,15 @@ unsigned int test_transaction::send_transaction() {
transaction_require_scope(trx, N(testapi));
transaction_add_message(trx, msg);
transaction_send(trx);
return WASM_TEST_PASS;
return 0;
}
unsigned int test_transaction::send_transaction_empty() {
auto trx = transaction_create();
transaction_require_scope(trx, N(testapi));
transaction_send(trx);
assert(false, "send_transaction_empty() should've thrown an error");
return WASM_TEST_FAIL;
}
......@@ -88,6 +94,7 @@ unsigned int test_transaction::send_transaction_max() {
transaction_create();
}
assert(false, "send_transaction_max() should've thrown an error");
return WASM_TEST_FAIL;
}
......@@ -104,6 +111,8 @@ unsigned int test_transaction::send_transaction_large() {
}
transaction_send(trx);
assert(false, "send_transaction_large() should've thrown an error");
return WASM_TEST_FAIL;
}
......@@ -8,101 +8,101 @@
unsigned int test_types::types_size() {
WASM_ASSERT( sizeof(int64_t) == 8, "int64_t size != 8");
WASM_ASSERT( sizeof(uint64_t) == 8, "uint64_t size != 8");
WASM_ASSERT( sizeof(uint32_t) == 4, "uint32_t size != 4");
WASM_ASSERT( sizeof(int32_t) == 4, "int32_t size != 4");
WASM_ASSERT( sizeof(uint128_t) == 16, "uint128_t size != 16");
WASM_ASSERT( sizeof(int128_t) == 16, "int128_t size != 16");
WASM_ASSERT( sizeof(uint8_t) == 1, "uint8_t size != 1");
WASM_ASSERT( sizeof(account_name) == 8, "account_name size != 8");
WASM_ASSERT( sizeof(token_name) == 8, "token_name size != 8");
WASM_ASSERT( sizeof(table_name) == 8, "table_name size != 8");
WASM_ASSERT( sizeof(time) == 4, "time size != 4");
WASM_ASSERT( sizeof(uint256) == 32, "uint256 != 32" );
assert( sizeof(int64_t) == 8, "int64_t size != 8");
assert( sizeof(uint64_t) == 8, "uint64_t size != 8");
assert( sizeof(uint32_t) == 4, "uint32_t size != 4");
assert( sizeof(int32_t) == 4, "int32_t size != 4");
assert( sizeof(uint128_t) == 16, "uint128_t size != 16");
assert( sizeof(int128_t) == 16, "int128_t size != 16");
assert( sizeof(uint8_t) == 1, "uint8_t size != 1");
assert( sizeof(account_name) == 8, "account_name size != 8");
assert( sizeof(token_name) == 8, "token_name size != 8");
assert( sizeof(table_name) == 8, "table_name size != 8");
assert( sizeof(time) == 4, "time size != 4");
assert( sizeof(uint256) == 32, "uint256 != 32" );
return WASM_TEST_PASS;
return 0;
}
unsigned int test_types::char_to_symbol() {
WASM_ASSERT( eosio::char_to_symbol('1') == 1, "eosio::char_to_symbol('1') != 1");
WASM_ASSERT( eosio::char_to_symbol('2') == 2, "eosio::char_to_symbol('2') != 2");
WASM_ASSERT( eosio::char_to_symbol('3') == 3, "eosio::char_to_symbol('3') != 3");
WASM_ASSERT( eosio::char_to_symbol('4') == 4, "eosio::char_to_symbol('4') != 4");
WASM_ASSERT( eosio::char_to_symbol('5') == 5, "eosio::char_to_symbol('5') != 5");
WASM_ASSERT( eosio::char_to_symbol('a') == 6, "eosio::char_to_symbol('a') != 6");
WASM_ASSERT( eosio::char_to_symbol('b') == 7, "eosio::char_to_symbol('b') != 7");
WASM_ASSERT( eosio::char_to_symbol('c') == 8, "eosio::char_to_symbol('c') != 8");
WASM_ASSERT( eosio::char_to_symbol('d') == 9, "eosio::char_to_symbol('d') != 9");
WASM_ASSERT( eosio::char_to_symbol('e') == 10, "eosio::char_to_symbol('e') != 10");
WASM_ASSERT( eosio::char_to_symbol('f') == 11, "eosio::char_to_symbol('f') != 11");
WASM_ASSERT( eosio::char_to_symbol('g') == 12, "eosio::char_to_symbol('g') != 12");
WASM_ASSERT( eosio::char_to_symbol('h') == 13, "eosio::char_to_symbol('h') != 13");
WASM_ASSERT( eosio::char_to_symbol('i') == 14, "eosio::char_to_symbol('i') != 14");
WASM_ASSERT( eosio::char_to_symbol('j') == 15, "eosio::char_to_symbol('j') != 15");
WASM_ASSERT( eosio::char_to_symbol('k') == 16, "eosio::char_to_symbol('k') != 16");
WASM_ASSERT( eosio::char_to_symbol('l') == 17, "eosio::char_to_symbol('l') != 17");
WASM_ASSERT( eosio::char_to_symbol('m') == 18, "eosio::char_to_symbol('m') != 18");
WASM_ASSERT( eosio::char_to_symbol('n') == 19, "eosio::char_to_symbol('n') != 19");
WASM_ASSERT( eosio::char_to_symbol('o') == 20, "eosio::char_to_symbol('o') != 20");
WASM_ASSERT( eosio::char_to_symbol('p') == 21, "eosio::char_to_symbol('p') != 21");
WASM_ASSERT( eosio::char_to_symbol('q') == 22, "eosio::char_to_symbol('q') != 22");
WASM_ASSERT( eosio::char_to_symbol('r') == 23, "eosio::char_to_symbol('r') != 23");
WASM_ASSERT( eosio::char_to_symbol('s') == 24, "eosio::char_to_symbol('s') != 24");
WASM_ASSERT( eosio::char_to_symbol('t') == 25, "eosio::char_to_symbol('t') != 25");
WASM_ASSERT( eosio::char_to_symbol('u') == 26, "eosio::char_to_symbol('u') != 26");
WASM_ASSERT( eosio::char_to_symbol('v') == 27, "eosio::char_to_symbol('v') != 27");
WASM_ASSERT( eosio::char_to_symbol('w') == 28, "eosio::char_to_symbol('w') != 28");
WASM_ASSERT( eosio::char_to_symbol('x') == 29, "eosio::char_to_symbol('x') != 29");
WASM_ASSERT( eosio::char_to_symbol('y') == 30, "eosio::char_to_symbol('y') != 30");
WASM_ASSERT( eosio::char_to_symbol('z') == 31, "eosio::char_to_symbol('z') != 31");
assert( eosio::char_to_symbol('1') == 1, "eosio::char_to_symbol('1') != 1");
assert( eosio::char_to_symbol('2') == 2, "eosio::char_to_symbol('2') != 2");
assert( eosio::char_to_symbol('3') == 3, "eosio::char_to_symbol('3') != 3");
assert( eosio::char_to_symbol('4') == 4, "eosio::char_to_symbol('4') != 4");
assert( eosio::char_to_symbol('5') == 5, "eosio::char_to_symbol('5') != 5");
assert( eosio::char_to_symbol('a') == 6, "eosio::char_to_symbol('a') != 6");
assert( eosio::char_to_symbol('b') == 7, "eosio::char_to_symbol('b') != 7");
assert( eosio::char_to_symbol('c') == 8, "eosio::char_to_symbol('c') != 8");
assert( eosio::char_to_symbol('d') == 9, "eosio::char_to_symbol('d') != 9");
assert( eosio::char_to_symbol('e') == 10, "eosio::char_to_symbol('e') != 10");
assert( eosio::char_to_symbol('f') == 11, "eosio::char_to_symbol('f') != 11");
assert( eosio::char_to_symbol('g') == 12, "eosio::char_to_symbol('g') != 12");
assert( eosio::char_to_symbol('h') == 13, "eosio::char_to_symbol('h') != 13");
assert( eosio::char_to_symbol('i') == 14, "eosio::char_to_symbol('i') != 14");
assert( eosio::char_to_symbol('j') == 15, "eosio::char_to_symbol('j') != 15");
assert( eosio::char_to_symbol('k') == 16, "eosio::char_to_symbol('k') != 16");
assert( eosio::char_to_symbol('l') == 17, "eosio::char_to_symbol('l') != 17");
assert( eosio::char_to_symbol('m') == 18, "eosio::char_to_symbol('m') != 18");
assert( eosio::char_to_symbol('n') == 19, "eosio::char_to_symbol('n') != 19");
assert( eosio::char_to_symbol('o') == 20, "eosio::char_to_symbol('o') != 20");
assert( eosio::char_to_symbol('p') == 21, "eosio::char_to_symbol('p') != 21");
assert( eosio::char_to_symbol('q') == 22, "eosio::char_to_symbol('q') != 22");
assert( eosio::char_to_symbol('r') == 23, "eosio::char_to_symbol('r') != 23");
assert( eosio::char_to_symbol('s') == 24, "eosio::char_to_symbol('s') != 24");
assert( eosio::char_to_symbol('t') == 25, "eosio::char_to_symbol('t') != 25");
assert( eosio::char_to_symbol('u') == 26, "eosio::char_to_symbol('u') != 26");
assert( eosio::char_to_symbol('v') == 27, "eosio::char_to_symbol('v') != 27");
assert( eosio::char_to_symbol('w') == 28, "eosio::char_to_symbol('w') != 28");
assert( eosio::char_to_symbol('x') == 29, "eosio::char_to_symbol('x') != 29");
assert( eosio::char_to_symbol('y') == 30, "eosio::char_to_symbol('y') != 30");
assert( eosio::char_to_symbol('z') == 31, "eosio::char_to_symbol('z') != 31");
for(unsigned char i = 0; i<255; i++) {
if((i >= 'a' && i <= 'z') || (i >= '1' || i <= '5')) continue;
WASM_ASSERT( eosio::char_to_symbol(i) == 0, "eosio::char_to_symbol() != 0");
assert( eosio::char_to_symbol(i) == 0, "eosio::char_to_symbol() != 0");
}
return WASM_TEST_PASS;
return 0;
}
unsigned int test_types::string_to_name() {
WASM_ASSERT( eosio::string_to_name("a") == N(a) , "eosio::string_to_name(a)" );
WASM_ASSERT( eosio::string_to_name("ba") == N(ba) , "eosio::string_to_name(ba)" );
WASM_ASSERT( eosio::string_to_name("cba") == N(cba) , "eosio::string_to_name(cba)" );
WASM_ASSERT( eosio::string_to_name("dcba") == N(dcba) , "eosio::string_to_name(dcba)" );
WASM_ASSERT( eosio::string_to_name("edcba") == N(edcba) , "eosio::string_to_name(edcba)" );
WASM_ASSERT( eosio::string_to_name("fedcba") == N(fedcba) , "eosio::string_to_name(fedcba)" );
WASM_ASSERT( eosio::string_to_name("gfedcba") == N(gfedcba) , "eosio::string_to_name(gfedcba)" );
WASM_ASSERT( eosio::string_to_name("hgfedcba") == N(hgfedcba) , "eosio::string_to_name(hgfedcba)" );
WASM_ASSERT( eosio::string_to_name("ihgfedcba") == N(ihgfedcba) , "eosio::string_to_name(ihgfedcba)" );
WASM_ASSERT( eosio::string_to_name("jihgfedcba") == N(jihgfedcba) , "eosio::string_to_name(jihgfedcba)" );
WASM_ASSERT( eosio::string_to_name("kjihgfedcba") == N(kjihgfedcba) , "eosio::string_to_name(kjihgfedcba)" );
WASM_ASSERT( eosio::string_to_name("lkjihgfedcba") == N(lkjihgfedcba) , "eosio::string_to_name(lkjihgfedcba)" );
WASM_ASSERT( eosio::string_to_name("mlkjihgfedcba") == N(mlkjihgfedcba) , "eosio::string_to_name(mlkjihgfedcba)" );
WASM_ASSERT( eosio::string_to_name("mlkjihgfedcba1") == N(mlkjihgfedcba2) , "eosio::string_to_name(mlkjihgfedcba2)" );
WASM_ASSERT( eosio::string_to_name("mlkjihgfedcba55") == N(mlkjihgfedcba14) , "eosio::string_to_name(mlkjihgfedcba14)" );
WASM_ASSERT( eosio::string_to_name("azAA34") == N(azBB34) , "eosio::string_to_name N(azBB34)" );
WASM_ASSERT( eosio::string_to_name("AZaz12Bc34") == N(AZaz12Bc34) , "eosio::string_to_name AZaz12Bc34" );
WASM_ASSERT( eosio::string_to_name("AAAAAAAAAAAAAAA") == eosio::string_to_name("BBBBBBBBBBBBBDDDDDFFFGG") , "eosio::string_to_name BBBBBBBBBBBBBDDDDDFFFGG" );
assert( eosio::string_to_name("a") == N(a) , "eosio::string_to_name(a)" );
assert( eosio::string_to_name("ba") == N(ba) , "eosio::string_to_name(ba)" );
assert( eosio::string_to_name("cba") == N(cba) , "eosio::string_to_name(cba)" );
assert( eosio::string_to_name("dcba") == N(dcba) , "eosio::string_to_name(dcba)" );
assert( eosio::string_to_name("edcba") == N(edcba) , "eosio::string_to_name(edcba)" );
assert( eosio::string_to_name("fedcba") == N(fedcba) , "eosio::string_to_name(fedcba)" );
assert( eosio::string_to_name("gfedcba") == N(gfedcba) , "eosio::string_to_name(gfedcba)" );
assert( eosio::string_to_name("hgfedcba") == N(hgfedcba) , "eosio::string_to_name(hgfedcba)" );
assert( eosio::string_to_name("ihgfedcba") == N(ihgfedcba) , "eosio::string_to_name(ihgfedcba)" );
assert( eosio::string_to_name("jihgfedcba") == N(jihgfedcba) , "eosio::string_to_name(jihgfedcba)" );
assert( eosio::string_to_name("kjihgfedcba") == N(kjihgfedcba) , "eosio::string_to_name(kjihgfedcba)" );
assert( eosio::string_to_name("lkjihgfedcba") == N(lkjihgfedcba) , "eosio::string_to_name(lkjihgfedcba)" );
assert( eosio::string_to_name("mlkjihgfedcba") == N(mlkjihgfedcba) , "eosio::string_to_name(mlkjihgfedcba)" );
assert( eosio::string_to_name("mlkjihgfedcba1") == N(mlkjihgfedcba2) , "eosio::string_to_name(mlkjihgfedcba2)" );
assert( eosio::string_to_name("mlkjihgfedcba55") == N(mlkjihgfedcba14) , "eosio::string_to_name(mlkjihgfedcba14)" );
assert( eosio::string_to_name("azAA34") == N(azBB34) , "eosio::string_to_name N(azBB34)" );
assert( eosio::string_to_name("AZaz12Bc34") == N(AZaz12Bc34) , "eosio::string_to_name AZaz12Bc34" );
assert( eosio::string_to_name("AAAAAAAAAAAAAAA") == eosio::string_to_name("BBBBBBBBBBBBBDDDDDFFFGG") , "eosio::string_to_name BBBBBBBBBBBBBDDDDDFFFGG" );
return WASM_TEST_PASS;
return 0;
}
unsigned int test_types::name_class() {
WASM_ASSERT ( eosio::name(eosio::string_to_name("azAA34")).value == N(azAA34), "eosio::name != N(azAA34)" );
WASM_ASSERT ( eosio::name(eosio::string_to_name("AABBCC")).value == 0, "eosio::name != N(0)" );
WASM_ASSERT ( eosio::name(eosio::string_to_name("AA11")).value == N(AA11), "eosio::name != N(AA11)" );
WASM_ASSERT ( eosio::name(eosio::string_to_name("11AA")).value == N(11), "eosio::name != N(11)" );
WASM_ASSERT ( eosio::name(eosio::string_to_name("22BBCCXXAA")).value == N(22), "eosio::name != N(22)" );
WASM_ASSERT ( eosio::name(eosio::string_to_name("AAAbbcccdd")) == eosio::name(eosio::string_to_name("AAAbbcccdd")), "eosio::name == eosio::name" );
assert( eosio::name(eosio::string_to_name("azAA34")).value == N(azAA34), "eosio::name != N(azAA34)" );
assert( eosio::name(eosio::string_to_name("AABBCC")).value == 0, "eosio::name != N(0)" );
assert( eosio::name(eosio::string_to_name("AA11")).value == N(AA11), "eosio::name != N(AA11)" );
assert( eosio::name(eosio::string_to_name("11AA")).value == N(11), "eosio::name != N(11)" );
assert( eosio::name(eosio::string_to_name("22BBCCXXAA")).value == N(22), "eosio::name != N(22)" );
assert( eosio::name(eosio::string_to_name("AAAbbcccdd")) == eosio::name(eosio::string_to_name("AAAbbcccdd")), "eosio::name == eosio::name" );
uint64_t tmp = eosio::name(eosio::string_to_name("11bbcccdd"));
WASM_ASSERT(N(11bbcccdd) == tmp, "N(11bbcccdd) == tmp");
assert(N(11bbcccdd) == tmp, "N(11bbcccdd) == tmp");
return WASM_TEST_PASS;
return 0;
}
......@@ -53,28 +53,29 @@ endif()
# Setup for the `api_tests`
#
###########################################################################################
#"api_tests/db_test/db_test.cpp"
add_subdirectory(api_tests)
file(GLOB API_SC_TESTS "api_tests/action_test/action_test.cpp"
"api_tests/account_test/account_test.cpp"
"api_tests/chain_test/chain_test.cpp"
"api_tests/crypto_test/crypto_test.cpp"
"api_tests/extended_memory_test/extended_memory_test.cpp"
"api_tests/fixedpoint_test/fixedpoint_test.cpp"
add_dependencies(unit_tests test_api)
#"api_tests/db_test/db_test.cpp"
#file(GLOB API_SC_TESTS #"api_tests/action_test/action_test.cpp"
#"api_tests/account_test/account_test.cpp"
# "api_tests/chain_test/chain_test.cpp"
# "api_tests/crypto_test/crypto_test.cpp"
# "api_tests/extended_memory_test/extended_memory_test.cpp"
# "api_tests/fixedpoint_test/fixedpoint_test.cpp"
# "api_tests/db_test/db_test.cpp"
"api_tests/memory_test/memory_test.cpp"
"api_tests/math_test/math_test.cpp"
"api_tests/print_test/print_test.cpp"
"api_tests/real_test/real_test.cpp"
"api_tests/string_test/string_test.cpp"
"api_tests/types_test/types_test.cpp"
"api_tests/transaction_test/transaction_test.cpp")
# "api_tests/memory_test/memory_test.cpp"
# "api_tests/math_test/math_test.cpp"
#"api_tests/print_test/print_test.cpp"
#"api_tests/real_test/real_test.cpp"
#"api_tests/string_test/string_test.cpp"
#"api_tests/types_test/types_test.cpp")
# "api_tests/transaction_test/transaction_test.cpp")
# we need to get the `custom` target name that wasm.cmake will generate with add_wast_target
foreach(api_sc_test_f ${API_SC_TESTS})
get_filename_component(_tmp ${api_sc_test_f} NAME)
string(REGEX REPLACE ".cpp" "" _tmp ${_tmp})
add_dependencies(unit_tests "${_tmp}") # add the add_wast_target target `${_tmp}.sc`
endforeach(api_test_f)
##foreach(api_sc_test_f ${API_SC_TESTS})
# get_filename_component(_tmp ${api_sc_test_f} NAME)
# string(REGEX REPLACE ".cpp" "" _tmp ${_tmp})
# add_dependencies(unit_tests "${_tmp}") # add the add_wast_target target `${_tmp}.sc`
#endforeach(api_test_f)
###########################################################################################
#
......
#add_wast_target(test_api "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(action_test)
add_subdirectory(account_test)
add_subdirectory(chain_test)
add_subdirectory(crypto_test)
#add_subdirectory(action_test)
#add_subdirectory(account_test)
#add_subdirectory(chain_test)
#add_subdirectory(crypto_test)
#add_subdirectory(db_test)
add_subdirectory(extended_memory_test)
add_subdirectory(fixedpoint_test)
add_subdirectory(math_test)
add_subdirectory(memory_test)
add_subdirectory(print_test)
add_subdirectory(real_test)
add_subdirectory(string_test)
add_subdirectory(types_test)
add_subdirectory(transaction_test)
#add_subdirectory(extended_memory_test)
#add_subdirectory(math_test)
#add_subdirectory(string_test)
#add_subdirectory(fixedpoint_test)
#add_subdirectory(memory_test)
#add_subdirectory(print_test)
#add_subdirectory(real_test)
#add_subdirectory(types_test)
#add_subdirectory(transaction_test)
......@@ -4,7 +4,7 @@
*/
#include "../test_api.hpp"
#include "test_account.cpp"
#include "test_account_sc.cpp"
extern "C" {
void init() {
......
......@@ -3,11 +3,11 @@
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/account.hpp>
#include <eoslib/eos.hpp>
#include <eoslib/account.hpp>
#include <eoslib/system.h>
#include "../test_api.hpp"
#include "test_api.hpp"
/// must match #define in eos/types/asset.hpp
#define EOS_SYMBOL (int64_t(4) | (uint64_t('E') << 8) | (uint64_t('O') << 16) | (uint64_t('S') << 24))
......@@ -30,3 +30,12 @@ unsigned int test_account::test_balance_acc1()
assert(b.last_unstaking_time == 55, "account_balance_get should have set a last unstaking time of 55");
return 0;
}
extern "C" {
void init() {
}
void apply( unsigned long long code, unsigned long long action ) {
WASM_TEST_HANDLER(test_account, test_balance_acc1);
}
}
......@@ -3,8 +3,84 @@
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/eos.hpp>
#include "../test_api.hpp"
#include "test_action.cpp"
//#include "test_action.cpp"
void test_action::read_action_normal() {
char buffer[100];
uint32_t total = 0;
assert( current_receiver() == N(testapi), "current_receiver() == N(testapi)" );
assert(action_size() == sizeof(dummy_action), "action_size() == sizeof(dummy_action)");
total = read_action(buffer, 30);
assert(total == sizeof(dummy_action) , "read_action(30)" );
total = read_action(buffer, 100);
assert(total == sizeof(dummy_action) , "read_action(100)" );
total = read_action(buffer, 5);
assert(total == 5 , "read_action(5)" );
total = read_action(buffer, sizeof(dummy_action) );
assert(total == sizeof(dummy_action), "read_action(sizeof(dummy_action))" );
dummy_action *dummy13 = reinterpret_cast<dummy_action *>(buffer);
assert(dummy13->a == DUMMY_MESSAGE_DEFAULT_A, "dummy13->a == DUMMY_MESSAGE_DEFAULT_A");
assert(dummy13->b == DUMMY_MESSAGE_DEFAULT_B, "dummy13->b == DUMMY_MESSAGE_DEFAULT_B");
assert(dummy13->c == DUMMY_MESSAGE_DEFAULT_C, "dummy13->c == DUMMY_MESSAGE_DEFAULT_C");
}
void test_action::read_action_to_0() {
prints("made it here\n");
uint32_t total = read_action((void *)0, 0x7FFFFFFF); //0x7FFFFFFF);
prints("made it out\n");
// assert(false, "WHY YOU NO FAIL!");
}
void test_action::read_action_to_64k() {
uint32_t total = read_action( (void *)((1<<16)-1), 0x7FFFFFFF);
}
unsigned int test_action::require_notice() {
if( current_receiver() == N(testapi) ) {
eosio::require_recipient( N(acc1) );
eosio::require_recipient( N(acc2) );
eosio::require_recipient( N(acc1), N(acc2) );
assert(false, "Should've failed");
return 1;
} else if ( current_receiver() == N(acc1) || current_receiver() == N(acc2) ) {
return 0;
}
assert(false, "Should've failed");
return 1;
}
unsigned int test_action::require_auth() {
prints("require_auth");
eosio::require_auth( N(acc3) );
eosio::require_auth( N(acc4) );
return 0;
}
void test_action::assert_false() {
assert(false, "test_action::assert_false");
}
void test_action::assert_true() {
assert(true, "test_action::assert_true");
}
//unsigned int test_action::now() {
// uint32_t tmp = 0;
// uint32_t total = read_action(&tmp, sizeof(uint32_t));
// WASM_ASSERT( total == sizeof(uint32_t), "total == sizeof(uint32_t)");
// WASM_ASSERT( tmp == ::now(), "tmp == now()" );
// return WASM_TEST_PASS;
//}
extern "C" {
void init() {
......
/**
* @file
* @file api_tests.cpp
* @copyright defined in eos/LICENSE.txt
*/
#include <algorithm>
......@@ -39,28 +39,9 @@
#include <WASM/WASM.h>
#include <Runtime/Runtime.h>
//extern const char* test_api_wast;
//#include <test_api/test_api.wast.hpp>
//#include <test_api/test_api.hpp>
#include <test_api/test_api.wast.hpp>
#include "test_api.hpp"
//#include "memory_test/memory_test.wast.hpp"
#include <extended_memory_test/extended_memory_test.wast.hpp>
#include <action_test/action_test.wast.hpp>
#include <account_test/account_test.wast.hpp>
#include <real_test/real_test.wast.hpp>
#include <crypto_test/crypto_test.wast.hpp>
//#include <chain_test/chain_test.wast.hpp>
//#include <db_test/db_test.wast.hpp>
#include <fixedpoint_test/fixedpoint_test.wast.hpp>
#include <math_test/math_test.wast.hpp>
#include <memory_test/memory_test.wast.hpp>
#include <print_test/print_test.wast.hpp>
#include <string_test/string_test.wast.hpp>
#include <types_test/types_test.wast.hpp>
//#include "extended_memory_test/extended_memory_test.wast.hpp"
//#include "table_abi_test/table_abi_test.wast.hpp"
//#include "table_abi_test/table_abi_test.abi.hpp"
#include <eosio/chain/staked_balance_objects.hpp>
//#include <eosio/chain/balance_object.hpp>
......@@ -126,7 +107,7 @@ string U64Str(uint64_t i)
BOOST_AUTO_TEST_SUITE(api_tests)
/*
vector<uint8_t> assemble_wast( const std::string& wast ) {
// std::cout << "\n" << wast << "\n";
IR::Module module;
......@@ -159,7 +140,7 @@ vector<uint8_t> assemble_wast( const std::string& wast ) {
throw;
}
}
*/
}
template <typename T>
......@@ -350,7 +331,7 @@ BOOST_FIXTURE_TEST_CASE(account_tests, tester) { try {
trx.sign(get_private_key(N(inita), "active"), chain_id_type());
push_transaction(trx);
produce_blocks(1000);
set_code( N(testapi), account_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1);
//const auto& balance = get_balance(N(acc1));
......@@ -371,7 +352,7 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
produce_blocks(1000);
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), action_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1);
CALL_TEST_FUNCTION( *this, "test_action", "assert_true", {});
......@@ -409,7 +390,7 @@ BOOST_FIXTURE_TEST_CASE(chain_tests, tester) { try {
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), chain_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1);
auto& gpo = control->get_global_properties();
......@@ -429,7 +410,7 @@ BOOST_FIXTURE_TEST_CASE(db_tests, tester) { try {
produce_blocks(1000);
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), db_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1);
CALL_TEST_FUNCTION( *this, "test_db", "key_i64_general", {});
......@@ -447,7 +428,7 @@ BOOST_FIXTURE_TEST_CASE(fixedpoint_tests, tester) { try {
produce_blocks(1000);
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), fixedpoint_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1);
CALL_TEST_FUNCTION( *this, "test_fixedpoint", "create_instances", {});
......@@ -469,7 +450,7 @@ BOOST_FIXTURE_TEST_CASE(real_test, tester) { try {
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), real_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_real", "create_instances", {} );
produce_blocks(1000);
......@@ -492,7 +473,7 @@ BOOST_FIXTURE_TEST_CASE(real_test, tester) { try {
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), crypto_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_crypto", "test_sha256", {} );
produce_blocks(1000);
......@@ -516,7 +497,7 @@ BOOST_FIXTURE_TEST_CASE(memory_test, tester) { try {
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), memory_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_memory", "test_memory_allocs", {} );
produce_blocks(1000);
......@@ -546,7 +527,7 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_initial_memory, tester) { try {
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), extended_memory_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_extended_memory", "test_initial_buffer", {} );
} FC_LOG_AND_RETHROW() }
......@@ -557,7 +538,7 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_page_memory, tester) { try {
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), extended_memory_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_extended_memory", "test_page_memory", {} );
} FC_LOG_AND_RETHROW() }
......@@ -568,7 +549,7 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_page_memory_exceeded, tester) { try
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), extended_memory_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_extended_memory", "test_page_memory_exceeded", {} ),
page_memory_error, is_page_memory_error);
......@@ -580,7 +561,7 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_page_memory_negative_bytes, tester)
produce_blocks(1000);
transfer(N(inita), N(testapi), "100.0000 EOS", "memo");
produce_blocks(1000);
set_code(N(testapi), extended_memory_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1000);
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_extended_memory", "test_page_memory_negative_bytes", {} ),
page_memory_error, is_page_memory_error);
......@@ -599,7 +580,7 @@ BOOST_FIXTURE_TEST_CASE(string_tests, tester) { try {
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), string_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1000);
//transfer( N(testapi), N(testextmem), "1.0000 EOS", "memo" );
......@@ -643,7 +624,7 @@ BOOST_FIXTURE_TEST_CASE(print_tests, tester) { try {
//Set test code
transfer(N(inita), N(testapi), "10.0000 EOS", "memo");
set_code(N(testapi), print_test_wast);
set_code(N(testapi), test_api_wast);
produce_blocks(1);
string captured = "";
......@@ -691,7 +672,7 @@ BOOST_FIXTURE_TEST_CASE(math_tests, tester) { try {
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), math_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_math", "test_multeq", {});
......@@ -712,7 +693,7 @@ BOOST_FIXTURE_TEST_CASE(types_tests, tester) { try {
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
produce_blocks(1000);
set_code( N(testapi), types_test_wast );
set_code( N(testapi), test_api_wast );
produce_blocks(1000);
CALL_TEST_FUNCTION( *this, "test_types", "types_size", {});
......
......@@ -5,7 +5,7 @@
#include <eoslib/action.h>
#include <eoslib/chain.h>
#include "../test_api.hpp"
#include "test_api.hpp"
#pragma pack(push, 1)
struct producers {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册