Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
51327e58
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,发现更多精彩内容 >>
提交
51327e58
编写于
1月 24, 2018
作者:
B
Bucky Kittinger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rebasing to eos-noon
上级
6f865078
变更
33
展开全部
隐藏空白更改
内联
并排
Showing
33 changed file
with
2147 addition
and
367 deletion
+2147
-367
CMakeLists.txt
CMakeLists.txt
+4
-0
CMakeModules/wasm.cmake
CMakeModules/wasm.cmake
+1
-1
build.sh
build.sh
+1
-1
contracts/CMakeLists.txt
contracts/CMakeLists.txt
+1
-0
contracts/asserter/asserter.hpp
contracts/asserter/asserter.hpp
+1
-1
contracts/eoslib/account.h
contracts/eoslib/account.h
+1
-1
contracts/eoslib/account.hpp
contracts/eoslib/account.hpp
+2
-1
contracts/eoslib/db.h
contracts/eoslib/db.h
+2
-2
contracts/eoslib/db.hpp
contracts/eoslib/db.hpp
+8
-8
contracts/eoslib/eos.hpp
contracts/eoslib/eos.hpp
+0
-4
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+60
-56
contracts/test_api/test_chain.cpp
contracts/test_api/test_chain.cpp
+1
-3
contracts/test_api/test_compiler_builtins.cpp
contracts/test_api/test_compiler_builtins.cpp
+1
-1
contracts/test_api/test_crypto.cpp
contracts/test_api/test_crypto.cpp
+10
-19
contracts/test_api/test_db.cpp
contracts/test_api/test_db.cpp
+1
-0
contracts/test_api/test_fixedpoint.cpp
contracts/test_api/test_fixedpoint.cpp
+19
-16
contracts/test_api/test_math.cpp
contracts/test_api/test_math.cpp
+46
-3
contracts/test_api/test_real.cpp
contracts/test_api/test_real.cpp
+12
-9
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+17
-51
contracts/test_api/test_types.cpp
contracts/test_api/test_types.cpp
+4
-12
contracts/test_api_db/CMakeLists.txt
contracts/test_api_db/CMakeLists.txt
+1
-0
contracts/test_api_db/test_api_db.cpp
contracts/test_api_db/test_api_db.cpp
+58
-0
contracts/test_api_db/test_db.cpp
contracts/test_api_db/test_db.cpp
+59
-78
contracts/test_api_mem/test_api_mem.cpp
contracts/test_api_mem/test_api_mem.cpp
+0
-37
contracts/test_api_mem/test_db.cpp.bak
contracts/test_api_mem/test_db.cpp.bak
+1504
-0
contracts/test_api_mem/test_memory.cpp
contracts/test_api_mem/test_memory.cpp
+1
-1
libraries/chain/include/eosio/chain/apply_context.hpp
libraries/chain/include/eosio/chain/apply_context.hpp
+21
-5
libraries/chain/include/eosio/chain/contracts/contract_table_objects.hpp
.../include/eosio/chain/contracts/contract_table_objects.hpp
+1
-1
libraries/chain/include/eosio/chain/wasm_interface_private.hpp
...ries/chain/include/eosio/chain/wasm_interface_private.hpp
+4
-0
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+127
-7
libraries/wasm-jit/Source/Platform/POSIX.cpp
libraries/wasm-jit/Source/Platform/POSIX.cpp
+1
-0
scripts/install_dependencies.sh
scripts/install_dependencies.sh
+4
-2
tests/api_tests/api_tests.cpp
tests/api_tests/api_tests.cpp
+174
-47
未找到文件。
CMakeLists.txt
浏览文件 @
51327e58
...
...
@@ -30,6 +30,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif
()
endif
()
if
(
"
${
CMAKE_BUILD_TYPE
}
"
STREQUAL
"Debug"
)
add_definitions
(
-D_DEBUG
)
endif
()
list
(
APPEND CMAKE_MODULE_PATH
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/CMakeModules"
)
set
(
CMAKE_EXPORT_COMPILE_COMMANDS
"ON"
)
...
...
CMakeModules/wasm.cmake
浏览文件 @
51327e58
...
...
@@ -91,7 +91,7 @@ macro(add_wast_target target INCLUDE_FOLDERS DESTINATION_FOLDER)
add_custom_command
(
OUTPUT
${
outfile
}
.bc
DEPENDS
${
infile
}
COMMAND
${
WASM_CLANG
}
-emit-llvm -O0 --std=c++14 --target=wasm32 -ffreestanding
COMMAND
${
WASM_CLANG
}
-emit-llvm -O0 --std=c++14 --target=wasm32 -ffreestanding
-nostdlib -fno-threadsafe-statics -fno-rtti -fno-exceptions -I
${
INCLUDE_FOLDERS
}
-c
${
infile
}
-o
${
outfile
}
.bc
IMPLICIT_DEPENDS CXX
${
infile
}
...
...
build.sh
浏览文件 @
51327e58
...
...
@@ -38,7 +38,7 @@ if [[ $ARCH =~ [[:space:]] || ! $TARGET_ARCHS =~ (^|[[:space:]])$ARCH([[:space:]
exit
1
fi
if
[
-z
"
$2
"
]
;
then
if
[
[
-z
"
$2
"
]
]
;
then
INSTALL_DEPS
=
1
else
if
[
"
$2
"
==
"full"
]
;
then
...
...
contracts/CMakeLists.txt
浏览文件 @
51327e58
...
...
@@ -5,6 +5,7 @@ add_subdirectory(exchange)
add_subdirectory
(
infinite
)
add_subdirectory
(
proxy
)
add_subdirectory
(
test_api
)
add_subdirectory
(
test_api_db
)
add_subdirectory
(
test_api_mem
)
add_subdirectory
(
simpledb
)
add_subdirectory
(
storage
)
...
...
contracts/asserter/asserter.hpp
浏览文件 @
51327e58
...
...
@@ -11,4 +11,4 @@ namespace asserter {
int8_t
message_length
;
char
message
[];
};
}
\ No newline at end of file
}
contracts/eoslib/account.h
浏览文件 @
51327e58
...
...
@@ -41,6 +41,6 @@ extern "C" {
*
*/
bool
account_balance_get
(
void
*
balance
,
uint32_t
len
);
bool
get_account_balance
(
void
*
balance
,
uint32_t
len
);
///@ } accountcapi
}
contracts/eoslib/account.hpp
浏览文件 @
51327e58
...
...
@@ -74,7 +74,8 @@ struct PACKED(account_balance) {
bool
get
(
account_balance
&
b
)
{
return
account_balance_get
(
&
b
,
sizeof
(
account_balance
));
// return account_balance_get(&b, sizeof(account_balance));
}
/// @} eosio
...
...
contracts/eoslib/db.h
浏览文件 @
51327e58
...
...
@@ -310,7 +310,7 @@ int32_t remove_i64( account_name scope, table_name table, void* data );
* @param valuelen - maximum length of the record value to read
* @return the number of bytes read or -1 if key was not found
*/
int32_t
front_str
(
account_name
scope
,
account_name
code
,
table_name
table
,
char
*
value
,
uint32_t
valuelen
);
int32_t
front_str
(
account_name
scope
,
account_name
code
,
table_name
table
,
char
*
key
,
uint32_t
keylen
,
char
*
value
,
uint32_t
valuelen
);
/**
* @param scope - the account scope that will be read, must exist in the transaction scopes list
...
...
@@ -322,7 +322,7 @@ int32_t remove_i64( account_name scope, table_name table, void* data );
* @param valuelen - maximum length of the record value to read
* @return the number of bytes read or -1 if key was not found
*/
int32_t
back_str
(
account_name
scope
,
account_name
code
,
table_name
table
,
char
*
value
,
uint32_t
valuelen
);
int32_t
back_str
(
account_name
scope
,
account_name
code
,
table_name
table
,
char
*
key
,
uint32_t
keylen
,
char
*
value
,
uint32_t
valuelen
);
/**
* @param scope - the account scope that will be read, must exist in the transaction scopes list
...
...
contracts/eoslib/db.hpp
浏览文件 @
51327e58
...
...
@@ -705,12 +705,12 @@ struct table_impl_obj<char*> {
return
update_str
(
scope
,
table_n
,
key
,
keylen
,
data
,
datalen
);
}
static
int32_t
front
(
account_name
scope
,
account_name
code
,
table_name
table_n
,
char
*
data
,
uint32_t
len
)
{
return
front_str
(
scope
,
code
,
table_n
,
data
,
len
);
static
int32_t
front
(
account_name
scope
,
account_name
code
,
table_name
table_n
,
char
*
key
,
uint32_t
keylen
,
char
*
data
,
uint32_t
len
)
{
return
front_str
(
scope
,
code
,
table_n
,
key
,
keylen
,
data
,
len
);
}
static
int32_t
back
(
account_name
scope
,
account_name
code
,
table_name
table_n
,
char
*
data
,
uint32_t
len
)
{
return
back_str
(
scope
,
code
,
table_n
,
data
,
len
);
static
int32_t
back
(
account_name
scope
,
account_name
code
,
table_name
table_n
,
char
*
key
,
uint32_t
keylen
,
char
*
data
,
uint32_t
len
)
{
return
back_str
(
scope
,
code
,
table_n
,
key
,
keylen
,
data
,
len
);
}
static
int32_t
load
(
account_name
scope
,
account_name
code
,
table_name
table_n
,
char
*
key
,
uint32_t
keylen
,
char
*
data
,
uint32_t
datalen
)
{
...
...
@@ -794,8 +794,8 @@ struct var_table {
* @param len - length of data to be updated
* @return the number of bytes read or -1 if key was not found
*/
int32_t
front
(
char
*
record
,
uint32_t
len
)
{
return
impl
::
front
(
scope
,
code
,
table_n
,
record
,
len
);
int32_t
front
(
primary
key
,
uint32_t
keylen
,
char
*
record
,
uint32_t
len
)
{
return
impl
::
front
(
scope
,
code
,
table_n
,
key
,
keylen
,
record
,
len
);
}
/**
...
...
@@ -807,8 +807,8 @@ struct var_table {
* @param len - length of data to be updated
* @return the number of bytes read or -1 if key was not found
*/
int32_t
back
(
char
*
record
,
uint32_t
len
)
{
return
impl
::
back
(
scope
,
code
,
table_n
,
record
,
len
);
int32_t
back
(
primary
key
,
uint32_t
keylen
,
char
*
record
,
uint32_t
len
)
{
return
impl
::
back
(
scope
,
code
,
table_n
,
key
,
keylen
,
record
,
len
);
}
/**
...
...
contracts/eoslib/eos.hpp
浏览文件 @
51327e58
...
...
@@ -7,7 +7,3 @@
#include <eoslib/action.hpp>
#include <eoslib/print.hpp>
#include <eoslib/math.hpp>
contracts/test_api/test_api.hpp
浏览文件 @
51327e58
...
...
@@ -41,10 +41,10 @@ static_assert( sizeof(dummy_action) == 13 , "unexpected packing" );
static_assert
(
sizeof
(
u128_action
)
==
16
*
3
,
"unexpected packing"
);
struct
test_types
{
static
unsigned
int
types_size
();
static
unsigned
int
char_to_symbol
();
static
unsigned
int
string_to_name
();
static
unsigned
int
name_class
();
static
void
types_size
();
static
void
char_to_symbol
();
static
void
string_to_name
();
static
void
name_class
();
};
struct
test_print
{
...
...
@@ -77,54 +77,56 @@ struct test_math {
static
void
test_diveq_by_0
();
static
void
test_double_api
();
static
void
test_double_api_div_0
();
static
void
test_i64_to_double
();
static
void
test_double_to_i64
();
};
struct
test_db
{
static
unsigned
int
key_i64_general
();
static
unsigned
int
key_i64_remove_all
();
static
unsigned
int
key_i64_small_load
();
static
unsigned
int
key_i64_small_store
();
static
unsigned
int
key_i64_store_scope
();
static
unsigned
int
key_i64_remove_scope
();
static
unsigned
int
key_i64_not_found
();
static
unsigned
int
key_i64_front_back
();
static
unsigned
int
key_i128i128_general
();
static
unsigned
int
key_i64i64i64_general
();
static
unsigned
int
key_str_general
();
static
unsigned
int
key_str_table
();
static
unsigned
int
key_str_setup_limit
();
static
unsigned
int
key_str_min_exceed_limit
();
static
unsigned
int
key_str_under_limit
();
static
unsigned
int
key_str_available_space_exceed_limit
();
static
unsigned
int
key_str_another_under_limit
();
static
unsigned
int
key_i64_setup_limit
();
static
unsigned
int
key_i64_min_exceed_limit
();
static
unsigned
int
key_i64_under_limit
();
static
unsigned
int
key_i64_available_space_exceed_limit
();
static
unsigned
int
key_i64_another_under_limit
();
static
unsigned
int
key_i128i128_setup_limit
();
static
unsigned
int
key_i128i128_min_exceed_limit
();
static
unsigned
int
key_i128i128_under_limit
();
static
unsigned
int
key_i128i128_available_space_exceed_limit
();
static
unsigned
int
key_i128i128_another_under_limit
();
static
unsigned
int
key_i64i64i64_setup_limit
();
static
unsigned
int
key_i64i64i64_min_exceed_limit
();
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
key_i64_general
();
static
void
key_i64_remove_all
();
static
void
key_i64_small_load
();
static
void
key_i64_small_store
();
static
void
key_i64_store_scope
();
static
void
key_i64_remove_scope
();
static
void
key_i64_not_found
();
static
void
key_i64_front_back
();
static
void
key_i128i128_general
();
static
void
key_i64i64i64_general
();
static
void
key_str_general
();
static
void
key_str_table
();
static
void
key_str_setup_limit
();
static
void
key_str_min_exceed_limit
();
static
void
key_str_under_limit
();
static
void
key_str_available_space_exceed_limit
();
static
void
key_str_another_under_limit
();
static
void
key_i64_setup_limit
();
static
void
key_i64_min_exceed_limit
();
static
void
key_i64_under_limit
();
static
void
key_i64_available_space_exceed_limit
();
static
void
key_i64_another_under_limit
();
static
void
key_i128i128_setup_limit
();
static
void
key_i128i128_min_exceed_limit
();
static
void
key_i128i128_under_limit
();
static
void
key_i128i128_available_space_exceed_limit
();
static
void
key_i128i128_another_under_limit
();
static
void
key_i64i64i64_setup_limit
();
static
void
key_i64i64i64_min_exceed_limit
();
static
void
key_i64i64i64_under_limit
();
static
void
key_i64i64i64_available_space_exceed_limit
();
static
void
key_i64i64i64_another_under_limit
();
};
struct
test_crypto
{
static
unsigned
int
test_sha256
();
static
unsigned
int
sha256_no_data
();
static
unsigned
int
asert_sha256_false
();
static
unsigned
int
asert_sha256_tru
e
();
static
unsigned
int
asert_no_data
();
static
void
test_sha256
();
static
void
sha256_no_data
();
static
void
sha256_null
();
static
void
assert_sha256_fals
e
();
static
void
assert_sha256_true
();
};
struct
test_transaction
{
...
...
@@ -142,7 +144,7 @@ struct test_transaction {
};
struct
test_chain
{
static
unsigned
int
test_activeprods
();
static
void
test_activeprods
();
};
struct
test_string
{
...
...
@@ -169,18 +171,20 @@ struct test_string {
};
struct
test_fixedpoint
{
static
unsigned
int
create_instances
();
static
unsigned
int
test_addition
();
static
unsigned
int
test_subtraction
();
static
unsigned
int
test_multiplication
();
static
unsigned
int
test_division
();
static
void
create_instances
();
static
void
test_addition
();
static
void
test_subtraction
();
static
void
test_multiplication
();
static
void
test_division
();
static
void
test_division_by_0
();
};
struct
test_real
{
static
unsigned
int
create_instances
();
static
unsigned
int
test_addition
();
static
unsigned
int
test_multiplication
();
static
unsigned
int
test_division
();
static
void
create_instances
();
static
void
test_addition
();
static
void
test_multiplication
();
static
void
test_division
();
static
void
test_division_by_0
();
};
struct
test_compiler_builtins
{
...
...
contracts/test_api/test_chain.cpp
浏览文件 @
51327e58
...
...
@@ -14,7 +14,7 @@ struct producers {
};
#pragma pack(pop)
unsigned
int
test_chain
::
test_activeprods
()
{
void
test_chain
::
test_activeprods
()
{
producers
act_prods
;
read_action
(
&
act_prods
,
sizeof
(
producers
));
...
...
@@ -26,6 +26,4 @@ unsigned int test_chain::test_activeprods() {
for
(
int
i
=
0
;
i
<
21
;
++
i
)
{
assert
(
api_prods
.
producers
[
i
]
==
act_prods
.
producers
[
i
],
"Active producer"
);
}
return
0
;
}
contracts/test_api/test_compiler_builtins.cpp
浏览文件 @
51327e58
...
...
@@ -99,7 +99,7 @@ void test_compiler_builtins::test_divti3_by_0() {
__int128
res
=
0
;
__divti3
(
res
,
100
,
0
,
0
,
0
);
assert
(
false
,
"Should have
thrown divide by zero
"
);
assert
(
false
,
"Should have
asserted
"
);
}
void
test_compiler_builtins
::
test_lshlti3
()
{
...
...
contracts/test_api/test_crypto.cpp
浏览文件 @
51327e58
...
...
@@ -69,7 +69,7 @@ extern "C" {
}
unsigned
int
test_crypto
::
test_sha256
()
{
void
test_crypto
::
test_sha256
()
{
checksum
tmp
;
...
...
@@ -84,21 +84,23 @@ unsigned int test_crypto::test_sha256() {
sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
assert
(
my_memcmp
((
void
*
)
test5_ok
,
&
tmp
,
sizeof
(
checksum
)),
"sha256 test5"
);
}
return
0
;
void
test_crypto
::
sha256_null
()
{
checksum
tmp
;
sha256
(
nullptr
,
100
,
&
tmp
);
assert
(
false
,
"should've thrown an error"
);
}
unsigned
int
test_crypto
::
sha256_no_data
()
{
void
test_crypto
::
sha256_no_data
()
{
checksum
tmp
;
sha256
(
(
char
*
)
test2
,
my_strlen
(
test2
),
&
tmp
);
assert
(
my_memcmp
((
void
*
)
test2_ok
,
&
tmp
,
sizeof
(
checksum
)),
"sha256 test2"
);
return
0
;
}
unsigned
int
test_crypto
::
a
sert_sha256_false
()
{
void
test_crypto
::
as
sert_sha256_false
()
{
checksum
tmp
;
...
...
@@ -106,11 +108,10 @@ unsigned int test_crypto::asert_sha256_false() {
tmp
.
hash
[
0
]
^=
(
uint64_t
)(
-
1
);
assert_sha256
(
(
char
*
)
test1
,
my_strlen
(
test1
),
&
tmp
);
assert
(
false
,
"sha256 failed"
);
return
WASM_TEST_FAIL
;
assert
(
false
,
"should have failed"
);
}
unsigned
int
test_crypto
::
a
sert_sha256_true
()
{
void
test_crypto
::
as
sert_sha256_true
()
{
checksum
tmp
;
...
...
@@ -125,14 +126,4 @@ unsigned int test_crypto::asert_sha256_true() {
sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
assert_sha256
(
(
char
*
)
test5
,
my_strlen
(
test5
),
&
tmp
);
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
;
}
contracts/test_api/test_db.cpp
浏览文件 @
51327e58
...
...
@@ -291,6 +291,7 @@ unsigned int test_db::key_i64_general() {
test_model
tmp
;
//__breakpoint();
res
=
front_i64
(
current_receiver
(),
current_receiver
(),
N
(
test_table
),
&
tmp
,
sizeof
(
test_model
)
);
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
));
...
...
contracts/test_api/test_fixedpoint.cpp
浏览文件 @
51327e58
...
...
@@ -3,7 +3,7 @@
#include "test_api.hpp"
using
namespace
eosio
;
unsigned
int
test_fixedpoint
::
create_instances
()
void
test_fixedpoint
::
create_instances
()
{
{
// Various ways to create fixed_point128
...
...
@@ -31,12 +31,9 @@ unsigned int test_fixedpoint::create_instances()
assert
(
b
==
a
,
"fixed_point32 instances comparison with same number of decimals"
);
assert
(
c
==
a
,
"fixed_point32 instances with different number of decimals"
);
}
return
0
;
}
unsigned
int
test_fixedpoint
::
test_addition
()
void
test_fixedpoint
::
test_addition
()
{
{
// Various ways to create fixed_point32
...
...
@@ -54,11 +51,9 @@ unsigned int test_fixedpoint::test_addition()
fixed_point64
<
0
>
d
=
200
;
assert
(
c
==
d
,
"fixed_point64 instances addition with zero decmimals"
);
}
return
0
;
};
unsigned
int
test_fixedpoint
::
test_subtraction
()
void
test_fixedpoint
::
test_subtraction
()
{
{
// Various ways to create fixed_point64
...
...
@@ -76,11 +71,9 @@ unsigned int test_fixedpoint::test_subtraction()
fixed_point32
<
0
>
d
=
0
;
assert
(
c
==
d
,
"fixed_point32 instances subtraction with zero decmimals"
);
}
return
0
;
};
unsigned
int
test_fixedpoint
::
test_multiplication
()
void
test_fixedpoint
::
test_multiplication
()
{
{
// Various ways to create fixed_point64
...
...
@@ -99,11 +92,9 @@ unsigned int test_fixedpoint::test_multiplication()
fixed_point64
<
0
>
d
(
200
*
100
);
assert
(
c
==
d
,
"fixed_point32 instances multiplication result in fixed_point64"
);
}
return
0
;
}
unsigned
int
test_fixedpoint
::
test_division
()
void
test_fixedpoint
::
test_division
()
{
{
uint64_t
lhs
=
10000000
;
...
...
@@ -130,8 +121,20 @@ unsigned int test_fixedpoint::test_division()
assert
(
c
==
e
,
"fixed_point64 instances division result from operator and function and compare in fixed_point128"
);
}
return
0
;
}
void
test_fixedpoint
::
test_division_by_0
()
{
{
uint64_t
lhs
=
10000000
;
uint64_t
rhs
=
0
;
fixed_point64
<
0
>
a
(
lhs
);
fixed_point64
<
0
>
b
(
rhs
);
fixed_point128
<
5
>
e
=
fixed_divide
<
5
>
(
lhs
,
rhs
);
assert
(
false
,
"should've thrown an error"
);
}
}
contracts/test_api/test_math.cpp
浏览文件 @
51327e58
...
...
@@ -35,6 +35,47 @@ void test_math::test_diveq_by_0() {
}
void
test_math
::
test_i64_to_double
()
{
uint64_t
i
[
4
];
read_action
(
&
i
,
sizeof
(
i
));
uint64_t
d
=
i64_to_double
(
2
);
assert
(
i
[
0
]
==
d
,
"test_i64_to_double i[0] == d"
);
d
=
i64_to_double
(
-
2
);
assert
(
i
[
1
]
==
d
,
"test_i64_to_double i[1] == d"
);
d
=
i64_to_double
(
100000
);
assert
(
i
[
2
]
==
d
,
"test_i64_to_double i[2] == d"
);
d
=
i64_to_double
(
-
100000
);
assert
(
i
[
3
]
==
d
,
"test_i64_to_double i[3] == d"
);
d
=
i64_to_double
(
0
);
assert
(
0
==
d
,
"test_i64_to_double 0 == d"
);
}
void
test_math
::
test_double_to_i64
()
{
uint64_t
d
[
4
];
read_action
(
&
d
,
sizeof
(
d
));
int64_t
i
=
double_to_i64
(
d
[
0
]);
assert
(
2
==
i
,
"test_double_to_i64 2 == i"
);
i
=
double_to_i64
(
d
[
1
]);
assert
(
-
2
==
i
,
"test_double_to_i64 -2 == i"
);
i
=
double_to_i64
(
d
[
2
]);
assert
(
100000
==
i
,
"test_double_to_i64 100000 == i"
);
i
=
double_to_i64
(
d
[
3
]);
assert
(
-
100000
==
i
,
"test_double_to_i64 -100000 == i"
);
i
=
double_to_i64
(
0
);
assert
(
0
==
i
,
"test_double_to_i64 0 == i"
);
}
void
test_math
::
test_double_api
()
{
...
...
@@ -68,8 +109,10 @@ void test_math::test_double_api() {
}
void
test_math
::
test_double_api_div_0
()
{
// double_div( i64_to_double(1), i64_to_double(0));
double_add
(
double_div
(
i64_to_double
(
1
),
double_add
(
i64_to_double
(
-
5
),
i64_to_double
(
5
)
);
));
assert
(
false
,
"should've thrown an error"
);
}
contracts/test_api/test_real.cpp
浏览文件 @
51327e58
...
...
@@ -3,32 +3,37 @@
#include "test_api.hpp"
using
namespace
eosio
;
unsigned
int
test_real
::
create_instances
()
{
void
test_real
::
create_instances
()
{
real
lhs1
(
5
);
assert
(
lhs1
.
value
()
==
5
,
"real instance value is wrong"
);
return
0
;
}
unsigned
int
test_real
::
test_division
()
{
void
test_real
::
test_division
()
{
real
lhs1
(
5
);
real
rhs1
(
10
);
real
result1
=
lhs1
/
rhs1
;
uint64_t
a
=
double_div
(
i64_to_double
(
5
),
i64_to_double
(
10
));
assert
(
a
==
result1
.
value
(),
"real division result is wrong"
);
return
0
;
}
unsigned
int
test_real
::
test_multiplication
()
{
void
test_real
::
test_division_by_0
()
{
real
lhs1
(
5
);
real
rhs1
(
0
);
real
result1
=
lhs1
/
rhs1
;
assert
(
false
,
"should've thrown an error"
);
}
void
test_real
::
test_multiplication
()
{
real
lhs1
(
5
);
real
rhs1
(
10
);
real
result1
=
lhs1
*
rhs1
;
uint64_t
res
=
double_mult
(
5
,
10
);
assert
(
res
==
result1
.
value
(),
"real multiplication result is wrong"
);
return
0
;
}
unsigned
int
test_real
::
test_addition
()
void
test_real
::
test_addition
()
{
real
lhs1
(
5
);
real
rhs1
(
10
);
...
...
@@ -44,8 +49,6 @@ unsigned int test_real::test_addition()
real
sum
=
result1
+
result2
;
uint64_t
c
=
double_add
(
a
,
b
);
assert
(
sum
.
value
()
==
c
,
"real addition operation result is wrong"
);
return
0
;
}
contracts/test_api/test_transaction.cpp
浏览文件 @
51327e58
...
...
@@ -26,20 +26,6 @@ void test_transaction::send_action_empty() {
send_inline
(
act_buff
,
sizeof
(
act_buff
));
}
/**
* cause failure due to too many pending inline messages
*/
void
test_transaction
::
send_action_max
()
{
dummy_action
payload
=
{
DUMMY_ACTION_DEFAULT_A
,
DUMMY_ACTION_DEFAULT_B
,
DUMMY_ACTION_DEFAULT_C
};
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
action
<>
act
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"read_action_normal"
),
payload
);
char
act_buff
[
sizeof
(
act
)];
act
.
pack
(
act_buff
,
sizeof
(
act_buff
));
// send_inline(act_buff, sizeof(act_buff));
}
//assert(false, "send_message_max() should've thrown an error");
}
/**
* cause failure due to a large action payload
*/
...
...
@@ -65,63 +51,43 @@ void test_transaction::send_action_recurse() {
* cause failure due to inline TX failure
*/
void
test_transaction
::
send_action_inline_fail
()
{
action
<>
act
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"asser_false"
),
nullptr
);
action
<>
act
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"asser
t
_false"
),
nullptr
);
char
act_buff
[
sizeof
(
act
)];
act
.
pack
(
act_buff
,
sizeof
(
act_buff
));
send_inline
(
act_buff
,
sizeof
(
act_buff
));
}
#if 0
unsigned int test_transaction::send_transaction() {
void
test_transaction
::
send_transaction
()
{
dummy_action
payload
=
{
DUMMY_ACTION_DEFAULT_A
,
DUMMY_ACTION_DEFAULT_B
,
DUMMY_ACTION_DEFAULT_C
};
action act(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), payload);
//auto act = action_create(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), &payload, sizeof(dummy_action));
action
<>
act
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"read_action_normal"
),
payload
);
//auto trx = transaction();
auto
trx
=
transaction
<
256
,
2
,
4
>
();
transaction_require_scope(trx, N(testapi));
trx.add_action(trx, msg);
transaction_send(trx);
return 0;
trx
.
add_read_scope
(
N
(
testapi
));
trx
.
add_action
(
act
);
trx
.
send
(
0
);
}
unsigned int
test_transaction::send_transaction_empty() {
auto trx = transaction
_create
();
tr
ansaction_require_scope(trx,
N(testapi));
tr
ansaction_send(trx
);
void
test_transaction
::
send_transaction_empty
()
{
auto
trx
=
transaction
<
256
,
2
,
4
>
();
tr
x
.
add_read_scope
(
N
(
testapi
));
tr
x
.
send
(
0
);
assert
(
false
,
"send_transaction_empty() should've thrown an error"
);
return WASM_TEST_FAIL;
}
/**
* cause failure due to too many pending deferred transactions
*/
unsigned int test_transaction::send_transaction_max() {
for (int i = 0; i < 10; i++) {
transaction_create();
}
assert(false, "send_transaction_max() should've thrown an error");
return WASM_TEST_FAIL;
}
/**
* cause failure due to a large transaction size
*/
unsigned int
test_transaction::send_transaction_large() {
auto trx = transaction
_create
();
tr
ansaction_require_scope(trx,
N(testapi));
void
test_transaction
::
send_transaction_large
()
{
auto
trx
=
transaction
<
256
,
2
,
4
>
();
tr
x
.
add_read_scope
(
N
(
testapi
));
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
char large_message[
4 *
1024];
a
uto msg = message_create(N(testapi), WASM_TEST_ACTION("test_action", "read_action_normal"), large_message, sizeof(large_message)
);
tr
ansaction_add_message(trx, msg
);
char
large_message
[
1024
];
a
ction
<>
act
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"read_action_normal"
),
large_message
);
tr
x
.
add_action
(
act
);
}
tr
ansaction_send(trx
);
tr
x
.
send
(
0
);
assert
(
false
,
"send_transaction_large() should've thrown an error"
);
return WASM_TEST_FAIL;
}
#endif
contracts/test_api/test_types.cpp
浏览文件 @
51327e58
...
...
@@ -6,7 +6,7 @@
#include "test_api.hpp"
unsigned
int
test_types
::
types_size
()
{
void
test_types
::
types_size
()
{
assert
(
sizeof
(
int64_t
)
==
8
,
"int64_t size != 8"
);
assert
(
sizeof
(
uint64_t
)
==
8
,
"uint64_t size != 8"
);
...
...
@@ -21,11 +21,9 @@ unsigned int test_types::types_size() {
assert
(
sizeof
(
table_name
)
==
8
,
"table_name size != 8"
);
assert
(
sizeof
(
time
)
==
4
,
"time size != 4"
);
assert
(
sizeof
(
uint256
)
==
32
,
"uint256 != 32"
);
return
0
;
}
unsigned
int
test_types
::
char_to_symbol
()
{
void
test_types
::
char_to_symbol
()
{
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"
);
...
...
@@ -63,11 +61,9 @@ unsigned int test_types::char_to_symbol() {
if
((
i
>=
'a'
&&
i
<=
'z'
)
||
(
i
>=
'1'
||
i
<=
'5'
))
continue
;
assert
(
eosio
::
char_to_symbol
(
i
)
==
0
,
"eosio::char_to_symbol() != 0"
);
}
return
0
;
}
unsigned
int
test_types
::
string_to_name
()
{
void
test_types
::
string_to_name
()
{
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)"
);
...
...
@@ -88,11 +84,9 @@ unsigned int test_types::string_to_name() {
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
0
;
}
unsigned
int
test_types
::
name_class
()
{
void
test_types
::
name_class
()
{
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)"
);
...
...
@@ -103,6 +97,4 @@ unsigned int test_types::name_class() {
uint64_t
tmp
=
eosio
::
name
(
eosio
::
string_to_name
(
"11bbcccdd"
));
assert
(
N
(
11
bbcccdd
)
==
tmp
,
"N(11bbcccdd) == tmp"
);
return
0
;
}
contracts/test_api_db/CMakeLists.txt
0 → 100644
浏览文件 @
51327e58
add_wast_target
(
test_api_db
"
${
CMAKE_SOURCE_DIR
}
/contracts"
${
CMAKE_CURRENT_BINARY_DIR
}
)
contracts/test_api_db/test_api_db.cpp
0 → 100644
浏览文件 @
51327e58
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/eos.hpp>
#include "../test_api/test_api.hpp"
#include "test_db.cpp"
extern
"C"
{
void
init
()
{
}
void
apply
(
unsigned
long
long
code
,
unsigned
long
long
action
)
{
//test db
WASM_TEST_HANDLER
(
test_db
,
key_i64_general
);
#if 0
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
//unhandled test call
assert
(
false
,
"Unknown Test"
);
}
}
contracts/test_api_
mem
/test_db.cpp
→
contracts/test_api_
db
/test_db.cpp
浏览文件 @
51327e58
...
...
@@ -64,11 +64,24 @@ extern "C" {
char
*
ptr
=
(
char
*
)
vptr
;
while
(
size
--
)
{
*
(
ptr
++
)
=
val
;
}
}
uint32_t
my_strlen
(
const
char
*
str
);
bool
my_memcmp
(
void
*
s1
,
void
*
s2
,
uint32_t
n
);
uint32_t
my_strlen
(
const
char
*
str
)
{
uint32_t
len
=
0
;
while
(
str
[
len
])
++
len
;
return
len
;
}
bool
my_memcmp
(
void
*
s1
,
void
*
s2
,
uint32_t
n
)
{
unsigned
char
*
c1
=
(
unsigned
char
*
)
s1
;
unsigned
char
*
c2
=
(
unsigned
char
*
)
s2
;
for
(
uint32_t
i
=
0
;
i
<
n
;
i
++
)
{
if
(
c1
[
i
]
!=
c2
[
i
])
{
return
false
;
}
}
return
true
;
}
}
unsigned
int
test_db
::
key_str_table
()
{
void
test_db
::
key_str_table
()
{
const
char
*
keys
[]
=
{
"alice"
,
"bob"
,
"carol"
,
"dave"
};
const
char
*
vals
[]
=
{
"data1"
,
"data2"
,
"data3"
,
"data4"
};
...
...
@@ -144,10 +157,10 @@ unsigned int test_db::key_str_table() {
res
=
StringTableStr
.
next
((
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
0
);
assert
(
res
==
0
,
"next 0"
);
res
=
StringTableStr
.
front
(
tmp
,
64
);
res
=
StringTableStr
.
front
(
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
assert
(
res
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
res
),
"front alice"
);
res
=
StringTableStr
.
back
(
tmp
,
64
);
res
=
StringTableStr
.
back
(
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
assert
(
res
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
res
),
"back dave"
);
res
=
StringTableStr
.
lower_bound
((
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
...
...
@@ -162,10 +175,9 @@ unsigned int test_db::key_str_table() {
res
=
StringTableStr
.
upper_bound
((
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
assert
(
res
==
-
1
,
"no upper_bound"
);
return
0
;
}
unsigned
int
test_db
::
key_str_general
()
{
void
test_db
::
key_str_general
()
{
const
char
*
keys
[]
=
{
"alice"
,
"bob"
,
"carol"
,
"dave"
};
const
char
*
vals
[]
=
{
"data1"
,
"data2"
,
"data3"
,
"data4"
};
...
...
@@ -237,12 +249,13 @@ unsigned int test_db::key_str_general() {
res
=
next_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
0
);
assert
(
res
==
0
,
"next 0"
);
/*
res = front_str(current_receiver(), current_receiver(), N(str), tmp, 64);
assert(res == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, res), "front alice");
res = back_str(current_receiver(), current_receiver(), N(str), tmp, 64);
assert(res == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, res), "back dave");
*/
res
=
lower_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
assert
(
res
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
res
),
"lowerbound alice"
);
...
...
@@ -255,10 +268,9 @@ unsigned int test_db::key_str_general() {
res
=
upper_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
assert
(
res
==
-
1
,
"no upper_bound"
);
return
0
;
}
unsigned
int
test_db
::
key_i64_general
()
{
void
test_db
::
key_i64_general
()
{
uint32_t
res
=
0
;
...
...
@@ -292,6 +304,12 @@ unsigned int 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
));
...
...
@@ -457,10 +475,9 @@ unsigned int test_db::key_i64_general() {
}
}
return
0
;
}
unsigned
int
test_db
::
key_i64_remove_all
()
{
void
test_db
::
key_i64_remove_all
()
{
uint32_t
res
=
0
;
uint64_t
key
;
...
...
@@ -503,36 +520,29 @@ unsigned int test_db::key_i64_remove_all() {
key
=
N
(
dave
);
res
=
remove_i64
(
current_receiver
(),
N
(
test_table
),
&
key
);
assert
(
res
==
0
,
"remove dave 1"
);
return
0
;
}
unsigned
int
test_db
::
key_i64_small_load
()
{
void
test_db
::
key_i64_small_load
()
{
uint64_t
dummy
=
0
;
load_i64
(
current_receiver
(),
current_receiver
(),
N
(
just_uint64
),
&
dummy
,
sizeof
(
uint64_t
)
-
1
);
return
0
;
}
unsigned
int
test_db
::
key_i64_small_store
()
{
void
test_db
::
key_i64_small_store
()
{
uint64_t
dummy
=
0
;
store_i64
(
current_receiver
(),
N
(
just_uint64
),
&
dummy
,
sizeof
(
uint64_t
)
-
1
);
return
0
;
}
unsigned
int
test_db
::
key_i64_store_scope
()
{
void
test_db
::
key_i64_store_scope
()
{
uint64_t
dummy
=
0
;
store_i64
(
current_receiver
(),
N
(
just_uint64
),
&
dummy
,
sizeof
(
uint64_t
));
return
0
;
}
unsigned
int
test_db
::
key_i64_remove_scope
()
{
void
test_db
::
key_i64_remove_scope
()
{
uint64_t
dummy
=
0
;
store_i64
(
current_receiver
(),
N
(
just_uint64
),
&
dummy
,
sizeof
(
uint64_t
));
return
0
;
}
unsigned
int
test_db
::
key_i64_not_found
()
{
void
test_db
::
key_i64_not_found
()
{
uint64_t
dummy
=
1000
;
auto
res
=
load_i64
(
current_receiver
(),
current_receiver
(),
N
(
just_uint64
),
&
dummy
,
sizeof
(
uint64_t
));
...
...
@@ -540,10 +550,9 @@ unsigned int test_db::key_i64_not_found() {
res
=
remove_i64
(
current_receiver
(),
N
(
just_uint64
),
&
dummy
);
assert
(
res
==
0
,
"i64_not_found remove"
);
return
0
;
}
unsigned
int
test_db
::
key_i64_front_back
()
{
void
test_db
::
key_i64_front_back
()
{
uint32_t
res
=
0
;
...
...
@@ -620,11 +629,9 @@ unsigned int test_db::key_i64_front_back() {
assert
(
res
==
-
1
,
"key_i64_front 13"
);
res
=
back_i64
(
current_receiver
(),
current_receiver
(),
N
(
a
),
&
tmp
,
sizeof
(
test_model
)
);
assert
(
res
==
-
1
,
"key_i64_front 14"
);
return
0
;
}
u
nsigned
in
t
store_set_in_table
(
uint64_t
table_name
)
u
int32_
t
store_set_in_table
(
uint64_t
table_name
)
{
uint32_t
res
=
0
;
...
...
@@ -696,11 +703,10 @@ unsigned int store_set_in_table(uint64_t table_name)
res
=
store_i128i128
(
current_receiver
(),
table_name
,
&
dave3
,
sizeof
(
TestModel128x2
));
assert
(
res
==
1
,
"store dave3"
);
return
0
;
return
res
;
}
unsigned
int
store_set_in_table
(
TestModel3xi64
*
records
,
int
len
,
uint64_t
table_name
)
{
void
store_set_in_table
(
TestModel3xi64
*
records
,
int
len
,
uint64_t
table_name
)
{
uint32_t
res
=
0
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
TestModel3xi64
*
tmp
=
records
+
i
;
...
...
@@ -708,7 +714,6 @@ unsigned int store_set_in_table(TestModel3xi64* records, int len, uint64_t table
res
=
store_i64i64i64
(
current_receiver
(),
table_name
,
tmp
,
sizeof
(
TestModel3xi64
));
assert
(
res
==
1
,
"store_set_in_table"
);
}
return
res
;
}
...
...
@@ -902,7 +907,7 @@ unsigned int test_db::key_i64i64i64_general() {
}
#endif
unsigned
int
test_db
::
key_i128i128_general
()
{
void
test_db
::
key_i128i128_general
()
{
uint32_t
res
=
0
;
...
...
@@ -1082,8 +1087,6 @@ unsigned int test_db::key_i128i128_general() {
tmp2
.
table_name
==
N
(
table5
)
&&
tmp2
.
new_field
==
123456
,
"lp small update_i128i128 ok"
);
return
0
;
}
void
set_key_str
(
int
i
,
char
*
key_4_digit
)
...
...
@@ -1095,7 +1098,7 @@ void set_key_str(int i, char* key_4_digit)
key_4_digit
[
3
]
=
nums
[(
i
%
10
)];
}
unsigned
int
test_db
::
key_str_setup_limit
()
void
test_db
::
key_str_setup_limit
()
{
// assuming max memory: 5 MBytes
// assuming row overhead: 16 Bytes
...
...
@@ -1115,10 +1118,9 @@ unsigned int test_db::key_str_setup_limit()
store_str
(
N
(
dblimits
),
N
(
dblstr
),
key
,
sizeof
(
key
),
value
,
value_size
);
}
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_str_min_exceed_limit
()
void
test_db
::
key_str_min_exceed_limit
()
{
char
key
=
'1'
;
char
value
=
'1'
;
...
...
@@ -1129,10 +1131,9 @@ unsigned int test_db::key_str_min_exceed_limit()
// -> key + value bytes: 8 Bytes
// 8 + 32 = 40 Bytes (not enough space)
store_str
(
N
(
dblimits
),
N
(
dblstr
),
&
key
,
1
,
&
value
,
1
);
return
0
;
}
unsigned
int
test_db
::
key_str_under_limit
()
void
test_db
::
key_str_under_limit
()
{
// assuming max memory: 5 MBytes
// assuming row overhead: 16 Bytes
...
...
@@ -1152,10 +1153,9 @@ unsigned int test_db::key_str_under_limit()
store_str
(
N
(
dblimits
),
N
(
dblstr
),
key
,
sizeof
(
key
),
value
,
value_size
);
}
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_str_available_space_exceed_limit
()
void
test_db
::
key_str_available_space_exceed_limit
()
{
// key length: 30 bytes
// value length: 16323 bytes
...
...
@@ -1167,10 +1167,9 @@ unsigned int test_db::key_str_available_space_exceed_limit()
char
*
value
=
static_cast
<
char
*>
(
eosio
::
malloc
(
value_size
));
store_str
(
N
(
dblimits
),
N
(
dblstr
),
key
,
sizeof
(
key
),
value
,
value_size
);
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_str_another_under_limit
()
void
test_db
::
key_str_another_under_limit
()
{
// 16K bytes remaining
// key length: 30 bytes
...
...
@@ -1200,11 +1199,9 @@ unsigned int test_db::key_str_another_under_limit()
value
=
static_cast
<
char
*>
(
eosio
::
realloc
(
value
,
value_size
));
update_str
(
N
(
dblimits
),
N
(
dblstr
),
key
,
sizeof
(
key
),
value
,
value_size
);
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64_setup_limit
()
void
test_db
::
key_i64_setup_limit
()
{
// assuming max memory: 5M Bytes
// assuming row overhead: 16 Bytes
...
...
@@ -1220,19 +1217,17 @@ unsigned int test_db::key_i64_setup_limit()
store_i64
(
N
(
dblimits
),
N
(
dbli64
),
(
char
*
)
value
,
value_size
);
}
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64_min_exceed_limit
()
void
test_db
::
key_i64_min_exceed_limit
()
{
// will allocate 8 + 32 Bytes
// at 5M Byte limit, so cannot store anything
uint64_t
value
=
(
uint64_t
)
-
1
;
store_i64
(
N
(
dblimits
),
N
(
dbli64
),
(
char
*
)
&
value
,
sizeof
(
uint64_t
));
return
0
;
}
unsigned
int
test_db
::
key_i64_under_limit
()
void
test_db
::
key_i64_under_limit
()
{
// updating keys' values
// key length: 8 bytes
...
...
@@ -1248,10 +1243,9 @@ unsigned int test_db::key_i64_under_limit()
}
// 262,144 Bytes remaining
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64_available_space_exceed_limit
()
void
test_db
::
key_i64_available_space_exceed_limit
()
{
// 262,144 Bytes remaining
// key length: 8 bytes
...
...
@@ -1263,10 +1257,9 @@ unsigned int test_db::key_i64_available_space_exceed_limit()
value
[
0
]
=
1024
*
2
;
store_i64
(
N
(
dblimits
),
N
(
dbli64
),
(
char
*
)
value
,
value_size
);
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64_another_under_limit
()
void
test_db
::
key_i64_another_under_limit
()
{
// 262,144 Bytes remaining
// key length: 8 bytes
...
...
@@ -1298,11 +1291,9 @@ unsigned int test_db::key_i64_another_under_limit()
// 32 Bytes remaining (smallest row entry is 40 Bytes)
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i128i128_setup_limit
()
void
test_db
::
key_i128i128_setup_limit
()
{
// assuming max memory: 5M Bytes
// assuming row overhead: 16 Bytes
...
...
@@ -1319,10 +1310,9 @@ unsigned int test_db::key_i128i128_setup_limit()
store_i128i128
(
N
(
dblimits
),
N
(
dbli128i128
),
(
char
*
)
value
,
value_size
);
}
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i128i128_min_exceed_limit
()
void
test_db
::
key_i128i128_min_exceed_limit
()
{
// will allocate 32 + 32 Bytes
// at 5M Byte limit, so cannot store anything
...
...
@@ -1331,10 +1321,9 @@ unsigned int test_db::key_i128i128_min_exceed_limit()
value
[
0
]
=
(
uint128_t
)
-
1
;
value
[
1
]
=
value
[
0
]
+
1
;
store_i128i128
(
N
(
dblimits
),
N
(
dbli128i128
),
(
char
*
)
&
value
,
value_size
);
return
0
;
}
unsigned
int
test_db
::
key_i128i128_under_limit
()
void
test_db
::
key_i128i128_under_limit
()
{
// updating keys' values
// keys length: 32 bytes
...
...
@@ -1351,10 +1340,9 @@ unsigned int test_db::key_i128i128_under_limit()
}
// 262,144 Bytes remaining
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i128i128_available_space_exceed_limit
()
void
test_db
::
key_i128i128_available_space_exceed_limit
()
{
// 262,144 Bytes remaining
// keys length: 32 bytes
...
...
@@ -1367,10 +1355,9 @@ unsigned int test_db::key_i128i128_available_space_exceed_limit()
value
[
1
]
=
value
[
0
]
+
1
;
store_i128i128
(
N
(
dblimits
),
N
(
dbli128i128
),
(
char
*
)
value
,
value_size
);
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i128i128_another_under_limit
()
void
test_db
::
key_i128i128_another_under_limit
()
{
// 262,144 Bytes remaining
// keys length: 32 bytes
...
...
@@ -1406,10 +1393,9 @@ unsigned int test_db::key_i128i128_another_under_limit()
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64i64i64_setup_limit
()
void
test_db
::
key_i64i64i64_setup_limit
()
{
// assuming max memory: 5M Bytes
// assuming row overhead: 16 Bytes
...
...
@@ -1427,10 +1413,9 @@ unsigned int test_db::key_i64i64i64_setup_limit()
store_i64i64i64
(
N
(
dblimits
),
N
(
dbli64i64i64
),
(
char
*
)
value
,
value_size
);
}
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64i64i64_min_exceed_limit
()
void
test_db
::
key_i64i64i64_min_exceed_limit
()
{
// will allocate 24 + 32 Bytes
// at 5M Byte limit, so cannot store anything
...
...
@@ -1440,10 +1425,9 @@ unsigned int test_db::key_i64i64i64_min_exceed_limit()
value
[
1
]
=
value
[
0
]
+
1
;
value
[
2
]
=
value
[
0
]
+
2
;
store_i64i64i64
(
N
(
dblimits
),
N
(
dbli64i64i64
),
(
char
*
)
&
value
,
value_size
);
return
0
;
}
unsigned
int
test_db
::
key_i64i64i64_under_limit
()
void
test_db
::
key_i64i64i64_under_limit
()
{
// updating keys' values
// keys length: 24 bytes
...
...
@@ -1461,10 +1445,9 @@ unsigned int test_db::key_i64i64i64_under_limit()
}
// 262,144 Bytes remaining
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64i64i64_available_space_exceed_limit
()
void
test_db
::
key_i64i64i64_available_space_exceed_limit
()
{
// 262,144 Bytes remaining
// keys length: 24 bytes
...
...
@@ -1478,10 +1461,9 @@ unsigned int test_db::key_i64i64i64_available_space_exceed_limit()
value
[
2
]
=
value
[
0
]
+
2
;
store_i64i64i64
(
N
(
dblimits
),
N
(
dbli64i64i64
),
(
char
*
)
value
,
value_size
);
eosio
::
free
(
value
);
return
0
;
}
unsigned
int
test_db
::
key_i64i64i64_another_under_limit
()
void
test_db
::
key_i64i64i64_another_under_limit
()
{
// 262,144 Bytes remaining
// keys length: 24 bytes
...
...
@@ -1520,5 +1502,4 @@ unsigned int test_db::key_i64i64i64_another_under_limit()
eosio
::
free
(
value
);
return
0
;
}
contracts/test_api_mem/test_api_mem.cpp
浏览文件 @
51327e58
...
...
@@ -8,7 +8,6 @@
#include "test_extended_memory.cpp"
#include "test_memory.cpp"
#include "test_string.cpp"
//#include "test_db.cpp"
extern
"C"
{
...
...
@@ -36,42 +35,6 @@ extern "C" {
WASM_TEST_HANDLER
(
test_memory
,
test_memcpy_overlap_end
);
WASM_TEST_HANDLER
(
test_memory
,
test_memcmp
);
#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
// test string
WASM_TEST_HANDLER
(
test_string
,
construct_with_size
);
WASM_TEST_HANDLER
(
test_string
,
construct_with_data
);
...
...
contracts/test_api_mem/test_db.cpp.bak
0 → 100644
浏览文件 @
51327e58
此差异已折叠。
点击以展开。
contracts/test_api_mem/test_memory.cpp
浏览文件 @
51327e58
...
...
@@ -2,7 +2,7 @@
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eoslib/message.h>
//
#include <eoslib/message.h>
#include <eoslib/memory.hpp>
using
namespace
eosio
;
...
...
libraries/chain/include/eosio/chain/apply_context.hpp
浏览文件 @
51327e58
...
...
@@ -45,6 +45,7 @@ class apply_context {
template
<
typename
IndexType
,
typename
Scope
>
int32_t
load_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
);
template
<
typename
IndexType
,
typename
Scope
>
int32_t
front_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
);
...
...
@@ -442,9 +443,24 @@ using apply_handler = std::function<void(apply_context&)>;
}
return
0
;
}
template
<
typename
IndexType
,
typename
Scope
>
int32_t
apply_context
::
load_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
)
{
template
<
typename
T
>
struct
is_char_t
{
static
const
bool
value
=
false
;
};
template
<
>
struct
is_char_t
<
char
>
{
static
const
bool
value
=
true
;
};
template
<
typename
T
>
struct
is_char_ptr
{
static
const
bool
value
=
std
::
is_pointer
<
T
>::
value
&&
is_char_t
<
T
>::
value
;
};
template
<
typename
IndexType
,
typename
Scope
>
int32_t
apply_context
::
load_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
)
{
require_read_scope
(
t_id
.
scope
);
const
auto
&
idx
=
db
.
get_index
<
IndexType
,
Scope
>
();
...
...
@@ -468,7 +484,7 @@ using apply_handler = std::function<void(apply_context&)>;
}
}
template
<
typename
IndexType
,
typename
Scope
>
template
<
typename
IndexType
,
typename
Scope
>
int32_t
apply_context
::
front_record
(
const
table_id_object
&
t_id
,
typename
IndexType
::
value_type
::
key_type
*
keys
,
char
*
value
,
size_t
valuelen
)
{
require_read_scope
(
t_id
.
scope
);
...
...
@@ -652,4 +668,4 @@ using apply_handler = std::function<void(apply_context&)>;
}
}
// namespace eosio::chain
FC_REFLECT
(
eosio
::
chain
::
apply_context
::
apply_results
,
(
applied_actions
)(
generated_transactions
));
\ No newline at end of file
FC_REFLECT
(
eosio
::
chain
::
apply_context
::
apply_results
,
(
applied_actions
)(
generated_transactions
));
libraries/chain/include/eosio/chain/contracts/contract_table_objects.hpp
浏览文件 @
51327e58
...
...
@@ -214,4 +214,4 @@ FC_REFLECT(eosio::chain::contracts::table_id_object, (id)(scope)(code)(table) )
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key_value_object
,
(
id
)(
t_id
)(
primary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
keystr_value_object
,
(
id
)(
t_id
)(
primary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key128x128_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
value
)
)
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key64x64x64_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
tertiary_key
)(
value
)
)
\ No newline at end of file
FC_REFLECT
(
eosio
::
chain
::
contracts
::
key64x64x64_value_object
,
(
id
)(
t_id
)(
primary_key
)(
secondary_key
)(
tertiary_key
)(
value
)
)
libraries/chain/include/eosio/chain/wasm_interface_private.hpp
浏览文件 @
51327e58
...
...
@@ -136,6 +136,10 @@ struct native_to_wasm<uint64_t> {
using
type
=
I64
;
};
template
<
>
struct
native_to_wasm
<
size_t
>
{
using
type
=
I32
;
};
template
<
>
struct
native_to_wasm
<
bool
>
{
using
type
=
I32
;
};
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
51327e58
...
...
@@ -751,7 +751,12 @@ class db_api : 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
);
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
;
}
public:
...
...
@@ -767,13 +772,54 @@ class db_api : public context_aware_api {
int
update
(
const
scope_name
&
scope
,
const
name
&
table
,
array_ptr
<
const
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
update_record
<
ObjectType
>
,
scope
,
table
,
data
,
data_len
);
}
int
remove
(
const
scope_name
&
scope
,
const
name
&
table
,
const
KeyArrayType
&
keys
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
scope
,
context
.
receiver
,
table
);
return
context
.
remove_record
<
ObjectType
>
(
t_id
,
keys
);
}
};
template
<
>
class
db_api
<
keystr_value_object
>
:
public
context_aware_api
{
using
KeyType
=
std
::
string
;
static
constexpr
int
KeyCount
=
1
;
using
KeyArrayType
=
KeyType
[
KeyCount
];
using
ContextMethodType
=
int
(
apply_context
::*
)(
const
table_id_object
&
,
const
KeyType
*
,
const
char
*
,
size_t
);
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);
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);
}
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
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
remove_str
(
const
scope_name
&
scope
,
const
name
&
table
,
array_ptr
<
const
char
>
&
key
,
uint32_t
key_len
)
{
const
auto
&
t_id
=
context
.
find_or_create_table
(
scope
,
context
.
receiver
,
table
);
const
KeyArrayType
k
=
{
std
::
string
(
key
,
key_len
)};
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
;
...
...
@@ -795,7 +841,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
)
;
//
+ sizeof(KeyArrayType);
}
public:
...
...
@@ -833,6 +879,65 @@ class db_index_api : public context_aware_api {
};
template
<
>
class
db_index_api
<
keystr_value_index
,
by_scope_primary
>
:
public
context_aware_api
{
using
KeyType
=
std
::
string
;
static
constexpr
int
KeyCount
=
1
;
using
KeyArrayType
=
KeyType
[
KeyCount
];
using
ContextMethodType
=
int
(
apply_context
::*
)(
const
table_id_object
&
,
KeyType
*
,
char
*
,
size_t
);
int
call
(
ContextMethodType
method
,
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
&
key
,
uint32_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
maybe_t_id
=
context
.
find_table
(
scope
,
context
.
receiver
,
table
);
if
(
maybe_t_id
==
nullptr
)
{
return
0
;
}
const
auto
&
t_id
=
*
maybe_t_id
;
//FC_ASSERT(data_len >= KeyCount * sizeof(KeyType), "Data is not long enough to contain keys");
KeyType
keys
((
const
char
*
)
key
,
key_len
);
// = reinterpret_cast<KeyType *>((char *)data);
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);
}
public:
using
context_aware_api
::
context_aware_api
;
int
load_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
res
=
call
(
&
apply_context
::
load_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
return
res
;
}
int
front_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
front_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
int
back_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
back_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
int
next_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
next_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
int
previous_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
previous_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
int
lower_bound_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
lower_bound_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
int
upper_bound_str
(
const
scope_name
&
scope
,
const
account_name
&
code
,
const
name
&
table
,
array_ptr
<
char
>
key
,
size_t
key_len
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
return
call
(
&
apply_context
::
upper_bound_record
<
keystr_value_index
,
by_scope_primary
>
,
scope
,
code
,
table
,
key
,
key_len
,
data
,
data_len
);
}
};
class
memory_api
:
public
context_aware_api
{
public:
using
context_aware_api
::
context_aware_api
;
...
...
@@ -1095,10 +1200,10 @@ class math_api : public context_aware_api {
uint64_t
double_to_i64
(
uint64_t
n
)
{
using
DOUBLE
=
boost
::
multiprecision
::
cpp_bin_float_50
;
return
DOUBLE
(
*
reinterpret_cast
<
double
*>
(
&
n
)).
convert_to
<
u
int64_t
>
();
return
DOUBLE
(
*
reinterpret_cast
<
double
*>
(
&
n
)).
convert_to
<
int64_t
>
();
}
uint64_t
i64_to_double
(
u
int64_t
n
)
{
uint64_t
i64_to_double
(
int64_t
n
)
{
using
DOUBLE
=
boost
::
multiprecision
::
cpp_bin_float_50
;
double
res
=
DOUBLE
(
n
).
convert_to
<
double
>
();
return
*
reinterpret_cast
<
uint64_t
*>
(
&
res
);
...
...
@@ -1216,12 +1321,27 @@ using db_index_api_key64x64x64_value_index_by_scope_secondary = db_index_api<key
using
db_index_api_key64x64x64_value_index_by_scope_tertiary
=
db_index_api
<
key64x64x64_value_index
,
by_scope_tertiary
>
;
REGISTER_INTRINSICS
(
db_api_key_value_object
,
DB_METHOD_SEQ
(
i64
));
REGISTER_INTRINSICS
(
db_api_keystr_value_object
,
DB_METHOD_SEQ
(
str
));
//
REGISTER_INTRINSICS(db_api_keystr_value_object, DB_METHOD_SEQ(str));
REGISTER_INTRINSICS
(
db_api_key128x128_value_object
,
DB_METHOD_SEQ
(
i128i128
));
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
)
)
(
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
,
DB_INDEX_METHOD_SEQ
(
str
));
//REGISTER_INTRINSICS(db_index_api_keystr_value_index_by_scope_primary, DB_INDEX_METHOD_SEQ(str));
#if 1
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
)
)
(
back_str
,
int32_t
(
int64_t
,
int64_t
,
int64_t
,
int
,
int
,
int
,
int
)
)
(
next_str
,
int32_t
(
int64_t
,
int64_t
,
int64_t
,
int
,
int
,
int
,
int
)
)
(
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
)
));
#endif
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_key64x64x64_value_index_by_scope_primary
,
DB_INDEX_METHOD_SEQ
(
primary_i64i64i64
));
...
...
libraries/wasm-jit/Source/Platform/POSIX.cpp
浏览文件 @
51327e58
...
...
@@ -13,6 +13,7 @@
#include <setjmp.h>
#include <sys/resource.h>
#include <string.h>
#include <iostream>
#include <sys/time.h>
...
...
scripts/install_dependencies.sh
浏览文件 @
51327e58
...
...
@@ -63,8 +63,8 @@ if [ $ARCH == "darwin" ]; then
DEPS
=
"git automake libtool boost openssl llvm@4 gmp wget cmake gettext"
brew update
brew
install
--force
$DEPS
brew
unlink
$DEPS
&&
brew
link
--force
$DEPS
# LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm
#
brew unlink $DEPS && brew link --force $DEPS
LLVM_DIR
=
/usr/local/Cellar/llvm
\@
4/4.0.1/lib/cmake
# install secp256k1-zkp (Cryptonomex branch)
cd
${
TEMP_DIR
}
...
...
@@ -88,6 +88,7 @@ if [ $ARCH == "darwin" ]; then
sudo rm
-rf
${
TEMP_DIR
}
/binaryen
BINARYEN_BIN
=
/usr/local/binaryen/bin/
# Build LLVM and clang for WASM:
cd
${
TEMP_DIR
}
mkdir
wasm-compiler
...
...
@@ -103,4 +104,5 @@ if [ $ARCH == "darwin" ]; then
sudo rm
-rf
${
TEMP_DIR
}
/wasm-compiler
WASM_LLVM_CONFIG
=
/usr/local/wasm/bin/llvm-config
fi
tests/api_tests/api_tests.cpp
浏览文件 @
51327e58
...
...
@@ -38,6 +38,7 @@
#include <Runtime/Runtime.h>
#include <test_api/test_api.wast.hpp>
#include <test_api_db/test_api_db.wast.hpp>
#include <test_api_mem/test_api_mem.wast.hpp>
#include <test_api/test_api.hpp>
...
...
@@ -67,11 +68,17 @@ struct test_api_action {
};
FC_REFLECT_TEMPLATE
((
uint64_t
T
),
test_api_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
());
return
(
ex
.
get_log
().
at
(
0
).
get_message
().
find
(
expected
)
!=
std
::
string
::
npos
);
}
struct
assert_message_is
{
assert_message_is
(
string
expected
)
:
expected
(
expected
)
{}
//
assert_message_is(string expected)
//
: expected(expected) {}
bool
operator
()(
const
fc
::
assert_exception
&
ex
)
{
bool
operator
()(
const
fc
::
exception
&
ex
,
string
expected
)
{
auto
act
=
ex
.
get_log
().
at
(
0
).
get_message
();
return
boost
::
algorithm
::
ends_with
(
act
,
expected
);
}
...
...
@@ -279,9 +286,12 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
set_code
(
N
(
acc1
),
test_api_wast
);
set_code
(
N
(
acc2
),
test_api_wast
);
produce_blocks
(
1
);
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"assert_true"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"assert_false"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"assert_false"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"test_action::assert_false"
);
}
);
dummy_action
dummy13
{
DUMMY_ACTION_DEFAULT_A
,
DUMMY_ACTION_DEFAULT_B
,
DUMMY_ACTION_DEFAULT_C
};
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_normal"
,
fc
::
raw
::
pack
(
dummy13
));
...
...
@@ -290,15 +300,23 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_0"
,
raw_bytes
);
std
::
vector
<
char
>
raw_bytes2
((
1
<<
16
)
+
1
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_0"
,
raw_bytes2
),
eosio
::
chain
::
wasm_execution_error
,
is_wasm_execution_error
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_0"
,
raw_bytes2
),
eosio
::
chain
::
wasm_execution_error
,
[](
const
eosio
::
chain
::
wasm_execution_error
&
e
)
{
return
expect_assert_message
(
e
,
"access violation"
);
}
);
raw_bytes
.
resize
(
1
);
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_64k"
,
raw_bytes
);
raw_bytes
.
resize
(
2
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_64k"
,
raw_bytes
),
eosio
::
chain
::
wasm_execution_error
,
is_wasm_execution_error
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"read_action_to_64k"
,
raw_bytes
),
eosio
::
chain
::
wasm_execution_error
,
[](
const
eosio
::
chain
::
wasm_execution_error
&
e
)
{
return
expect_assert_message
(
e
,
"access violation"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_notice"
,
raw_bytes
);
...
...
@@ -319,16 +337,34 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
BOOST_CHECK_EQUAL
(
res
.
status
,
transaction_receipt
::
executed
);
};
BOOST_CHECK_EXCEPTION
(
test_require_notice
(
*
this
,
raw_bytes
,
scope
),
tx_missing_sigs
,
is_tx_missing_sigs
);
BOOST_CHECK_EXCEPTION
(
test_require_notice
(
*
this
,
raw_bytes
,
scope
),
tx_missing_sigs
,
[](
const
tx_missing_sigs
&
e
)
{
return
expect_assert_message
(
e
,
"transaction declares authority"
);
}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
{}),
tx_missing_auth
,
[](
const
tx_missing_auth
&
e
)
{
return
expect_assert_message
(
e
,
"missing authority of"
);
}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
{}),
tx_missing_auth
,
is_tx_missing_auth
);
auto
a3only
=
std
::
vector
<
permission_level
>
{{
N
(
acc3
),
config
::
active_name
}};
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
fc
::
raw
::
pack
(
a3only
)),
tx_missing_auth
,
is_tx_missing_auth
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
fc
::
raw
::
pack
(
a3only
)),
tx_missing_auth
,
[](
const
tx_missing_auth
&
e
)
{
return
expect_assert_message
(
e
,
"missing authority of"
);
}
);
auto
a4only
=
std
::
vector
<
permission_level
>
{{
N
(
acc4
),
config
::
active_name
}};
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
fc
::
raw
::
pack
(
a4only
)),
tx_missing_auth
,
is_tx_missing_auth
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"require_auth"
,
fc
::
raw
::
pack
(
a4only
)),
tx_missing_auth
,
[](
const
tx_missing_auth
&
e
)
{
return
expect_assert_message
(
e
,
"missing authority of"
);
}
);
auto
a3a4
=
std
::
vector
<
permission_level
>
{{
N
(
acc3
),
config
::
active_name
},
{
N
(
acc4
),
config
::
active_name
}};
auto
a3a4_scope
=
std
::
vector
<
account_name
>
{
N
(
acc3
),
N
(
acc4
)};
...
...
@@ -341,7 +377,6 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
for
(
int
i
=
1
;
i
<
a3a4_scope
.
size
();
i
++
)
pl
.
push_back
({
a3a4_scope
[
i
],
config
::
active_name
});
//action act(vector<permission_level>{{scope[0], config::active_name}}, tm);
action
act
(
pl
,
tm
);
auto
dat
=
fc
::
raw
::
pack
(
a3a4
);
vector
<
char
>&
dest
=
*
(
vector
<
char
>
*
)(
&
act
.
data
);
...
...
@@ -358,7 +393,13 @@ BOOST_FIXTURE_TEST_CASE(action_tests, tester) { try {
uint32_t
now
=
control
->
head_block_time
().
sec_since_epoch
();
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"now"
,
fc
::
raw
::
pack
(
now
));
produce_block
();
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"now"
,
fc
::
raw
::
pack
(
now
)),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_action"
,
"now"
,
fc
::
raw
::
pack
(
now
)),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"assertion failed: tmp == now"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -380,7 +421,12 @@ BOOST_FIXTURE_TEST_CASE(compiler_builtins_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_multi3"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_divti3"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_divti3_by_0"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_divti3_by_0"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"divide by zero"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_lshlti3"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_lshrti3"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_compiler_builtins"
,
"test_ashlti3"
,
{});
...
...
@@ -406,11 +452,36 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_empty"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_max"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_large"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_recurse"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_inline_fail"
,
{});
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
,
"payload exceeds maximum size"
);
}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_recurse"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"payload exceeds maximum size"
);
}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_action_inline_fail"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"test_action::assert_false"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_transaction"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_transaction_empty"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"transaction must have at least one action"
);
}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_transaction"
,
"send_transaction_large"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
!
expect_assert_message
(
e
,
"send_transaction_large() should've thrown an error"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -438,7 +509,7 @@ BOOST_FIXTURE_TEST_CASE(chain_tests, tester) { try {
// (Bucky) TODO got to fix macros in test_db.cpp
#if
0
#if
1
/*************************************************************************************
* db_tests test case
*************************************************************************************/
...
...
@@ -448,7 +519,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), test_api_
mem
_wast );
set_code
(
N
(
testapi
),
test_api_
db
_wast
);
produce_blocks
(
1
);
CALL_TEST_FUNCTION
(
*
this
,
"test_db"
,
"key_i64_general"
,
{});
...
...
@@ -473,6 +544,12 @@ BOOST_FIXTURE_TEST_CASE(fixedpoint_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_fixedpoint"
,
"test_subtraction"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_fixedpoint"
,
"test_multiplication"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_fixedpoint"
,
"test_division"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_fixedpoint"
,
"test_division_by_0"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"divide by zero"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -489,12 +566,16 @@ BOOST_FIXTURE_TEST_CASE(real_tests, tester) { try {
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_real"
,
"create_instances"
,
{}
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_real"
,
"test_addition"
,
{}
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_real"
,
"test_multiplication"
,
{}
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_real"
,
"test_division"
,
{}
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_fixedpoint"
,
"test_division_by_0"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"divide by zero"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -509,17 +590,26 @@ BOOST_FIXTURE_TEST_CASE(crypto_tests, tester) { try {
produce_blocks
(
1000
);
set_code
(
N
(
testapi
),
test_api_wast
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"test_sha256"
,
{}
);
produce_blocks
(
1000
);
// TODO should this throw an exception
//BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_crypto", "sha256_no_data", {} ), fc::assert_exception, is_assert_exception);
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"sha256_no_data"
,
{}
);
produce_blocks
(
1000
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"asert_sha256_false"
,
{}
),
fc
::
assert_exception
,
is_assert_exception
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"asert_sha256_true"
,
{}
);
produce_blocks
(
1000
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"asert_no_data"
,
{}
),
fc
::
assert_exception
,
is_assert_exception
);
// TODO this works, not sure if this should
#if 0
BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_crypto", "sha256_null", {} ), fc::assert_exception,
[](const fc::assert_exception& e) {
return !expect_assert_message(e, "should've thrown an error");
}
);
#endif
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"assert_sha256_false"
,
{}
),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"hash miss match"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_crypto"
,
"assert_sha256_true"
,
{}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -534,6 +624,7 @@ BOOST_FIXTURE_TEST_CASE(memory_test, tester) { try {
produce_blocks
(
1000
);
set_code
(
N
(
testapi
),
test_api_mem_wast
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_memory"
,
"test_memory_allocs"
,
{}
);
produce_blocks
(
1000
);
CALL_TEST_FUNCTION
(
*
this
,
"test_memory"
,
"test_memory_hunk"
,
{}
);
...
...
@@ -585,8 +676,9 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_page_memory_exceeded, tester) { try
produce_blocks
(
1000
);
set_code
(
N
(
testapi
),
test_api_mem_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
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_extended_memory"
,
"test_page_memory_exceeded"
,
{}
),
page_memory_error
,
is_page_memory_error
);
}
FC_LOG_AND_RETHROW
()
}
BOOST_FIXTURE_TEST_CASE
(
extended_memory_test_page_memory_negative_bytes
,
tester
)
{
try
{
...
...
@@ -598,7 +690,8 @@ BOOST_FIXTURE_TEST_CASE(extended_memory_test_page_memory_negative_bytes, tester)
set_code
(
N
(
testapi
),
test_api_mem_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
);
page_memory_error
,
is_page_memory_error
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -623,10 +716,20 @@ BOOST_FIXTURE_TEST_CASE(string_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"copy_constructor"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"assignment_operator"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"index_operator"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"index_out_of_bound"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"index_out_of_bound"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"index out of bound"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"substring"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"concatenation_null_terminated"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"substring_out_of_bound"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"substring_out_of_bound"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"out of bound"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"concatenation_non_null_terminated"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"assign"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"comparison_operator"
,
{});
...
...
@@ -635,8 +738,12 @@ BOOST_FIXTURE_TEST_CASE(string_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"print_unicode"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"string_literal"
,
{});
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"valid_utf8"
,
{});
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"invalid_utf8"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_string"
,
"invalid_utf8"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"string should be a valid utf8 string"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
@@ -669,9 +776,6 @@ BOOST_FIXTURE_TEST_CASE(print_tests, tester) { try {
BOOST_CHECK_EQUAL
(
captured
.
substr
(
1
,
6
),
U64Str
(
556644
)
);
// "556644"
BOOST_CHECK_EQUAL
(
captured
.
substr
(
7
,
capture
[
3
].
size
()),
U64Str
(
-
1
)
);
// "18446744073709551615"
//TODO come back to this, no native uint128_t
// test printi128
// test printn
CAPTURE_AND_PRE_TEST_PRINT
(
"test_printn"
);
BOOST_CHECK_EQUAL
(
captured
.
substr
(
0
,
5
),
"abcde"
);
...
...
@@ -726,9 +830,32 @@ BOOST_FIXTURE_TEST_CASE(math_tests, tester) { try {
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_diveq"
,
fc
::
raw
::
pack
(
act
));
}
// test diveq for divide by zero
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_diveq_by_0"
,
{}),
fc
::
assert_exception
,
is_assert_exception
);
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_diveq_by_0"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"divide by zero"
);
}
);
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_double_api"
,
{});
//BOOST_CHECK_EXCEPTION(CALL_TEST_FUNCTION( *this, "test_math", "test_double_api_div_0", {}), fc::assert_exception, is_assert_exception);
union
{
char
whole
[
32
];
double
_
[
4
]
=
{
2
,
-
2
,
100000
,
-
100000
};
}
d_vals
;
std
::
vector
<
char
>
ds
(
sizeof
(
d_vals
));
std
::
copy
(
d_vals
.
whole
,
d_vals
.
whole
+
sizeof
(
d_vals
),
ds
.
begin
());
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_i64_to_double"
,
ds
);
//fc::raw::pack(d_vals));
std
::
copy
(
d_vals
.
whole
,
d_vals
.
whole
+
sizeof
(
d_vals
),
ds
.
begin
());
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_double_to_i64"
,
ds
);
//fc::raw::pack(d_vals));
BOOST_CHECK_EXCEPTION
(
CALL_TEST_FUNCTION
(
*
this
,
"test_math"
,
"test_double_api_div_0"
,
{}),
fc
::
assert_exception
,
[](
const
fc
::
assert_exception
&
e
)
{
return
expect_assert_message
(
e
,
"divide by zero"
);
}
);
}
FC_LOG_AND_RETHROW
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录