提交 3cf761c9 编写于 作者: B Bucky Kittinger

Still working on DB

上级 51327e58
......@@ -75,11 +75,11 @@ extern "C" {
WASM_TEST_HANDLER(test_crypto, assert_sha256_true);
//test transaction
WASM_TEST_HANDLER(test_transaction, send_message);
WASM_TEST_HANDLER(test_transaction, send_message_empty);
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_action);
WASM_TEST_HANDLER(test_transaction, send_action_empty);
WASM_TEST_HANDLER(test_transaction, send_action_large);
WASM_TEST_HANDLER(test_transaction, send_action_recurse);
WASM_TEST_HANDLER(test_transaction, send_action_inline_fail);
WASM_TEST_HANDLER(test_transaction, send_transaction);
WASM_TEST_HANDLER(test_transaction, send_transaction_empty);
WASM_TEST_HANDLER(test_transaction, send_transaction_large);
......
......@@ -273,7 +273,6 @@ void test_db::key_str_general() {
void test_db::key_i64_general() {
uint32_t res = 0;
test_model alice{ N(alice), 20, 4234622};
test_model bob { N(bob), 15, 11932435};
test_model carol{ N(carol), 30, 545342453};
......@@ -304,12 +303,6 @@ void test_db::key_i64_general() {
test_model tmp;
res = front_i64( current_receiver(), current_receiver(), N(test_table), &tmp, sizeof(test_model) );
prints("size ");
printi(res);
prints("\n");
printi(sizeof(test_model));
prints("\n");
assert(res == sizeof(test_model) && tmp.name == N(alice) && tmp.age == 20 && tmp.phone == 4234622, "front_i64 1");
my_memset(&tmp, 0, sizeof(test_model));
......@@ -326,7 +319,7 @@ void test_db::key_i64_general() {
assert(res == sizeof(test_model) && tmp.name == N(alice) && tmp.age == 20 && tmp.phone == 4234622, "alice previous");
res = previous_i64( current_receiver(), current_receiver(), N(test_table), &tmp, sizeof(test_model) );
assert(res == -1, "previous null");
assert(res == 0, "previous null");
res = next_i64( current_receiver(), current_receiver(), N(test_table), &tmp, sizeof(test_model) );
assert(res == sizeof(test_model) && tmp.name == N(bob) && tmp.age == 15 && tmp.phone == 11932435, "bob next");
......@@ -338,7 +331,7 @@ void test_db::key_i64_general() {
assert(res == sizeof(test_model) && tmp.name == N(dave) && tmp.age == 46 && tmp.phone == 6535354, "dave next");
res = next_i64( current_receiver(), current_receiver(), N(test_table), &tmp, sizeof(test_model) );
assert(res == -1, "next null");
assert(res == 0, "next null");
my_memset(&alice, 0, sizeof(test_model));
......@@ -380,10 +373,14 @@ void test_db::key_i64_general() {
assert(res == sizeof(test_model) && dave.age == 46 && dave.phone == 6535354, "dave error 1");
res = load_i64(current_receiver(), N(other_code), N(test_table), &alice, sizeof(test_model));
assert(res == -1, "other_code");
prints("other ");
printi(res);
prints("\n");
return;
assert(res == 0, "other_code");
res = load_i64(current_receiver(), current_receiver(), N(other_table), &alice, sizeof(test_model));
assert(res == -1, "other_table");
assert(res == 0, "other_table");
test_model_v2 alicev2;
......
......@@ -7,6 +7,7 @@
#include <eosio/chain/contracts/contract_table_objects.hpp>
#include <fc/utility.hpp>
#include <sstream>
#include <iostream>
namespace chainbase { class database; }
......@@ -396,6 +397,7 @@ using apply_handler = std::function<void(apply_context&)>;
const auto* obj = db.find<ObjectType, contracts::by_scope_primary>(tuple);
if( obj ) {
auto prev_size = obj->value.size();
mutable_db.modify( *obj, [&]( auto& o ) {
o.value.assign(value, valuelen);
});
......@@ -469,10 +471,10 @@ 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 -1;
!impl::record_scope_compare<IndexType, Scope>::compare(*itr, keys)) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
std::cout << "WHY!" << "\n";
if (valuelen) {
auto copylen = std::min<size_t>(itr->value.size(), valuelen);
if (copylen) {
......@@ -493,7 +495,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 -1;
itr->t_id != t_id.id ) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......@@ -517,11 +519,11 @@ using apply_handler = std::function<void(apply_context&)>;
auto tuple = boost::make_tuple( next_tid );
auto itr = idx.lower_bound(tuple);
if( std::distance(idx.begin(), itr) == 0 ) return -1;
if( std::distance(idx.begin(), itr) == 0 ) return 0;
--itr;
if( itr->t_id != t_id.id ) return -1;
if( itr->t_id != t_id.id ) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......@@ -546,7 +548,7 @@ using apply_handler = std::function<void(apply_context&)>;
auto pitr = pidx.find(tuple);
if(pitr == pidx.end())
return -1;
return 0;
const auto& fidx = db.get_index<IndexType>();
auto itr = fidx.indicies().template project<Scope>(pitr);
......@@ -556,14 +558,14 @@ using apply_handler = std::function<void(apply_context&)>;
if( itr == idx.end() ||
itr->t_id != t_id.id ||
!impl::key_helper<typename IndexType::value_type>::compare(*itr, keys) ) {
return -1;
return 0;
}
++itr;
if( itr == idx.end() ||
itr->t_id != t_id.id ) {
return -1;
return 0;
}
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......@@ -589,7 +591,7 @@ using apply_handler = std::function<void(apply_context&)>;
auto pitr = pidx.find(tuple);
if(pitr == pidx.end())
return -1;
return 0;
const auto& fidx = db.get_index<IndexType>();
auto itr = fidx.indicies().template project<Scope>(pitr);
......@@ -599,11 +601,11 @@ using apply_handler = std::function<void(apply_context&)>;
if( itr == idx.end() ||
itr == idx.begin() ||
itr->t_id != t_id.id ||
!impl::key_helper<typename IndexType::value_type>::compare(*itr, keys) ) return -1;
!impl::key_helper<typename IndexType::value_type>::compare(*itr, keys) ) return 0;
--itr;
if( itr->t_id != t_id.id ) return -1;
if( itr->t_id != t_id.id ) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......@@ -627,7 +629,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 -1;
itr->t_id != t_id.id) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......@@ -651,7 +653,7 @@ using apply_handler = std::function<void(apply_context&)>;
auto itr = idx.upper_bound(tuple);
if( itr == idx.end() ||
itr->t_id != t_id.id ) return -1;
itr->t_id != t_id.id ) return 0;
impl::key_helper<typename IndexType::value_type>::get(keys, *itr);
......
......@@ -751,12 +751,7 @@ class db_api : public context_aware_api {
const char* record_data = ((const char*)data) + sizeof(KeyArrayType);
size_t record_len = data_len - sizeof(KeyArrayType);
size_t ret = (context.*(method))(t_id, keys, record_data, record_len) + sizeof(KeyArrayType);
std::cout << "size " << ret << "\n";
std::cout << "key size " << sizeof(KeyArrayType) << "\n";
std::cout << "data size " << data_len << "\n";
std::cout << "record size " << record_len << "\n";
return ret;
return (context.*(method))(t_id, keys, record_data, record_len);
}
public:
......@@ -764,7 +759,6 @@ class db_api : public context_aware_api {
int store(const scope_name& scope, const name& table, array_ptr<const char> data, size_t data_len) {
auto res = call(&apply_context::store_record<ObjectType>, scope, table, data, data_len);
//ilog("STORE [${scope},${code},${table}] => ${res} :: ${HEX}", ("scope",scope)("code",context.receiver)("table",table)("res",res)("HEX", fc::to_hex(data, data_len)));
return res;
}
......@@ -795,7 +789,7 @@ class db_api<keystr_value_object> : public context_aware_api {
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); // + sizeof(KeyArrayType);
return (context.*(method))(t_id, &keys, record_data, record_len);
}
public:
......@@ -841,7 +835,7 @@ class db_index_api : public context_aware_api {
char* record_data = ((char*)data) + sizeof(KeyArrayType);
size_t record_len = data_len - sizeof(KeyArrayType);
return (context.*(method))(t_id, keys, record_data, record_len); // + sizeof(KeyArrayType);
return (context.*(method))(t_id, keys, record_data, record_len);
}
public:
......@@ -849,32 +843,38 @@ class db_index_api : public context_aware_api {
int load(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
auto res = call(&apply_context::load_record<IndexType, Scope>, scope, code, table, data, data_len);
//ilog("LOAD [${scope},${code},${table}] => ${res} :: ${HEX}", ("scope",scope)("code",code)("table",table)("res",res)("HEX", fc::to_hex(data, data_len)));
return res;
std::cout << "res " << res << "\n";
return (res == 0) ? 0 : res + sizeof(KeyArrayType);
}
int front(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::front_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::front_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
int back(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::back_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::back_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
int next(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::next_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::next_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
int previous(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::previous_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::previous_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
int lower_bound(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::lower_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::lower_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
int upper_bound(const scope_name& scope, const account_name& code, const name& table, array_ptr<char> data, size_t data_len) {
return call(&apply_context::upper_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
auto res = call(&apply_context::upper_bound_record<IndexType, Scope>, scope, code, table, data, data_len);
return (res > 0) ? res + sizeof(KeyArrayType) : 0;
}
};
......
......@@ -174,6 +174,7 @@ namespace eosio { namespace testing {
Module module;
vector<Error> parse_errors;
// TODO const_strlen(wast) blows the stack frame on debug build
parseModule(wast, fc::const_strlen(wast), module, parse_errors);
if (!parse_errors.empty()) {
fc::exception parse_exception(
......
......@@ -317,7 +317,6 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
}
);
CALL_TEST_FUNCTION( *this, "test_action", "require_notice", raw_bytes );
auto scope = std::vector<account_name>{N(testapi)};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册