提交 134512b1 编写于 作者: B Bucky Kittinger

Fixed some tests I didn't realize were crashing, and added fixes for string keys for db

上级 7957f446
......@@ -17,8 +17,8 @@ add_subdirectory(infinite)
add_subdirectory(proxy)
add_subdirectory(test_api)
add_subdirectory(test_api_mem)
add_subdirectory(test_api_db)
#add_subdirectory(simpledb)
#add_subdirectory(test_api_db)
#add_subdirectory(storage)
#add_subdirectory(social)
add_subdirectory(test.system)
......
......@@ -92,7 +92,6 @@ namespace testsystem {
using dispatcher = dispatcher_impl<set_account_limits, set_global_limits, set_producers, require_auth>;
};
extern "C" {
/// The apply method implements the dispatch of events to this contract
......
......@@ -17,7 +17,7 @@ struct producers {
void test_chain::test_activeprods() {
producers act_prods;
read_action(&act_prods, sizeof(producers));
eosio_assert(act_prods.len == 21, "producers.len != 21");
producers api_prods;
......
......@@ -16,7 +16,10 @@ void test_checktime::checktime_pass() {
void test_checktime::checktime_failure() {
int p = 0;
checktime_failure();
p++;
for ( unsigned long long i = 0; i < 10000000000000000000ULL; i++ )
for ( unsigned long long j = 0; i < 10000000000000000000ULL; i++ )
p += i+j;
eosio::print(p);
}
add_wast_target(test_api_db "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_BINARY_DIR})
add_wast_executable(TARGET test_api_db
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc++ libc eosiolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
......@@ -15,6 +15,8 @@ extern "C" {
void apply( unsigned long long code, unsigned long long action ) {
WASM_TEST_HANDLER(test_db, key_str_general);
#if 0
//test db
WASM_TEST_HANDLER(test_db, key_i64_general);
WASM_TEST_HANDLER(test_db, key_i64_remove_all);
......@@ -25,7 +27,6 @@ extern "C" {
WASM_TEST_HANDLER(test_db, key_i64_not_found);
WASM_TEST_HANDLER(test_db, key_i64_front_back);
WASM_TEST_HANDLER(test_db, key_i128i128_general);
#if 0
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);
......@@ -52,7 +53,7 @@ extern "C" {
#endif
//unhandled test call
assert(false, "Unknown Test");
eosio_assert(false, "Unknown Test");
}
}
此差异已折叠。
......@@ -699,7 +699,7 @@ using apply_handler = std::function<void(apply_context&)>;
if( itr == idx.end() ||
itr->t_id != t_id.id ||
!impl::record_scope_compare<IndexType, Scope>::compare(*itr, keys)) return 0;
!impl::record_scope_compare<IndexType, Scope>::compare(*itr, keys)) return -1;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
if (valuelen) {
......@@ -723,7 +723,7 @@ using apply_handler = std::function<void(apply_context&)>;
auto itr = idx.lower_bound( tuple );
if( itr == idx.end() ||
itr->t_id != t_id.id ) return 0;
itr->t_id != t_id.id ) return -1;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......
......@@ -875,7 +875,7 @@ class db_api : public context_aware_api {
return context.remove_record<ObjectType>(t_id, keys);
}
};
/*
template<>
class db_api<keystr_value_object> : public context_aware_api {
using KeyType = std::string;
......@@ -883,31 +883,40 @@ class db_api<keystr_value_object> : public context_aware_api {
using KeyArrayType = KeyType[KeyCount];
using ContextMethodType = int(apply_context::*)(const table_id_object&, const KeyType*, const char*, size_t);
/* TODO something weird is going on here, will maybe fix before DB changes or this might get
* totally changed anyway
private:
int call(ContextMethodType method, const scope_name& scope, const name& table,
array_ptr<const char> key, size_t key_len, array_ptr<const char> data, size_t data_len) {
const auto& t_id = context.find_or_create_table(scope, context.receiver, table);
//FC_ASSERT(data_len >= KeyCount * sizeof(KeyType), "Data is not long enough to contain keys");
const KeyType keys((const char*)key, key_len); // = std::string(reinterpret_cast<const KeyType *>((const char *)data);
int call(ContextMethodType method, const scope_name& scope, const name& table, account_name bta,
null_terminated_ptr key, size_t key_len, array_ptr<const char> data, size_t data_len) {
const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
const KeyType keys((const char*)key.value, key_len);
const char* record_data = ((const char*)data); // + sizeof(KeyArrayType);
size_t record_len = data_len; // - sizeof(KeyArrayType);
return (context.*(method))(t_id, &keys, record_data, record_len);
const char* record_data = ((const char*)data);
size_t record_len = data_len;
return (context.*(method))(t_id, bta, &keys, record_data, record_len);
}
*/
public:
using context_aware_api::context_aware_api;
int store_str(const scope_name& scope, const name& table,
array_ptr<const char> &key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
auto res = call(&apply_context::store_record<keystr_value_object>, scope, table, key, key_len, data, data_len);
return res;
int store_str(const scope_name& scope, const name& table, const account_name& bta,
null_terminated_ptr key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
const KeyType keys(key.value, key_len);
const char* record_data = ((const char*)data);
size_t record_len = data_len;
return context.store_record<keystr_value_object>(t_id, bta, &keys, record_data, record_len);
//return call(&apply_context::store_record<keystr_value_object>, scope, table, bta, key, key_len, data, data_len);
}
int update_str(const scope_name& scope, const name& table,
array_ptr<const char> &key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
return call(&apply_context::update_record<keystr_value_object>, scope, table, key, key_len, data, data_len);
int update_str(const scope_name& scope, const name& table, const account_name& bta,
null_terminated_ptr key, uint32_t key_len, array_ptr<const char> data, size_t data_len) {
const auto& t_id = context.find_or_create_table(context.receiver, scope, table);
const KeyType keys((const char*)key, key_len);
const char* record_data = ((const char*)data);
size_t record_len = data_len;
return context.update_record<keystr_value_object>(t_id, bta, &keys, record_data, record_len);
//return call(&apply_context::update_record<keystr_value_object>, scope, table, bta, key, key_len, data, data_len);
}
int remove_str(const scope_name& scope, const name& table, array_ptr<const char> &key, uint32_t key_len) {
......@@ -916,7 +925,7 @@ class db_api<keystr_value_object> : public context_aware_api {
return context.remove_record<keystr_value_object>(t_id, k);
}
};
*/
template<typename IndexType, typename Scope>
class db_index_api : public context_aware_api {
using KeyType = typename IndexType::value_type::key_type;
......@@ -1538,14 +1547,12 @@ REGISTER_INTRINSICS(db_api_key_value_object, DB_METHOD_SEQ(i64));
REGISTER_INTRINSICS(db_api_key128x128_value_object, DB_METHOD_SEQ(i128i128));
REGISTER_INTRINSICS(db_api_key64x64_value_object, DB_METHOD_SEQ(i64i64));
REGISTER_INTRINSICS(db_api_key64x64x64_value_object, DB_METHOD_SEQ(i64i64i64));
/*
REGISTER_INTRINSICS(db_api_keystr_value_object,
(store_str, int32_t(int64_t, int64_t, int, int, int, int) )
(update_str, int32_t(int64_t, int64_t, int, int, int, int) )
(store_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
(update_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
(remove_str, int32_t(int64_t, int64_t, int, int) ));
*/
REGISTER_INTRINSICS(db_index_api_key_value_index_by_scope_primary, DB_INDEX_METHOD_SEQ(i64));
/*
REGISTER_INTRINSICS(db_index_api_keystr_value_index_by_scope_primary,
(load_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
(front_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
......@@ -1554,7 +1561,7 @@ REGISTER_INTRINSICS(db_index_api_keystr_value_index_by_scope_primary,
(previous_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
(lower_bound_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) )
(upper_bound_str, int32_t(int64_t, int64_t, int64_t, int, int, int, int) ));
*/
REGISTER_INTRINSICS(db_index_api_key128x128_value_index_by_scope_primary, DB_INDEX_METHOD_SEQ(primary_i128i128));
REGISTER_INTRINSICS(db_index_api_key128x128_value_index_by_scope_secondary, DB_INDEX_METHOD_SEQ(secondary_i128i128));
REGISTER_INTRINSICS(db_index_api_key64x64_value_index_by_scope_primary, DB_INDEX_METHOD_SEQ(primary_i64i64));
......
......@@ -29,8 +29,6 @@ namespace eosio { namespace testing {
open();
if (process_genesis)
push_genesis_block();
return;
}
void tester::push_genesis_block() {
......
......@@ -37,6 +37,7 @@
#include <test_api/test_api.wast.hpp>
#include <test_api_mem/test_api_mem.wast.hpp>
#include <test_api_db/test_api_db.wast.hpp>
#include <test_api/test_api.hpp>
FC_REFLECT( dummy_action, (a)(b)(c) );
......@@ -63,6 +64,20 @@ struct test_api_action {
FC_REFLECT_TEMPLATE((uint64_t T), test_api_action<T>, BOOST_PP_SEQ_NIL);
template<uint64_t NAME>
struct test_chain_action {
static account_name get_account() {
return account_name(config::system_account_name);
}
static action_name get_name() {
return action_name(NAME);
}
};
FC_REFLECT_TEMPLATE((uint64_t T), test_chain_action<T>, BOOST_PP_SEQ_NIL);
bool expect_assert_message(const fc::exception& ex, string expected) {
BOOST_TEST_MESSAGE("LOG : " << ex.get_log().at(0).get_message());
......@@ -388,7 +403,7 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
/*************************************************************************************
* checktime_tests test case
*************************************************************************************/
BOOST_FIXTURE_TEST_CASE(checktime_tests, tester) { try {
BOOST_FIXTURE_TEST_CASE(checktime_pass_tests, tester) { try {
produce_blocks(2);
create_account( N(testapi) );
produce_blocks(1000);
......@@ -398,11 +413,35 @@ BOOST_FIXTURE_TEST_CASE(checktime_tests, tester) { try {
// test checktime_pass
CALL_TEST_FUNCTION( *this, "test_checktime", "checktime_pass", {});
// test checktime_fail
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_checktime", "checktime_failure", {}), checktime_exceeded, is_checktime_exceeded);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(checktime_fail_tests) {
try {
tester t( {fc::milliseconds(1), fc::milliseconds(1)} );
t.produce_blocks(2);
t.create_account( N(testapi) );
t.set_code( N(testapi), test_api_wast );
auto call_test = [](tester& test, auto ac) {
signed_transaction trx;
auto pl = vector<permission_level>{{N(testapi), config::active_name}};
action act(pl, ac);
trx.actions.push_back(act);
test.set_tapos(trx);
auto sigs = trx.sign(test.get_private_key(N(testapi), "active"), chain_id_type());
trx.get_signature_keys(chain_id_type() );
auto res = test.push_transaction(trx);
BOOST_CHECK_EQUAL(res.status, transaction_receipt::executed);
test.produce_block();
};
BOOST_CHECK_EXCEPTION(call_test( t, test_api_action<TEST_METHOD("test_checktime", "checktime_failure")>{}), checktime_exceeded, is_checktime_exceeded);
} FC_LOG_AND_RETHROW();
}
/*************************************************************************************
* compiler_builtins_tests test case
*************************************************************************************/
......@@ -476,7 +515,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, tester) { try {
// test send_action_empty
CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_empty", {});
/* checktime exceeds before this can cause an overflow
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_large", {}), fc::assert_exception,
[](const fc::assert_exception& e) {
return expect_assert_message(e, "inline action too big");
......@@ -488,7 +526,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, tester) { try {
return expect_assert_message(e, "stack overflow");
}
);
*/
// test send_action_inline_fail
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION(*this, "test_transaction", "send_action_inline_fail", {}), fc::assert_exception,
......@@ -529,12 +566,27 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, tester) { try {
CALL_TEST_FUNCTION(*this, "test_transaction", "test_tapos_block_prefix", fc::raw::pack(control->head_block_id()._hash[1]) );
} FC_LOG_AND_RETHROW() }
template <uint64_t NAME>
struct setprod_act {
static account_name get_account() {
return N(config::system_account_name);
}
static action_name get_name() {
return action_name(NAME);
}
};
// Fixing this to create active producers
#if 0
/*************************************************************************************
* chain_tests test case
*************************************************************************************/
BOOST_FIXTURE_TEST_CASE(chain_tests, tester) { try {
produce_blocks(2);
create_account( N(inita) );
create_account( N(initb) );
create_account( N(initc) );
create_account( N(testapi) ); //, asset::from_string("100000.0000 EOS") );
create_account( N(acc1) ); //, asset::from_string("0.0000 EOS") );
produce_blocks(1000);
......@@ -546,27 +598,27 @@ BOOST_FIXTURE_TEST_CASE(chain_tests, tester) { try {
auto& gpo = control->get_global_properties();
std::vector<account_name> prods(gpo.active_producers.producers.size());
for ( int i=0; i < gpo.active_producers.producers.size(); i++ )
for ( int i=0; i < gpo.active_producers.producers.size(); i++ ) {
prods[i] = gpo.active_producers.producers[i].producer_name;
std::cout << "prods " << prods[i] << "\n";
}
CALL_TEST_FUNCTION( *this, "test_chain", "test_activeprods", fc::raw::pack(prods));
} FC_LOG_AND_RETHROW() }
#endif
// (Bucky) TODO got to fix macros in test_db.cpp
#if 0
/*************************************************************************************
* db_tests test case
*************************************************************************************/
BOOST_FIXTURE_TEST_CASE(db_tests, tester) { try {
produce_blocks(2);
create_account( N(testapi), asset::from_string("100000.0000 EOS") );
produce_blocks(1000);
transfer( N(inita), N(testapi), "100.0000 EOS", "memo" );
create_account( N(testapi) );
produce_blocks(1000);
set_code( N(testapi), test_api_db_wast );
produce_blocks(1);
CALL_TEST_FUNCTION( *this, "test_db", "key_str_general", {});
/*
CALL_TEST_FUNCTION( *this, "test_db", "key_i64_general", {});
CALL_TEST_FUNCTION( *this, "test_db", "key_i64_remove_all", {});
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_db", "key_i64_small_load", {}), fc::assert_exception,
......@@ -587,11 +639,8 @@ BOOST_FIXTURE_TEST_CASE(db_tests, tester) { try {
CALL_TEST_FUNCTION( *this, "test_db", "key_i64_front_back", {});
//CALL_TEST_FUNCTION( *this, "test_db", "key_i64i64i64_general", {});
CALL_TEST_FUNCTION( *this, "test_db", "key_i128i128_general", {});
return;
return;
*/
} FC_LOG_AND_RETHROW() }
#endif
/*************************************************************************************
* fixedpoint_tests test case
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册