Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
cb9878c6
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cb9878c6
编写于
2月 13, 2018
作者:
K
Khaled Al-Hassanieh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unit tests for index API's
上级
27b89b2d
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
650 addition
and
193 deletion
+650
-193
contracts/eosiolib/db.h
contracts/eosiolib/db.h
+40
-0
contracts/eosiolib/multi_index.hpp
contracts/eosiolib/multi_index.hpp
+4
-1
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+9
-1
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+7
-0
contracts/test_api/test_db.cpp
contracts/test_api/test_db.cpp
+493
-167
libraries/chain/include/eosio/chain/apply_context.hpp
libraries/chain/include/eosio/chain/apply_context.hpp
+1
-3
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+4
-21
tests/wasm_tests/wasm_tests.cpp
tests/wasm_tests/wasm_tests.cpp
+92
-0
未找到文件。
contracts/eosiolib/db.h
浏览文件 @
cb9878c6
...
...
@@ -1028,5 +1028,45 @@ int32_t store_i64i64i64( account_name scope, table_name table, account_name bta,
*/
int32_t
update_i64i64i64
(
account_name
scope
,
table_name
table
,
account_name
bta
,
const
void
*
data
,
uint32_t
len
);
int32_t
db_store_i64
(
account_name
scope
,
table_name
table
,
account_name
payer
,
uint64_t
id
,
const
void
*
data
,
uint32_t
len
);
void
db_update_i64
(
int32_t
iterator
,
account_name
payer
,
const
void
*
data
,
uint32_t
len
);
void
db_remove_i64
(
int32_t
iterator
);
int32_t
db_get_i64
(
int32_t
iterator
,
const
void
*
data
,
uint32_t
len
);
int32_t
db_next_i64
(
int32_t
iterator
,
uint64_t
*
primary
);
int32_t
db_previous_i64
(
int32_t
iterator
,
uint64_t
*
primary
);
int32_t
db_find_i64
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
id
);
int32_t
db_lowerbound_i64
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
id
);
int32_t
db_upperbound_i64
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
id
);
/*
void db_update_i64( int iterator, uint64_t payer, char* buffer, size_t buffer_size );
int db_find_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id );
int db_lowerbound_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id );
int db_get_i64( int iterator, char* buffer, size_t buffer_size );
void db_remove_i64( int iterator );
int db_next_i64( int iterator, uint64_t* pk );
int db_previous_i64( int iterator, uint64_t* pk );
*/
int32_t
db_idx64_store
(
account_name
scope
,
table_name
table
,
account_name
payer
,
uint64_t
id
,
const
uint64_t
*
secondary
);
void
db_idx64_update
(
int32_t
iterator
,
account_name
payer
,
const
uint64_t
*
secondary
);
void
db_idx64_remove
(
int32_t
iterator
);
int32_t
db_idx64_next
(
int32_t
iterator
,
uint64_t
*
primary
);
int32_t
db_idx64_previous
(
int32_t
iterator
,
uint64_t
*
primary
);
int32_t
db_idx64_find_primary
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
*
secondary
,
uint64_t
primary
);
int32_t
db_idx64_find_secondary
(
account_name
code
,
account_name
scope
,
table_name
table
,
const
uint64_t
*
secondary
,
uint64_t
*
primary
);
int32_t
db_idx64_lowerbound
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
*
secondary
,
uint64_t
*
primary
);
int32_t
db_idx64_upperbound
(
account_name
code
,
account_name
scope
,
table_name
table
,
uint64_t
*
secondary
,
uint64_t
*
primary
);
int
db_idx128_next
(
int
iterator
,
uint64_t
*
primary
);
int
db_idx128_prev
(
int
iterator
,
uint64_t
*
primary
);
int
db_idx128_find_primary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
*
secondary
,
uint64_t
primary
);
int
db_idx128_find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
*
secondary
,
uint64_t
*
primary
);
int
db_idx128_lowerbound
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
*
secondary
,
uint64_t
*
primary
);
int
db_idx128_upperbound
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
*
secondary
,
uint64_t
*
primary
);
void
db_idx128_remove
(
int
iterator
);
void
db_idx128_update
(
int
iterator
,
uint64_t
payer
,
const
uint128_t
*
secondary
);
///@} dbi64i64i64
}
contracts/eosiolib/multi_index.hpp
浏览文件 @
cb9878c6
...
...
@@ -11,9 +11,11 @@
#include <eosiolib/types.hpp>
#include <eosiolib/serialize.hpp>
#include <eosiolib/datastream.hpp>
#include <eosiolib/db.h>
extern
"C"
{
/*
int db_store_i64( uint64_t scope, uint64_t table, uint64_t payer, uint64_t id, char* buffer, size_t buffer_size );
void db_update_i64( int iterator, uint64_t payer, char* buffer, size_t buffer_size );
int db_find_i64( uint64_t code, uint64_t scope, uint64_t table, uint64_t id );
...
...
@@ -40,6 +42,7 @@ extern "C" {
int db_idx128_upperbound( uint64_t code, uint64_t scope, uint64_t table, uint128_t* secondary, uint64_t* primary );
void db_idx128_remove( int iterator );
void db_idx128_update( int iterator, uint64_t payer, const uint128_t* secondary );
*/
}
...
...
@@ -54,7 +57,7 @@ struct secondary_iterator;
template
<
>
struct
secondary_iterator
<
uint64_t
>
{
static
int
db_idx_next
(
int
iterator
,
uint64_t
*
primary
)
{
return
db_idx64_next
(
iterator
,
primary
);
}
static
int
db_idx_prev
(
int
iterator
,
uint64_t
*
primary
)
{
return
db_idx64_prev
(
iterator
,
primary
);
}
static
int
db_idx_prev
(
int
iterator
,
uint64_t
*
primary
)
{
return
db_idx64_prev
ious
(
iterator
,
primary
);
}
static
void
db_idx_remove
(
int
iterator
)
{
db_idx64_remove
(
iterator
);
}
};
...
...
contracts/test_api/test_api.cpp
浏览文件 @
cb9878c6
...
...
@@ -17,6 +17,7 @@
//#include "test_real.cpp"
//#include "test_transaction.cpp"
//#include "test_types.cpp"
#include "test_db.cpp"
extern
"C"
{
...
...
@@ -91,7 +92,14 @@ extern "C" {
// 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);
//
WASM_TEST_HANDLER
(
test_db
,
primary_i64_general
);
WASM_TEST_HANDLER
(
test_db
,
primary_i64_lowerbound
);
WASM_TEST_HANDLER
(
test_db
,
primary_i64_upperbound
);
WASM_TEST_HANDLER
(
test_db
,
idx64_general
);
WASM_TEST_HANDLER
(
test_db
,
idx64_lowerbound
);
WASM_TEST_HANDLER
(
test_db
,
idx64_upperbound
);
// //test crypto
// WASM_TEST_HANDLER(test_crypto, test_sha256);
// WASM_TEST_HANDLER(test_crypto, sha256_no_data);
...
...
contracts/test_api/test_api.hpp
浏览文件 @
cb9878c6
...
...
@@ -117,6 +117,13 @@ struct test_db {
static
unsigned
int
key_i64i64i64_under_limit
();
static
unsigned
int
key_i64i64i64_available_space_exceed_limit
();
static
unsigned
int
key_i64i64i64_another_under_limit
();
static
void
primary_i64_general
();
static
void
primary_i64_lowerbound
();
static
void
primary_i64_upperbound
();
static
void
idx64_general
();
static
void
idx64_lowerbound
();
static
void
idx64_upperbound
();
};
struct
test_crypto
{
...
...
contracts/test_api/test_db.cpp
浏览文件 @
cb9878c6
此差异已折叠。
点击以展开。
libraries/chain/include/eosio/chain/apply_context.hpp
浏览文件 @
cb9878c6
...
...
@@ -134,7 +134,7 @@ class apply_context {
});
}
int
find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
secondary_key_type
&
secondary
,
uint64_t
&
primary
)
{
int
find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
const
secondary_key_type
&
secondary
,
uint64_t
&
primary
)
{
auto
tab
=
context
.
find_table
(
context
.
receiver
,
scope
,
table
);
if
(
!
tab
)
return
-
1
;
...
...
@@ -142,7 +142,6 @@ class apply_context {
if
(
!
obj
)
return
-
1
;
primary
=
obj
->
primary_key
;
secondary
=
obj
->
secondary_key
;
itr_cache
.
cache_table
(
*
tab
);
return
itr_cache
.
add
(
*
obj
);
...
...
@@ -209,7 +208,6 @@ class apply_context {
primary
=
itr
->
primary_key
;
return
itr_cache
.
add
(
*
itr
);
}
int
find_primary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
secondary_key_type
&
secondary
,
uint64_t
primary
)
{
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
cb9878c6
...
...
@@ -715,7 +715,7 @@ class database_api : public context_aware_api {
return
context
.
db_lowerbound_i64
(
code
,
scope
,
table
,
id
);
}
int
db_upperbound_i64
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint64_t
id
)
{
return
context
.
db_
low
erbound_i64
(
code
,
scope
,
table
,
id
);
return
context
.
db_
upp
erbound_i64
(
code
,
scope
,
table
,
id
);
}
int
db_idx64_store
(
uint64_t
scope
,
uint64_t
table
,
uint64_t
payer
,
uint64_t
id
,
const
uint64_t
&
secondary
)
{
...
...
@@ -727,13 +727,12 @@ class database_api : public context_aware_api {
void
db_idx64_remove
(
int
iterator
)
{
return
context
.
idx64
.
remove
(
iterator
);
}
int
db_idx64_find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint64_t
&
secondary
,
uint64_t
&
primary
)
{
int
db_idx64_find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
const
uint64_t
&
secondary
,
uint64_t
&
primary
)
{
return
context
.
idx64
.
find_secondary
(
code
,
scope
,
table
,
secondary
,
primary
);
}
int
db_idx64_find_primary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint64_t
&
secondary
,
uint64_t
primary
)
{
return
context
.
idx64
.
find_
second
ary
(
code
,
scope
,
table
,
secondary
,
primary
);
return
context
.
idx64
.
find_
prim
ary
(
code
,
scope
,
table
,
secondary
,
primary
);
}
int
db_idx64_lowerbound
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint64_t
&
secondary
,
uint64_t
&
primary
)
{
return
context
.
idx64
.
lowerbound_secondary
(
code
,
scope
,
table
,
secondary
,
primary
);
}
...
...
@@ -747,22 +746,6 @@ class database_api : public context_aware_api {
return
context
.
idx64
.
previous_secondary
(
iterator
,
primary
);
}
/*
int db_idx64_next( int iterator, uint64_t& primary ) {
}
int db_idx64_prev( int iterator, uint64_t& primary ) {
}
int db_idx64_find_primary( uint64_t code, uint64_t scope, uint64_t table, uint64_t& secondary, uint64_t primary ) {
}
int db_idx64_find_secondary( uint64_t code, uint64_t scope, uint64_t table, uint64_t& secondary, uint64_t& primary ) {
}
int db_idx64_lowerbound( uint64_t code, uint64_t scope, uint64_t table, uint64_t& secondary, uint64_t& primary ) {
}
int db_idx64_upperbound( uint64_t code, uint64_t scope, uint64_t table, uint64_t& secondary, uint64_t& primary ) {
}
*/
int
db_idx128_store
(
uint64_t
scope
,
uint64_t
table
,
uint64_t
payer
,
uint64_t
id
,
const
uint128_t
&
secondary
)
{
return
context
.
idx128
.
store
(
scope
,
table
,
payer
,
id
,
secondary
);
}
...
...
@@ -775,7 +758,7 @@ class database_api : public context_aware_api {
int
db_idx128_find_primary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
&
secondary
,
uint64_t
primary
)
{
return
context
.
idx128
.
find_primary
(
code
,
scope
,
table
,
secondary
,
primary
);
}
int
db_idx128_find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
&
secondary
,
uint64_t
&
primary
)
{
int
db_idx128_find_secondary
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
const
uint128_t
&
secondary
,
uint64_t
&
primary
)
{
return
context
.
idx128
.
find_secondary
(
code
,
scope
,
table
,
secondary
,
primary
);
}
int
db_idx128_lowerbound
(
uint64_t
code
,
uint64_t
scope
,
uint64_t
table
,
uint128_t
&
secondary
,
uint64_t
&
primary
)
{
...
...
tests/wasm_tests/wasm_tests.cpp
浏览文件 @
cb9878c6
...
...
@@ -830,5 +830,97 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, tester ) try {
} FC_LOG_AND_RETHROW()
#endif
#if 1
BOOST_FIXTURE_TEST_CASE
(
test_db
,
tester
)
try
{
produce_blocks
(
2
);
create_accounts
(
{
N
(
tester
)}
);
produce_block
();
set_code
(
N
(
tester
),
test_api_wast
);
// set_code(N(tester), test_api_abi);
produce_blocks
(
1
);
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"primary_i64_general"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"primary_i64_lowerbound"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"primary_i64_upperbound"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"idx64_general"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"idx64_lowerbound"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
{
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
N
(
tester
),
config
::
active_name
}},
test_api_action
<
TEST_METHOD
(
"test_db"
,
"idx64_upperbound"
)
>
{});
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
tester
),
"active"
),
chain_id_type
());
push_transaction
(
trx
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
}
}
FC_LOG_AND_RETHROW
()
/// test_db
#endif
BOOST_AUTO_TEST_SUITE_END
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录