Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
dbbd9717
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,发现更多精彩内容 >>
提交
dbbd9717
编写于
3月 08, 2018
作者:
K
Khaled Al-Hassanieh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changes in order to get rid of contract warnings
上级
cba7381e
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
275 addition
and
277 deletion
+275
-277
contracts/asserter/asserter.cpp
contracts/asserter/asserter.cpp
+1
-1
contracts/eosiolib/fixedpoint.hpp
contracts/eosiolib/fixedpoint.hpp
+6
-6
contracts/eosiolib/print.hpp
contracts/eosiolib/print.hpp
+2
-2
contracts/eosiolib/real.hpp
contracts/eosiolib/real.hpp
+1
-1
contracts/eosiolib/singleton.hpp
contracts/eosiolib/singleton.hpp
+1
-1
contracts/identity/identity.hpp
contracts/identity/identity.hpp
+1
-1
contracts/identity/test/identity_test.cpp
contracts/identity/test/identity_test.cpp
+2
-2
contracts/noop/noop.hpp
contracts/noop/noop.hpp
+0
-2
contracts/simpledb/simpledb.cpp
contracts/simpledb/simpledb.cpp
+16
-16
contracts/test_api/test_action.cpp
contracts/test_api/test_action.cpp
+2
-2
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+1
-1
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+1
-1
contracts/test_api/test_compiler_builtins.cpp
contracts/test_api/test_compiler_builtins.cpp
+81
-82
contracts/test_api/test_crypto.cpp
contracts/test_api/test_crypto.cpp
+5
-8
contracts/test_api/test_fixedpoint.cpp
contracts/test_api/test_fixedpoint.cpp
+76
-74
contracts/test_api/test_math.cpp
contracts/test_api/test_math.cpp
+8
-10
contracts/test_api/test_print.cpp
contracts/test_api/test_print.cpp
+22
-21
contracts/test_api/test_real.cpp
contracts/test_api/test_real.cpp
+4
-0
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+16
-15
contracts/test_api/test_types.cpp
contracts/test_api/test_types.cpp
+2
-2
contracts/test_api_db/test_db.cpp
contracts/test_api_db/test_db.cpp
+22
-23
contracts/test_api_mem/test_api_mem.cpp
contracts/test_api_mem/test_api_mem.cpp
+1
-1
contracts/test_api_mem/test_extended_memory.cpp
contracts/test_api_mem/test_extended_memory.cpp
+3
-3
contracts/test_api_mem/test_memory.cpp
contracts/test_api_mem/test_memory.cpp
+1
-2
未找到文件。
contracts/asserter/asserter.cpp
浏览文件 @
dbbd9717
...
...
@@ -29,7 +29,7 @@ extern "C" {
}
// maybe assert?
eosio_assert
(
def
->
condition
,
def
->
message
);
eosio_assert
(
(
uint32_t
)
def
->
condition
,
def
->
message
);
}
else
if
(
action
==
N
(
provereset
)
)
{
eosio_assert
(
global_variable
==
45
,
"Global Variable Initialized poorly"
);
global_variable
=
100
;
...
...
contracts/eosiolib/fixedpoint.hpp
浏览文件 @
dbbd9717
...
...
@@ -147,11 +147,11 @@ ope * fixed_point128<3> b(a);
*/
uint128_t
frac_part
()
const
{
if
(
!
Q
)
return
0
;
return
val
<<
(
32
-
Q
);
return
uint128_t
(
val
<<
(
32
-
Q
)
);
}
void
print
()
const
{
uint128_t
ip
(
int_part
());
uint128_t
ip
(
(
uint128_t
)
int_part
());
uint128_t
fp
(
frac_part
());
printi128
(
&
ip
);
prints
(
"."
);
...
...
@@ -230,7 +230,7 @@ ope * fixed_point128<3> b(a);
*/
uint64_t
frac_part
()
const
{
if
(
!
Q
)
return
0
;
return
val
<<
(
32
-
Q
);
return
uint64_t
(
val
<<
(
32
-
Q
)
);
}
void
print
()
const
{
...
...
@@ -306,7 +306,7 @@ ope * fixed_point128<3> b(a);
}
uint32_t
frac_part
()
const
{
if
(
!
Q
)
return
0
;
return
val
<<
(
32
-
Q
);
return
uint32_t
(
val
<<
(
32
-
Q
)
);
}
void
print
()
const
{
...
...
@@ -576,7 +576,7 @@ ope * fixed_point128<3> b(a);
{
eosio_assert
(
rhs
!=
0
,
"divide by zero"
);
fixed_point64
<
Q
>
result
=
fixed_point32
<
0
>
(
lhs
)
/
fixed_point32
<
0
>
(
rhs
);
fixed_point64
<
Q
>
result
=
fixed_point32
<
0
>
(
(
int32_t
)
lhs
)
/
fixed_point32
<
0
>
((
int32_t
)
rhs
);
return
result
;
}
...
...
@@ -595,7 +595,7 @@ ope * fixed_point128<3> b(a);
{
eosio_assert
(
rhs
!=
0
,
"divide by zero"
);
fixed_point128
<
Q
>
result
=
fixed_point64
<
0
>
(
lhs
)
/
fixed_point64
<
0
>
(
rhs
);
fixed_point128
<
Q
>
result
=
fixed_point64
<
0
>
(
(
int32_t
)
lhs
)
/
fixed_point64
<
0
>
((
int32_t
)
rhs
);
return
fixed_point128
<
Q
>
(
result
);
}
...
...
contracts/eosiolib/print.hpp
浏览文件 @
dbbd9717
/**
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
...
...
@@ -50,7 +50,7 @@ namespace eosio {
}
inline
void
print
(
long
num
)
{
printi
(
num
);
printi
(
uint64_t
(
num
)
);
}
/**
...
...
contracts/eosiolib/real.hpp
浏览文件 @
dbbd9717
...
...
@@ -30,7 +30,7 @@ namespace eosio {
* @brief Constructor to double object from uint64 value
*
* @details Constructor to double object from uint64 value
* @param val data
* @param
_
val data
*/
real
(
const
uint64_t
&
_val
)
:
val
(
_val
)
{}
...
...
contracts/eosiolib/singleton.hpp
浏览文件 @
dbbd9717
...
...
@@ -20,7 +20,7 @@ namespace eosio {
uint64_t
primary_key
()
const
{
return
pk_value
;
}
EOSLIB_SERIALIZE
(
row
,
(
value
)
)
;
EOSLIB_SERIALIZE
(
row
,
(
value
)
)
};
typedef
eosio
::
multi_index
<
SingletonName
,
row
>
table
;
...
...
contracts/identity/identity.hpp
浏览文件 @
dbbd9717
...
...
@@ -155,7 +155,7 @@ namespace identity {
uint64_t
primary_key
()
const
{
return
account
;
}
EOSLIB_SERIALIZE
(
trustrow
,
(
account
)
)
;
EOSLIB_SERIALIZE
(
trustrow
,
(
account
)
)
};
typedef
eosio
::
multi_index
<
N
(
certs
),
certrow
,
...
...
contracts/identity/test/identity_test.cpp
浏览文件 @
dbbd9717
...
...
@@ -25,14 +25,14 @@ namespace identity_test {
{
uint64_t
identity
;
EOSLIB_SERIALIZE
(
get_owner_for_identity
,
(
identity
)
)
;
EOSLIB_SERIALIZE
(
get_owner_for_identity
,
(
identity
)
)
};
struct
get_identity_for_account
:
public
action_meta
<
code
,
N
(
getidentity
)
>
{
account_name
account
;
EOSLIB_SERIALIZE
(
get_identity_for_account
,
(
account
)
)
;
EOSLIB_SERIALIZE
(
get_identity_for_account
,
(
account
)
)
};
typedef
singleton
<
code
,
N
(
result
),
code
,
uint64_t
>
result_table
;
...
...
contracts/noop/noop.hpp
浏览文件 @
dbbd9717
...
...
@@ -7,8 +7,6 @@
#include <eosiolib/eosio.hpp>
#include <eosiolib/dispatcher.hpp>
using
namespace
eosio
;
namespace
noop
{
using
std
::
string
;
...
...
contracts/simpledb/simpledb.cpp
浏览文件 @
dbbd9717
...
...
@@ -35,7 +35,7 @@ namespace simpledb {
int16_t
i16
;
int8_t
i8
;
EOSLIB_SERIALIZE
(
record1
,
(
key
)(
u128
)(
u64
)(
u32
)(
u16
)(
u8
)(
i64
)(
i32
)(
i16
)(
i8
)
)
;
EOSLIB_SERIALIZE
(
record1
,
(
key
)(
u128
)(
u64
)(
u32
)(
u16
)(
u8
)(
i64
)(
i32
)(
i16
)(
i8
)
)
};
//@abi action insert1
...
...
@@ -46,7 +46,7 @@ namespace simpledb {
store_i64
(
N
(
simpledb
),
N
(
record1
),
N
(
simpledb
),
b
.
data
(),
b
.
size
());
}
EOSLIB_SERIALIZE
(
insert_record1
,
(
r1
)
)
;
EOSLIB_SERIALIZE
(
insert_record1
,
(
r1
)
)
};
//@abi action remove1
...
...
@@ -56,7 +56,7 @@ namespace simpledb {
remove_i64
(
N
(
simpledb
),
N
(
record1
),
(
char
*
)
this
);
}
EOSLIB_SERIALIZE
(
remove_record1
,
(
key
)
)
;
EOSLIB_SERIALIZE
(
remove_record1
,
(
key
)
)
};
//@abi table
...
...
@@ -64,7 +64,7 @@ namespace simpledb {
uint128_t
key1
;
uint128_t
key2
;
EOSLIB_SERIALIZE
(
record2
,
(
key1
)(
key2
)
)
;
EOSLIB_SERIALIZE
(
record2
,
(
key1
)(
key2
)
)
};
//@abi action insert2
...
...
@@ -75,7 +75,7 @@ namespace simpledb {
store_i128i128
(
N
(
simpledb
),
N
(
record2
),
N
(
simpledb
),
b
.
data
(),
b
.
size
());
}
EOSLIB_SERIALIZE
(
insert_record2
,
(
r2
)
)
;
EOSLIB_SERIALIZE
(
insert_record2
,
(
r2
)
)
};
//@abi action remove2
...
...
@@ -86,7 +86,7 @@ namespace simpledb {
remove_i128i128
(
N
(
simpledb
),
N
(
record2
),
b
.
data
());
}
EOSLIB_SERIALIZE
(
remove_record2
,
(
key
)
)
;
EOSLIB_SERIALIZE
(
remove_record2
,
(
key
)
)
};
//@abi table
...
...
@@ -95,7 +95,7 @@ namespace simpledb {
uint64_t
key2
;
uint64_t
key3
;
EOSLIB_SERIALIZE
(
record3
,
(
key1
)(
key2
)(
key3
)
)
;
EOSLIB_SERIALIZE
(
record3
,
(
key1
)(
key2
)(
key3
)
)
};
//@abi action insert3
...
...
@@ -106,7 +106,7 @@ namespace simpledb {
store_i128i128
(
N
(
simpledb
),
N
(
record3
),
N
(
simpledb
),
b
.
data
(),
b
.
size
());
}
EOSLIB_SERIALIZE
(
insert_record3
,
(
r3
)
)
;
EOSLIB_SERIALIZE
(
insert_record3
,
(
r3
)
)
};
//@abi action remove3
...
...
@@ -117,7 +117,7 @@ namespace simpledb {
remove_i64i64i64
(
N
(
simpledb
),
N
(
record2
),
b
.
data
());
}
EOSLIB_SERIALIZE
(
remove_record3
,
(
key
)
)
;
EOSLIB_SERIALIZE
(
remove_record3
,
(
key
)
)
};
//@abi table
...
...
@@ -125,7 +125,7 @@ namespace simpledb {
std
::
string
key
;
std
::
string
value
;
EOSLIB_SERIALIZE
(
key_value1
,
(
key
)(
value
)
)
;
EOSLIB_SERIALIZE
(
key_value1
,
(
key
)(
value
)
)
};
//@abi action insertkv1
...
...
@@ -137,7 +137,7 @@ namespace simpledb {
// store_str( N(simpledb), N(keyvalue1), N(simpledb), (char *)kv1.key.data(), kv1.key.size(), b.data(), b.size());
}
EOSLIB_SERIALIZE
(
insert_keyvalue1
,
(
kv1
)
)
;
EOSLIB_SERIALIZE
(
insert_keyvalue1
,
(
kv1
)
)
};
//@abi action removekv1
...
...
@@ -148,14 +148,14 @@ namespace simpledb {
//remove_str( N(simpledb), N(keyvalue1), (char *)key.data(), key.size() );
}
EOSLIB_SERIALIZE
(
remove_keyvalue1
,
(
key
)
)
;
EOSLIB_SERIALIZE
(
remove_keyvalue1
,
(
key
)
)
};
struct
complex_type
{
std
::
string
name
;
uint64_t
age
;
EOSLIB_SERIALIZE
(
complex_type
,
(
name
)(
age
)
)
;
EOSLIB_SERIALIZE
(
complex_type
,
(
name
)(
age
)
)
};
//@abi table
...
...
@@ -163,7 +163,7 @@ namespace simpledb {
std
::
string
key
;
complex_type
value
;
EOSLIB_SERIALIZE
(
key_value2
,
(
key
)(
value
)
)
;
EOSLIB_SERIALIZE
(
key_value2
,
(
key
)(
value
)
)
};
//@abi action insertkv2
...
...
@@ -175,7 +175,7 @@ namespace simpledb {
// store_str( N(simpledb), N(keyvalue2), N(simpledb), (char *)kv2.key.data(), kv2.key.size(), b.data(), b.size());
}
EOSLIB_SERIALIZE
(
insert_keyvalue2
,
(
kv2
)
)
;
EOSLIB_SERIALIZE
(
insert_keyvalue2
,
(
kv2
)
)
};
//@abi action removekv2
...
...
@@ -185,7 +185,7 @@ namespace simpledb {
remove_str
(
N
(
simpledb
),
N
(
keyvalue2
),
(
char
*
)
key
.
data
(),
key
.
size
()
);
}
EOSLIB_SERIALIZE
(
remove_keyvalue2
,
(
key
)
)
;
EOSLIB_SERIALIZE
(
remove_keyvalue2
,
(
key
)
)
};
template
<
typename
...
Ts
>
...
...
contracts/test_api/test_action.cpp
浏览文件 @
dbbd9717
...
...
@@ -38,11 +38,11 @@ void test_action::read_action_normal() {
}
void
test_action
::
read_action_to_0
()
{
uint32_t
total
=
read_action
((
void
*
)
0
,
action_size
());
read_action
((
void
*
)
0
,
action_size
());
}
void
test_action
::
read_action_to_64k
()
{
uint32_t
total
=
read_action
(
(
void
*
)((
1
<<
16
)
-
2
),
action_size
());
read_action
(
(
void
*
)((
1
<<
16
)
-
2
),
action_size
());
}
void
test_action
::
require_notice
()
{
...
...
contracts/test_api/test_api.cpp
浏览文件 @
dbbd9717
...
...
@@ -23,7 +23,7 @@ extern "C" {
}
void
apply
(
unsigned
long
long
code
,
unsigned
long
long
action
)
{
void
apply
(
unsigned
long
long
,
unsigned
long
long
action
)
{
//eosio::print("==> CONTRACT: ", code, " ", action, "\n");
//test_types
WASM_TEST_HANDLER
(
test_types
,
types_size
);
...
...
contracts/test_api/test_api.hpp
浏览文件 @
dbbd9717
...
...
@@ -69,7 +69,7 @@ struct test_action {
static
void
assert_false
();
static
void
assert_true
();
static
void
now
();
static
void
test_abort
();
static
void
test_abort
()
__attribute__
((
noreturn
))
;
static
void
test_current_receiver
();
static
void
test_current_sender
();
static
void
test_publication_time
();
...
...
contracts/test_api/test_compiler_builtins.cpp
浏览文件 @
dbbd9717
...
...
@@ -9,7 +9,6 @@
#include "test_api.hpp"
using
namespace
eosio
;
unsigned
__int128
operator
""
_ULLL
(
const
char
*
lit
)
{
__int128
ret
=
0
;
size_t
i
=
0
;
...
...
@@ -32,7 +31,7 @@ unsigned __int128 operator "" _ULLL( const char* lit ) {
if
(
sign
)
ret
*=
-
1
;
return
ret
;
return
(
unsigned
__int128
)
ret
;
}
__int128
operator
""
_LLL
(
const
char
*
lit
)
{
...
...
@@ -70,28 +69,28 @@ void test_compiler_builtins::test_multi3() {
__int128
lhs_b
=
100
;
__int128
rhs_b
=
-
30
;
__multi3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__multi3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
-
3000
,
"__multi3 result should be -3000"
);
__multi3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__multi3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
-
3000
,
"__multi3 result should be -3000"
);
__multi3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__multi3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
900
,
"__multi3 result should be 900"
);
/*
* test for positive values
*/
__multi3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__multi3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
10000
,
"__multi3 result should be 10000"
);
/*
* test identity
*/
__multi3
(
res
,
1
,
0
,
rhs_a
,
rhs_a
>>
64
);
__multi3
(
res
,
1
,
0
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
100
,
"__multi3 result should be 100"
);
__multi3
(
res
,
1
,
0
,
rhs_b
,
rhs_b
>>
64
);
__multi3
(
res
,
1
,
0
,
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
-
30
,
"__multi3 result should be -30"
);
}
...
...
@@ -105,13 +104,13 @@ void test_compiler_builtins::test_divti3() {
__int128
lhs_b
=
100
;
__int128
rhs_b
=
-
30
;
__divti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
0
,
"__divti3 result should be 0"
);
__divti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
-
3
,
"__divti3 result should be -3"
);
__divti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
1
,
"__divti3 result should be 1"
);
/*
...
...
@@ -120,22 +119,22 @@ void test_compiler_builtins::test_divti3() {
__int128
lhs_c
=
3333
;
__int128
rhs_c
=
3333
;
__divti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
1
,
"__divti3 result should be 1"
);
__divti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_c
,
(
rhs_c
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_c
),
uint64_t
(
rhs_c
>>
64
)
);
eosio_assert
(
res
==
0
,
"__divti3 result should be 0"
);
__divti3
(
res
,
lhs_c
,
(
lhs_c
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__divti3
(
res
,
uint64_t
(
lhs_c
),
uint64_t
(
lhs_c
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
33
,
"__divti3 result should be 33"
);
/*
* test identity
*/
__divti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
1
,
0
);
__divti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
1
,
0
);
eosio_assert
(
res
==
100
,
"__divti3 result should be 100"
);
__divti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
1
,
0
);
__divti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
1
,
0
);
eosio_assert
(
res
==
-
30
,
"__divti3 result should be -30"
);
}
...
...
@@ -147,22 +146,22 @@ void test_compiler_builtins::test_divti3_by_0() {
}
void
test_compiler_builtins
::
test_udivti3
()
{
/*
/*
* test for negative values
*/
unsigned
__int128
res
=
0
;
unsigned
__int128
lhs_a
=
-
30
;
unsigned
__int128
lhs_a
=
(
unsigned
__int128
)
-
30
;
unsigned
__int128
rhs_a
=
100
;
unsigned
__int128
lhs_b
=
100
;
unsigned
__int128
rhs_b
=
-
30
;
unsigned
__int128
rhs_b
=
(
unsigned
__int128
)
-
30
;
__udivti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
3402823669209384634633746074317682114
_ULLL
,
"__udivti3 result should be 0"
);
__udivti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
0
,
"__udivti3 result should be 0"
);
__udivti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
rhs_b
,
(
rhs_b
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
1
,
"__udivti3 result should be 1"
);
/*
...
...
@@ -171,23 +170,23 @@ void test_compiler_builtins::test_udivti3() {
__int128
lhs_c
=
3333
;
__int128
rhs_c
=
3333
;
__udivti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
1
,
"__divti3 result should be 1"
);
__udivti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
rhs_c
,
(
rhs_c
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_c
),
uint64_t
(
rhs_c
>>
64
)
);
eosio_assert
(
res
==
0
,
"__divti3 result should be 0"
);
__udivti3
(
res
,
lhs_c
,
(
lhs_c
>>
64
),
rhs_a
,
(
rhs_a
>>
64
)
);
__udivti3
(
res
,
uint64_t
(
lhs_c
),
uint64_t
(
lhs_c
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
33
,
"__divti3 result should be 33"
);
/*
* test identity
*/
__udivti3
(
res
,
lhs_b
,
(
lhs_b
>>
64
),
1
,
0
);
__udivti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
1
,
0
);
eosio_assert
(
res
==
100
,
"__divti3 result should be 100"
);
__udivti3
(
res
,
lhs_a
,
(
lhs_a
>>
64
),
1
,
0
);
eosio_assert
(
res
==
-
30
,
"__divti3 result should be -30"
);
__udivti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
1
,
0
);
eosio_assert
(
res
==
(
unsigned
__int128
)
-
30
,
"__divti3 result should be -30"
);
}
void
test_compiler_builtins
::
test_udivti3_by_0
()
{
...
...
@@ -207,27 +206,27 @@ void test_compiler_builtins::test_lshlti3() {
test_res
<<=
1
;
__lshlti3
(
res
,
val
,
val
>>
64
,
0
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
)
,
0
);
eosio_assert
(
res
==
1
,
"__lshlti3 result should be 1"
);
__lshlti3
(
res
,
val
,
val
>>
64
,
1
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
)
,
1
);
eosio_assert
(
res
==
(
1
<<
1
),
"__lshlti3 result should be 2"
);
__lshlti3
(
res
,
val
,
(
val
>>
64
),
31
);
eosio_assert
(
res
==
2147483648
_ULLL
,
"__lshlti3 result should be 2^31"
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
31
);
eosio_assert
(
(
unsigned
__int128
)
res
==
2147483648
_ULLL
,
"__lshlti3 result should be 2^31"
);
__lshlti3
(
res
,
val
,
(
val
>>
64
),
63
);
eosio_assert
(
res
==
9223372036854775808
_ULLL
,
"__lshlti3 result should be 2^63"
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
63
);
eosio_assert
(
(
unsigned
__int128
)
res
==
9223372036854775808
_ULLL
,
"__lshlti3 result should be 2^63"
);
__lshlti3
(
res
,
val
,
(
val
>>
64
),
64
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
64
);
eosio_assert
(
res
==
test_res
,
"__lshlti3 result should be 2^64"
);
__lshlti3
(
res
,
val
,
(
val
>>
64
),
127
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
127
);
test_res
<<=
63
;
eosio_assert
(
res
==
test_res
,
"__lshlti3 result should be 2^127"
);
__lshlti3
(
res
,
val
,
(
val
>>
64
),
128
);
__lshlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
128
);
test_res
<<=
1
;
//should rollover
eosio_assert
(
res
==
test_res
,
"__lshlti3 result should be 2^128"
);
...
...
@@ -241,27 +240,27 @@ void test_compiler_builtins::test_ashlti3() {
test_res
=
0x8000000000000000
;
test_res
<<=
1
;
__ashlti3
(
res
,
val
,
val
>>
64
,
0
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
)
,
0
);
eosio_assert
(
res
==
1
,
"__ashlti3 result should be 1"
);
__ashlti3
(
res
,
val
,
val
>>
64
,
1
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
)
,
1
);
eosio_assert
(
res
==
(
1
<<
1
),
"__ashlti3 result should be 2"
);
__ashlti3
(
res
,
val
,
(
val
>>
64
),
31
);
eosio_assert
(
res
==
2147483648
_ULLL
,
"__ashlti3 result should be 2^31"
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
31
);
eosio_assert
(
res
==
(
__int128
)
2147483648
_ULLL
,
"__ashlti3 result should be 2^31"
);
__ashlti3
(
res
,
val
,
(
val
>>
64
),
63
);
eosio_assert
(
res
==
9223372036854775808
_ULLL
,
"__ashlti3 result should be 2^63"
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
63
);
eosio_assert
(
res
==
(
__int128
)
9223372036854775808
_ULLL
,
"__ashlti3 result should be 2^63"
);
__ashlti3
(
res
,
val
,
(
val
>>
64
),
64
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
64
);
eosio_assert
(
res
==
test_res
,
"__ashlti3 result should be 2^64"
);
__ashlti3
(
res
,
val
,
(
val
>>
64
),
127
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
127
);
test_res
<<=
63
;
eosio_assert
(
res
==
test_res
,
"__ashlti3 result should be 2^127"
);
__ashlti3
(
res
,
val
,
(
val
>>
64
),
128
);
__ashlti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
128
);
test_res
<<=
1
;
//should rollover
eosio_assert
(
res
==
test_res
,
"__ashlti3 result should be 2^128"
);
...
...
@@ -276,22 +275,22 @@ void test_compiler_builtins::test_lshrti3() {
val
<<=
64
;
test_res
<<=
64
;
__lshrti3
(
res
,
val
,
(
val
>>
64
),
0
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
0
);
eosio_assert
(
res
==
test_res
,
"__lshrti3 result should be 2^127"
);
__lshrti3
(
res
,
val
,
(
val
>>
64
),
1
);
eosio_assert
(
res
==
85070591730234615865843651857942052864
_ULLL
,
"__lshrti3 result should be 2^126"
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
1
);
eosio_assert
(
res
==
(
__int128
)
85070591730234615865843651857942052864
_ULLL
,
"__lshrti3 result should be 2^126"
);
__lshrti3
(
res
,
val
,
(
val
>>
64
),
63
);
eosio_assert
(
res
==
18446744073709551616
_ULLL
,
"__lshrti3 result should be 2^64"
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
63
);
eosio_assert
(
res
==
(
__int128
)
18446744073709551616
_ULLL
,
"__lshrti3 result should be 2^64"
);
__lshrti3
(
res
,
val
,
(
val
>>
64
),
64
);
eosio_assert
(
res
==
9223372036854775808
_ULLL
,
"__lshrti3 result should be 2^63"
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
64
);
eosio_assert
(
res
==
(
__int128
)
9223372036854775808
_ULLL
,
"__lshrti3 result should be 2^63"
);
__lshrti3
(
res
,
val
,
(
val
>>
64
),
96
);
eosio_assert
(
res
==
2147483648
_ULLL
,
"__lshrti3 result should be 2^31"
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
96
);
eosio_assert
(
res
==
(
__int128
)
2147483648
_ULLL
,
"__lshrti3 result should be 2^31"
);
__lshrti3
(
res
,
val
,
(
val
>>
64
),
127
);
__lshrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
127
);
eosio_assert
(
res
==
0x1
,
"__lshrti3 result should be 2^0"
);
}
...
...
@@ -302,22 +301,22 @@ void test_compiler_builtins::test_ashrti3() {
test
<<=
127
;
__ashrti3
(
res
,
val
,
(
val
>>
64
),
0
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
0
);
eosio_assert
(
res
==
-
170141183460469231731687303715884105728
_LLL
,
"__ashrti3 result should be -2^127"
);
__ashrti3
(
res
,
val
,
(
val
>>
64
),
1
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
1
);
eosio_assert
(
res
==
-
85070591730234615865843651857942052864
_LLL
,
"__ashrti3 result should be -2^126"
);
__ashrti3
(
res
,
val
,
(
val
>>
64
),
2
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
2
);
eosio_assert
(
res
==
test
>>
2
,
"__ashrti3 result should be -2^125"
);
__ashrti3
(
res
,
val
,
(
val
>>
64
),
64
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
64
);
eosio_assert
(
res
==
test
>>
64
,
"__ashrti3 result should be -2^63"
);
__ashrti3
(
res
,
val
,
(
val
>>
64
),
95
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
95
);
eosio_assert
(
res
==
test
>>
95
,
"__ashrti3 result should be -2^31"
);
__ashrti3
(
res
,
val
,
(
val
>>
64
),
127
);
__ashrti3
(
res
,
uint64_t
(
val
),
uint64_t
(
val
>>
64
),
127
);
eosio_assert
(
res
==
test
>>
127
,
"__ashrti3 result should be -2^0"
);
}
...
...
@@ -329,25 +328,25 @@ void test_compiler_builtins::test_modti3() {
__int128
lhs_b
=
30
;
__int128
rhs_b
=
-
100
;
__modti3
(
res
,
lhs_a
,
lhs_a
>>
64
,
rhs_a
,
rhs_a
>>
64
);
__modti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
-
30
,
"__modti3 result should be -30"
);
__modti3
(
res
,
lhs_b
,
lhs_b
>>
64
,
rhs_b
,
rhs_b
>>
64
);
__modti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
30
,
"__modti3 result should be 30"
);
__modti3
(
res
,
lhs_a
,
lhs_a
>>
64
,
rhs_b
,
rhs_b
>>
64
);
__modti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
-
30
,
"__modti3 result should be -30"
);
__modti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
lhs_b
,
lhs_b
>>
64
);
__modti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
)
);
eosio_assert
(
res
==
10
,
"__modti3 result should be 10"
);
__modti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
rhs_b
,
rhs_b
>>
64
);
__modti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
__modti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
rhs_a
,
rhs_a
>>
64
);
__modti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
__modti3
(
res
,
0
,
0
,
rhs_a
,
rhs_a
>>
64
);
__modti3
(
res
,
0
,
0
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
}
...
...
@@ -355,36 +354,36 @@ void test_compiler_builtins::test_modti3_by_0() {
__int128
res
=
0
;
__int128
lhs
=
100
;
__modti3
(
res
,
lhs
,
lhs
>>
64
,
0
,
0
);
__modti3
(
res
,
uint64_t
(
lhs
),
uint64_t
(
lhs
>>
64
)
,
0
,
0
);
eosio_assert
(
false
,
"should have thrown an error"
);
}
void
test_compiler_builtins
::
test_umodti3
()
{
unsigned
__int128
res
=
0
;
unsigned
__int128
lhs_a
=
-
30
;
unsigned
__int128
lhs_a
=
(
unsigned
__int128
)
-
30
;
unsigned
__int128
rhs_a
=
100
;
unsigned
__int128
lhs_b
=
30
;
unsigned
__int128
rhs_b
=
-
100
;
unsigned
__int128
rhs_b
=
(
unsigned
__int128
)
-
100
;
__umodti3
(
res
,
lhs_a
,
lhs_a
>>
64
,
rhs_a
,
rhs_a
>>
64
);
eosio_assert
(
res
==
-
30
,
"__modti3 result should be -30"
);
__umodti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
(
unsigned
__int128
)
-
30
,
"__modti3 result should be -30"
);
__umodti3
(
res
,
lhs_b
,
lhs_b
>>
64
,
rhs_b
,
rhs_b
>>
64
);
__umodti3
(
res
,
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
30
,
"__modti3 result should be 30"
);
__umodti3
(
res
,
lhs_a
,
lhs_a
>>
64
,
rhs_b
,
rhs_b
>>
64
);
eosio_assert
(
res
==
-
30
,
"__modti3 result should be -30"
);
__umodti3
(
res
,
uint64_t
(
lhs_a
),
uint64_t
(
lhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
(
unsigned
__int128
)
-
30
,
"__modti3 result should be -30"
);
__umodti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
lhs_b
,
lhs_b
>>
64
);
__umodti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
lhs_b
),
uint64_t
(
lhs_b
>>
64
)
);
eosio_assert
(
res
==
10
,
"__modti3 result should be 10"
);
__umodti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
rhs_b
,
rhs_b
>>
64
);
__umodti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
rhs_b
),
uint64_t
(
rhs_b
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
__umodti3
(
res
,
rhs_a
,
rhs_a
>>
64
,
rhs_a
,
rhs_a
>>
64
);
__umodti3
(
res
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
),
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
__umodti3
(
res
,
0
,
0
,
rhs_a
,
rhs_a
>>
64
);
__umodti3
(
res
,
0
,
0
,
uint64_t
(
rhs_a
),
uint64_t
(
rhs_a
>>
64
)
);
eosio_assert
(
res
==
0
,
"__modti3 result should be 0"
);
}
...
...
@@ -392,6 +391,6 @@ void test_compiler_builtins::test_umodti3_by_0() {
unsigned
__int128
res
=
0
;
unsigned
__int128
lhs
=
100
;
__umodti3
(
res
,
lhs
,
lhs
>>
64
,
0
,
0
);
__umodti3
(
res
,
uint64_t
(
lhs
),
uint64_t
(
lhs
>>
64
)
,
0
,
0
);
eosio_assert
(
false
,
"should have thrown an error"
);
}
contracts/test_api/test_crypto.cpp
浏览文件 @
dbbd9717
...
...
@@ -193,24 +193,23 @@ struct sig_hash_key {
void
test_crypto
::
test_recover_key_assert_true
()
{
sig_hash_key
sh
;
int
read
=
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
public_key
public_key
;
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
assert_recover_key
(
&
sh
.
hash
,
(
const
char
*
)
&
sh
.
sig
,
sizeof
(
sh
.
sig
),
(
const
char
*
)
&
sh
.
pk
,
sizeof
(
sh
.
pk
)
);
}
void
test_crypto
::
test_recover_key_assert_false
()
{
sig_hash_key
sh
;
int
read
=
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
assert_recover_key
(
&
sh
.
hash
,
(
const
char
*
)
&
sh
.
sig
,
sizeof
(
sh
.
sig
),
(
const
char
*
)
&
sh
.
pk
,
sizeof
(
sh
.
pk
)
);
eosio_assert
(
false
,
"should have thrown an error"
);
}
void
test_crypto
::
test_recover_key
()
{
sig_hash_key
sh
;
int
read
=
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
read_action
(
(
char
*
)
&
sh
,
sizeof
(
sh
)
);
public_key
pk
;
int
recovered
=
recover_key
(
&
sh
.
hash
,
(
const
char
*
)
&
sh
.
sig
,
sizeof
(
sh
.
sig
),
pk
.
data
,
sizeof
(
pk
)
);
for
(
in
t
i
=
0
;
i
<
sizeof
(
pk
);
i
++
)
recover_key
(
&
sh
.
hash
,
(
const
char
*
)
&
sh
.
sig
,
sizeof
(
sh
.
sig
),
pk
.
data
,
sizeof
(
pk
)
);
for
(
uint32_
t
i
=
0
;
i
<
sizeof
(
pk
);
i
++
)
if
(
pk
.
data
[
i
]
!=
sh
.
pk
.
data
[
i
]
)
eosio_assert
(
false
,
"public key does not match"
);
}
...
...
@@ -284,8 +283,6 @@ void test_crypto::test_ripemd160() {
void
test_crypto
::
sha256_null
()
{
checksum256
tmp
;
int
a
=
3
;
int
*
b
=
&
a
;
sha256
(
nullptr
,
100
,
&
tmp
);
//eosio_assert(false, "should've thrown an error");
}
...
...
contracts/test_api/test_fixedpoint.cpp
浏览文件 @
dbbd9717
...
...
@@ -2,85 +2,85 @@
#include <eosiolib/eosio.hpp>
#include "test_api.hpp"
using
namespace
eosio
;
void
test_fixedpoint
::
create_instances
()
{
{
// Various ways to create fixed_point128
fixed_point128
<
18
>
a
(
12345667
);
fixed_point128
<
18
>
b
(
12345667
);
fixed_point128
<
16
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point128 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point128 instances with different number of decimals"
);
eosio
::
fixed_point128
<
18
>
a
(
12345667
);
eosio
::
fixed_point128
<
18
>
b
(
12345667
);
eosio
::
fixed_point128
<
16
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point128 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point128 instances with different number of decimals"
);
}
{
// Various ways to create fixed_point64
fixed_point64
<
5
>
a
(
12345667
);
fixed_point64
<
5
>
b
(
12345667
);
fixed_point64
<
5
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point64 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point64 instances with different number of decimals"
);
eosio
::
fixed_point64
<
5
>
a
(
12345667
);
eosio
::
fixed_point64
<
5
>
b
(
12345667
);
eosio
::
fixed_point64
<
5
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point64 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point64 instances with different number of decimals"
);
}
{
// Various ways to create fixed_point32
fixed_point32
<
18
>
a
(
12345667
);
fixed_point32
<
18
>
b
(
12345667
);
fixed_point32
<
16
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point32 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point32 instances with different number of decimals"
);
eosio
::
fixed_point32
<
18
>
a
(
12345667
);
eosio
::
fixed_point32
<
18
>
b
(
12345667
);
eosio
::
fixed_point32
<
16
>
c
(
12345667
);
eosio_assert
(
b
==
a
,
"fixed_point32 instances comparison with same number of decimals"
);
eosio_assert
(
c
==
a
,
"fixed_point32 instances with different number of decimals"
);
}
}
void
test_fixedpoint
::
test_addition
()
{
{
// Various ways to create fixed_point32
fixed_point32
<
0
>
a
(
100
);
fixed_point32
<
0
>
b
(
100
);
fixed_point32
<
0
>
c
=
a
+
b
;
fixed_point32
<
0
>
d
=
200
;
eosio_assert
(
c
==
d
,
"fixed_point32 instances addition with zero decmimals"
);
// Various ways to create fixed_point32
eosio
::
fixed_point32
<
0
>
a
(
100
);
eosio
::
fixed_point32
<
0
>
b
(
100
);
eosio
::
fixed_point32
<
0
>
c
=
a
+
b
;
eosio
::
fixed_point32
<
0
>
d
=
200
;
eosio_assert
(
c
==
d
,
"fixed_point32 instances addition with zero decmimals"
);
}
{
// Various ways to create fixed_point64
fixed_point64
<
0
>
a
(
100
);
fixed_point64
<
0
>
b
(
100
);
fixed_point64
<
0
>
c
=
a
+
b
;
fixed_point64
<
0
>
d
=
200
;
eosio_assert
(
c
==
d
,
"fixed_point64 instances addition with zero decmimals"
);
// Various ways to create fixed_point64
eosio
::
fixed_point64
<
0
>
a
(
100
);
eosio
::
fixed_point64
<
0
>
b
(
100
);
eosio
::
fixed_point64
<
0
>
c
=
a
+
b
;
eosio
::
fixed_point64
<
0
>
d
=
200
;
eosio_assert
(
c
==
d
,
"fixed_point64 instances addition with zero decmimals"
);
}
};
void
test_fixedpoint
::
test_subtraction
()
{
{
// Various ways to create fixed_point64
fixed_point64
<
0
>
a
(
100
);
fixed_point64
<
0
>
b
(
100
);
fixed_point64
<
0
>
c
=
a
-
b
;
fixed_point64
<
0
>
d
=
0
;
eosio_assert
(
c
==
d
,
"fixed_point64 instances subtraction with zero decmimals"
);
fixed_point64
<
0
>
a1
(
0
);
fixed_point64
<
0
>
c1
=
a1
-
b
;
fixed_point64
<
0
>
d1
=
-
100
;
eosio_assert
(
c1
==
d1
,
"fixed_point64 instances subtraction with zero decmimals"
);
// Various ways to create fixed_point64
eosio
::
fixed_point64
<
0
>
a
(
100
);
eosio
::
fixed_point64
<
0
>
b
(
100
);
eosio
::
fixed_point64
<
0
>
c
=
a
-
b
;
eosio
::
fixed_point64
<
0
>
d
=
0
;
eosio_assert
(
c
==
d
,
"fixed_point64 instances subtraction with zero decmimals"
);
eosio
::
fixed_point64
<
0
>
a1
(
0
);
eosio
::
fixed_point64
<
0
>
c1
=
a1
-
b
;
eosio
::
fixed_point64
<
0
>
d1
=
-
100
;
eosio_assert
(
c1
==
d1
,
"fixed_point64 instances subtraction with zero decmimals"
);
}
{
// Various ways to create fixed_point32
fixed_point32
<
0
>
a
(
100
);
fixed_point32
<
0
>
b
(
100
);
fixed_point32
<
0
>
c
=
a
-
b
;
fixed_point32
<
0
>
d
=
0
;
eosio_assert
(
c
==
d
,
"fixed_point32 instances subtraction with zero decmimals"
);
// Various ways to create fixed_point32
fixed_point32
<
0
>
a1
(
0
);
fixed_point32
<
0
>
c1
=
a1
-
b
;
fixed_point32
<
0
>
d1
=
-
100
;
eosio_assert
(
c1
==
d1
,
"fixed_point32 instances subtraction with zero decmimals"
);
// Various ways to create fixed_point32
eosio
::
fixed_point32
<
0
>
a
(
100
);
eosio
::
fixed_point32
<
0
>
b
(
100
);
eosio
::
fixed_point32
<
0
>
c
=
a
-
b
;
eosio
::
fixed_point32
<
0
>
d
=
0
;
eosio_assert
(
c
==
d
,
"fixed_point32 instances subtraction with zero decmimals"
);
// Various ways to create fixed_point32
eosio
::
fixed_point32
<
0
>
a1
(
0
);
eosio
::
fixed_point32
<
0
>
c1
=
a1
-
b
;
eosio
::
fixed_point32
<
0
>
d1
=
-
100
;
eosio_assert
(
c1
==
d1
,
"fixed_point32 instances subtraction with zero decmimals"
);
}
};
...
...
@@ -88,21 +88,21 @@ void test_fixedpoint::test_subtraction()
void
test_fixedpoint
::
test_multiplication
()
{
{
// Various ways to create fixed_point64
fixed_point64
<
0
>
a
(
100
);
fixed_point64
<
0
>
b
(
200
);
fixed_point128
<
0
>
c
=
a
*
b
;
fixed_point128
<
0
>
d
(
200
*
100
);
eosio_assert
(
c
==
d
,
"fixed_point64 instances multiplication result in fixed_point128"
);
// Various ways to create fixed_point64
eosio
::
fixed_point64
<
0
>
a
(
100
);
eosio
::
fixed_point64
<
0
>
b
(
200
);
eosio
::
fixed_point128
<
0
>
c
=
a
*
b
;
eosio
::
fixed_point128
<
0
>
d
(
200
*
100
);
eosio_assert
(
c
==
d
,
"fixed_point64 instances multiplication result in fixed_point128"
);
}
{
// Various ways to create fixed_point32
fixed_point32
<
0
>
a
(
100
);
fixed_point32
<
0
>
b
(
200
);
fixed_point64
<
0
>
c
=
a
*
b
;
fixed_point64
<
0
>
d
(
200
*
100
);
eosio_assert
(
c
==
d
,
"fixed_point32 instances multiplication result in fixed_point64"
);
// Various ways to create fixed_point32
eosio
::
fixed_point32
<
0
>
a
(
100
);
eosio
::
fixed_point32
<
0
>
b
(
200
);
eosio
::
fixed_point64
<
0
>
c
=
a
*
b
;
eosio
::
fixed_point64
<
0
>
d
(
200
*
100
);
eosio_assert
(
c
==
d
,
"fixed_point32 instances multiplication result in fixed_point64"
);
}
}
...
...
@@ -112,11 +112,11 @@ void test_fixedpoint::test_division()
uint64_t
lhs
=
10000000
;
uint64_t
rhs
=
333
;
fixed_point64
<
0
>
a
(
lhs
);
fixed_point64
<
0
>
b
(
rhs
);
fixed_point128
<
5
>
c
=
a
/
b
;
eosio
::
fixed_point64
<
0
>
a
((
int64_t
)
lhs
);
eosio
::
fixed_point64
<
0
>
b
((
int64_t
)
rhs
);
eosio
::
fixed_point128
<
5
>
c
=
a
/
b
;
fixed_point128
<
5
>
e
=
fixed_divide
<
5
>
(
lhs
,
rhs
);
eosio
::
fixed_point128
<
5
>
e
=
eosio
::
fixed_divide
<
5
>
(
lhs
,
rhs
);
print
(
e
);
eosio_assert
(
c
==
e
,
"fixed_point64 instances division result from operator and function and compare in fixed_point128"
);
...
...
@@ -126,11 +126,11 @@ void test_fixedpoint::test_division()
uint32_t
lhs
=
100000
;
uint32_t
rhs
=
33
;
fixed_point32
<
0
>
a
(
lhs
);
fixed_point32
<
0
>
b
(
rhs
);
fixed_point64
<
5
>
c
=
a
/
b
;
eosio
::
fixed_point32
<
0
>
a
((
int32_t
)
lhs
);
eosio
::
fixed_point32
<
0
>
b
((
int32_t
)
rhs
);
eosio
::
fixed_point64
<
5
>
c
=
a
/
b
;
fixed_point64
<
5
>
e
=
fixed_divide
<
5
>
(
lhs
,
rhs
);
eosio
::
fixed_point64
<
5
>
e
=
eosio
::
fixed_divide
<
5
>
(
lhs
,
rhs
);
eosio_assert
(
c
==
e
,
"fixed_point64 instances division result from operator and function and compare in fixed_point128"
);
}
...
...
@@ -142,10 +142,12 @@ 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
);
eosio
::
fixed_point64
<
0
>
a
((
int64_t
)
lhs
);
eosio
::
fixed_point64
<
0
>
b
((
int64_t
)
rhs
);
fixed_point128
<
5
>
e
=
fixed_divide
<
5
>
(
lhs
,
rhs
);
eosio
::
fixed_point128
<
5
>
e
=
eosio
::
fixed_divide
<
5
>
(
lhs
,
rhs
);
// in order to get rid of unused parameter warning
e
=
0
;
eosio_assert
(
false
,
"should've thrown an error"
);
}
...
...
contracts/test_api/test_math.cpp
浏览文件 @
dbbd9717
...
...
@@ -4,8 +4,6 @@
#include "test_api.hpp"
using
namespace
eosio
;
void
test_math
::
test_multeq
()
{
u128_action
act
;
auto
n
=
read_action
(
&
act
,
sizeof
(
u128_action
));
...
...
@@ -44,13 +42,13 @@ void test_math::test_i64_to_double()
uint64_t
d
=
i64_to_double
(
2
);
eosio_assert
(
i
[
0
]
==
d
,
"test_i64_to_double i[0] == d"
);
d
=
i64_to_double
(
-
2
);
d
=
i64_to_double
(
uint64_t
(
-
2
)
);
eosio_assert
(
i
[
1
]
==
d
,
"test_i64_to_double i[1] == d"
);
d
=
i64_to_double
(
100000
);
eosio_assert
(
i
[
2
]
==
d
,
"test_i64_to_double i[2] == d"
);
d
=
i64_to_double
(
-
100000
);
d
=
i64_to_double
(
uint64_t
(
-
100000
)
);
eosio_assert
(
i
[
3
]
==
d
,
"test_i64_to_double i[3] == d"
);
d
=
i64_to_double
(
0
);
...
...
@@ -62,19 +60,19 @@ void test_math::test_double_to_i64()
uint64_t
d
[
4
];
read_action
(
&
d
,
sizeof
(
d
));
int64_t
i
=
double_to_i64
(
d
[
0
]);
int64_t
i
=
(
int64_t
)
double_to_i64
(
d
[
0
]);
eosio_assert
(
2
==
i
,
"test_double_to_i64 2 == i"
);
i
=
double_to_i64
(
d
[
1
]);
i
=
(
int64_t
)
double_to_i64
(
d
[
1
]);
eosio_assert
(
-
2
==
i
,
"test_double_to_i64 -2 == i"
);
i
=
double_to_i64
(
d
[
2
]);
i
=
(
int64_t
)
double_to_i64
(
d
[
2
]);
eosio_assert
(
100000
==
i
,
"test_double_to_i64 100000 == i"
);
i
=
double_to_i64
(
d
[
3
]);
i
=
(
int64_t
)
double_to_i64
(
d
[
3
]);
eosio_assert
(
-
100000
==
i
,
"test_double_to_i64 -100000 == i"
);
i
=
double_to_i64
(
0
);
i
=
(
int64_t
)
double_to_i64
(
0
);
eosio_assert
(
0
==
i
,
"test_double_to_i64 0 == i"
);
}
...
...
@@ -112,7 +110,7 @@ void test_math::test_double_api() {
void
test_math
::
test_double_api_div_0
()
{
double_div
(
i64_to_double
(
1
),
double_add
(
i64_to_double
(
-
5
),
i64_to_double
(
5
)
i64_to_double
((
uint64_t
)
-
5
),
i64_to_double
(
5
)
));
eosio_assert
(
false
,
"should've thrown an error"
);
...
...
contracts/test_api/test_print.cpp
浏览文件 @
dbbd9717
...
...
@@ -5,7 +5,8 @@
#include <eosiolib/eosio.hpp>
#include "test_api.hpp"
using
namespace
eosio
;
//using namespace eosio;
void
test_print
::
test_prints_l
()
{
char
ab
[]
=
{
'a'
,
'b'
};
...
...
@@ -17,22 +18,22 @@ void test_print::test_prints_l() {
}
void
test_print
::
test_prints
()
{
prints
(
"ab"
);
prints
(
nullptr
);
prints
(
"c
\0
test_prints"
);
prints
(
0
);
prints
(
"efg"
);
prints
(
0
);
prints
(
"ab"
);
prints
(
nullptr
);
prints
(
"c
\0
test_prints"
);
prints
(
0
);
prints
(
"efg"
);
prints
(
0
);
}
void
test_print
::
test_printi
()
{
printi
(
0
);
printi
(
556644
);
printi
(
-
1
);
printi
(
0
);
printi
(
556644
);
printi
((
uint64_t
)
-
1
);
}
void
test_print
::
test_printi128
()
{
uint128_t
a
(
-
1
);
uint128_t
a
(
(
uint128_t
)
-
1
);
uint128_t
b
(
0
);
uint128_t
c
(
87654323456
);
printi128
(
&
a
);
...
...
@@ -41,14 +42,14 @@ void test_print::test_printi128() {
}
void
test_print
::
test_printn
()
{
printn
(
N
(
abcde
));
printn
(
N
(
abBde
));
printn
(
N
(
1
q1q1qAA
));
printn
(
N
());
printn
(
N
(
AAAAAA
));
printn
(
N
(
abcdefghijk
));
printn
(
N
(
abcdefghijkl
));
printn
(
N
(
abcdefghijkl1
));
printn
(
N
(
abcdefghijkl12
));
printn
(
N
(
abcdefghijkl123
));
printn
(
N
(
abcde
));
printn
(
N
(
abBde
));
printn
(
N
(
1
q1q1qAA
));
printn
(
N
());
printn
(
N
(
AAAAAA
));
printn
(
N
(
abcdefghijk
));
printn
(
N
(
abcdefghijkl
));
printn
(
N
(
abcdefghijkl1
));
printn
(
N
(
abcdefghijkl12
));
printn
(
N
(
abcdefghijkl123
));
}
contracts/test_api/test_real.cpp
浏览文件 @
dbbd9717
...
...
@@ -2,7 +2,9 @@
#include <eosiolib/eosio.hpp>
#include "test_api.hpp"
using
namespace
eosio
;
void
test_real
::
create_instances
()
{
real
lhs1
(
5
);
eosio_assert
(
lhs1
.
value
()
==
5
,
"real instance value is wrong"
);
...
...
@@ -21,6 +23,8 @@ void test_real::test_division_by_0() {
real
lhs1
(
5
);
real
rhs1
(
0
);
real
result1
=
lhs1
/
rhs1
;
// in order to get rid of unused parameter warning
result1
=
0
;
eosio_assert
(
false
,
"should've thrown an error"
);
}
...
...
contracts/test_api/test_transaction.cpp
浏览文件 @
dbbd9717
...
...
@@ -19,7 +19,7 @@ struct test_action_action {
return
action_name
(
NAME
);
}
vector
<
char
>
data
;
eosio
::
vector
<
char
>
data
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
test_action_action
&
a
)
{
...
...
@@ -35,6 +35,7 @@ struct test_action_action {
*/
};
template
<
uint64_t
ACCOUNT
,
uint64_t
NAME
>
struct
test_dummy_action
{
static
account_name
get_account
()
{
...
...
@@ -49,38 +50,38 @@ struct test_dummy_action {
int32_t
c
;
template
<
typename
DataStream
>
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
test_dummy_action
&
a
)
{
ds
<<
a
.
a
;
ds
<<
a
.
b
;
ds
<<
a
.
c
;
friend
DataStream
&
operator
<<
(
DataStream
&
ds
,
const
test_dummy_action
&
d
a
)
{
ds
<<
d
a
.
a
;
ds
<<
d
a
.
b
;
ds
<<
d
a
.
c
;
return
ds
;
}
template
<
typename
DataStream
>
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
test_dummy_action
&
a
)
{
ds
>>
a
.
a
;
ds
>>
a
.
b
;
ds
>>
a
.
c
;
friend
DataStream
&
operator
>>
(
DataStream
&
ds
,
test_dummy_action
&
d
a
)
{
ds
>>
d
a
.
a
;
ds
>>
d
a
.
b
;
ds
>>
d
a
.
c
;
return
ds
;
}
};
#pragma pack(pop)
void
copy_data
(
char
*
data
,
size_t
data_len
,
vector
<
char
>&
data_out
)
{
for
(
int
i
=
0
;
i
<
data_len
;
i
++
)
void
copy_data
(
char
*
data
,
size_t
data_len
,
eosio
::
vector
<
char
>&
data_out
)
{
for
(
unsigned
int
i
=
0
;
i
<
data_len
;
i
++
)
data_out
.
push_back
(
data
[
i
]);
}
void
test_transaction
::
send_action
()
{
test_dummy_action
<
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"read_action_normal"
)
>
test_action
=
{
DUMMY_ACTION_DEFAULT_A
,
DUMMY_ACTION_DEFAULT_B
,
DUMMY_ACTION_DEFAULT_C
};
action
act
(
vector
<
permission_level
>
{{
N
(
testapi
),
N
(
active
)}},
test_action
);
action
act
(
eosio
::
vector
<
permission_level
>
{{
N
(
testapi
),
N
(
active
)}},
test_action
);
act
.
send
();
}
void
test_transaction
::
send_action_empty
()
{
test_action_action
<
N
(
testapi
),
WASM_TEST_ACTION
(
"test_action"
,
"assert_true"
)
>
test_action
;
action
act
(
vector
<
permission_level
>
{{
N
(
testapi
),
N
(
active
)}},
test_action
);
action
act
(
eosio
::
vector
<
permission_level
>
{{
N
(
testapi
),
N
(
active
)}},
test_action
);
act
.
send
();
}
...
...
@@ -102,7 +103,7 @@ void test_transaction::send_action_large() {
*/
void
test_transaction
::
send_action_recurse
()
{
char
buffer
[
1024
];
uint32_t
size
=
read_action
(
buffer
,
1024
);
read_action
(
buffer
,
1024
);
test_action_action
<
N
(
testapi
),
WASM_TEST_ACTION
(
"test_transaction"
,
"send_action_recurse"
)
>
test_action
;
copy_data
(
buffer
,
1024
,
test_action
.
data
);
...
...
@@ -139,7 +140,7 @@ void test_transaction::test_read_transaction() {
checksum256
h
;
transaction
t
;
char
*
p
=
(
char
*
)
&
t
;
uint
64
_t
read
=
read_transaction
(
(
char
*
)
&
t
,
sizeof
(
t
)
);
uint
32
_t
read
=
read_transaction
(
(
char
*
)
&
t
,
sizeof
(
t
)
);
sha256
(
p
,
read
,
&
h
);
printhex
(
&
h
,
sizeof
(
h
)
);
}
...
...
contracts/test_api/test_types.cpp
浏览文件 @
dbbd9717
...
...
@@ -20,7 +20,7 @@ void test_types::types_size() {
eosio_assert
(
sizeof
(
token_name
)
==
8
,
"token_name size != 8"
);
eosio_assert
(
sizeof
(
table_name
)
==
8
,
"table_name size != 8"
);
eosio_assert
(
sizeof
(
time
)
==
4
,
"time size != 4"
);
eosio_assert
(
sizeof
(
key256
)
==
32
,
"key256 size != 32"
);
eosio_assert
(
sizeof
(
eosio
::
key256
)
==
32
,
"key256 size != 32"
);
}
void
test_types
::
char_to_symbol
()
{
...
...
@@ -59,7 +59,7 @@ void test_types::char_to_symbol() {
for
(
unsigned
char
i
=
0
;
i
<
255
;
i
++
)
{
if
((
i
>=
'a'
&&
i
<=
'z'
)
||
(
i
>=
'1'
||
i
<=
'5'
))
continue
;
eosio_assert
(
eosio
::
char_to_symbol
(
i
)
==
0
,
"eosio::char_to_symbol() != 0"
);
eosio_assert
(
eosio
::
char_to_symbol
(
(
char
)
i
)
==
0
,
"eosio::char_to_symbol() != 0"
);
}
}
...
...
contracts/test_api_db/test_db.cpp
浏览文件 @
dbbd9717
...
...
@@ -62,7 +62,7 @@ struct TestModel3xi64_V2 : TestModel3xi64 {
extern
"C"
{
void
my_memset
(
void
*
vptr
,
unsigned
char
val
,
unsigned
int
size
)
{
char
*
ptr
=
(
char
*
)
vptr
;
while
(
size
--
)
{
*
(
ptr
++
)
=
val
;
}
while
(
size
--
)
{
*
(
ptr
++
)
=
(
char
)
val
;
}
}
uint32_t
my_strlen
(
const
char
*
str
)
{
uint32_t
len
=
0
;
...
...
@@ -187,7 +187,7 @@ void test_db::key_str_general() {
const
char
*
atr
[]
=
{
"atr"
,
"atr"
,
"atr"
,
"atr"
};
const
char
*
ztr
[]
=
{
"ztr"
,
"ztr"
,
"ztr"
,
"ztr"
};
u
int32_t
res
=
0
;
int32_t
res
=
0
;
//fill some data in contiguous tables
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
...
...
@@ -214,46 +214,46 @@ void test_db::key_str_general() {
res
=
load_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
res
),
"load alice"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"load alice"
);
res
=
load_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
1
],
STRLEN
(
keys
[
1
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
res
),
"load bob"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"load bob"
);
res
=
load_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
2
],
STRLEN
(
keys
[
2
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
res
),
"load carol"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"load carol"
);
res
=
load_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
res
),
"load dave"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"load dave"
);
res
=
previous_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
res
),
"back carol"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"back carol"
);
res
=
previous_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
2
],
STRLEN
(
keys
[
2
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
res
),
"back dave"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"back dave"
);
res
=
previous_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
1
],
STRLEN
(
keys
[
1
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
res
),
"back alice"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"back alice"
);
res
=
previous_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
eosio_assert
(
res
==
0
,
"no prev"
);
res
=
next_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
res
),
"next bob"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"next bob"
);
res
=
next_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
1
],
STRLEN
(
keys
[
1
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
res
),
"next carol"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"next carol"
);
res
=
next_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
2
],
STRLEN
(
keys
[
2
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
res
),
"next dave"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"next dave"
);
res
=
lower_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
res
),
"lowerbound alice"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
0
])
&&
my_memcmp
((
void
*
)
vals
[
0
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"lowerbound alice"
);
res
=
upper_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
0
],
STRLEN
(
keys
[
0
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
res
),
"upperbound bob"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
1
])
&&
my_memcmp
((
void
*
)
vals
[
1
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"upperbound bob"
);
res
=
lower_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
res
),
"upperbound dave"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
3
])
&&
my_memcmp
((
void
*
)
vals
[
3
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"upperbound dave"
);
res
=
upper_bound_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
eosio_assert
(
res
==
0
,
"no upper_bound"
);
...
...
@@ -262,7 +262,7 @@ void test_db::key_str_general() {
eosio_assert
(
res
!=
0
,
"store dave"
);
res
=
load_str
(
current_receiver
(),
current_receiver
(),
N
(
str
),
(
char
*
)
keys
[
3
],
STRLEN
(
keys
[
3
]),
tmp
,
64
);
eosio_assert
(
res
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
res
),
"load updated carol"
);
eosio_assert
(
uint32_t
(
res
)
==
STRLEN
(
vals
[
2
])
&&
my_memcmp
((
void
*
)
vals
[
2
],
(
void
*
)
tmp
,
uint32_t
(
res
)
),
"load updated carol"
);
}
#if 0
...
...
@@ -1564,12 +1564,12 @@ void test_db::primary_i64_general()
{
int
itr
=
db_find_i64
(
current_receiver
(),
current_receiver
(),
table1
,
N
(
bob
));
eosio_assert
(
itr
>=
0
,
""
);
in
t
buffer_len
=
5
;
uint32_
t
buffer_len
=
5
;
char
value
[
50
];
auto
len
=
db_get_i64
(
itr
,
value
,
buffer_len
);
value
[
buffer_len
]
=
'\0'
;
std
::
string
s
(
value
);
eosio_assert
(
len
==
strlen
(
"bob's info"
),
"primary_i64_general - db_get_i64"
);
eosio_assert
(
uint32_t
(
len
)
==
strlen
(
"bob's info"
),
"primary_i64_general - db_get_i64"
);
eosio_assert
(
s
==
"bob's"
,
"primary_i64_general - db_get_i64"
);
buffer_len
=
20
;
...
...
@@ -1584,10 +1584,10 @@ void test_db::primary_i64_general()
int
itr
=
db_find_i64
(
current_receiver
(),
current_receiver
(),
table1
,
N
(
bob
));
eosio_assert
(
itr
>=
0
,
""
);
const
char
*
new_value
=
"bob's new info"
;
in
t
new_value_len
=
strlen
(
new_value
);
uint32_
t
new_value_len
=
strlen
(
new_value
);
db_update_i64
(
itr
,
current_receiver
(),
new_value
,
new_value_len
);
char
ret_value
[
50
];
auto
len
=
db_get_i64
(
itr
,
ret_value
,
new_value_len
);
db_get_i64
(
itr
,
ret_value
,
new_value_len
);
ret_value
[
new_value_len
]
=
'\0'
;
std
::
string
sret
(
ret_value
);
eosio_assert
(
sret
==
"bob's new info"
,
"primary_i64_general - db_update_i64"
);
...
...
@@ -1674,7 +1674,7 @@ void test_db::idx64_general()
{
110
,
N
(
joe
)}
};
for
(
in
t
i
=
0
;
i
<
sizeof
(
records
)
/
sizeof
(
records
[
0
]);
++
i
)
{
for
(
uint32_
t
i
=
0
;
i
<
sizeof
(
records
)
/
sizeof
(
records
[
0
]);
++
i
)
{
db_idx64_store
(
current_receiver
(),
table
,
current_receiver
(),
records
[
i
].
ssn
,
&
records
[
i
].
name
);
}
...
...
@@ -1818,7 +1818,7 @@ void test_db::idx64_upperbound()
{
secondary_type
ub_sec
=
N
(
alice
);
uint64_t
ub_prim
=
0
;
const
uint64_t
al
ice_ssn
=
265
,
al
lyson_ssn
=
650
;
const
uint64_t
allyson_ssn
=
650
;
int
ub
=
db_idx64_upperbound
(
current_receiver
(),
current_receiver
(),
table
,
&
ub_sec
,
&
ub_prim
);
eosio_assert
(
ub_prim
==
allyson_ssn
&&
ub_sec
==
N
(
allyson
),
""
);
eosio_assert
(
ub
==
db_idx64_find_primary
(
current_receiver
(),
current_receiver
(),
table
,
&
ub_sec
,
allyson_ssn
),
err
.
c_str
());
...
...
@@ -1834,7 +1834,6 @@ void test_db::idx64_upperbound()
{
secondary_type
ub_sec
=
N
(
joe
);
uint64_t
ub_prim
=
0
;
const
uint64_t
ssn
=
110
;
int
ub
=
db_idx64_upperbound
(
current_receiver
(),
current_receiver
(),
table
,
&
ub_sec
,
&
ub_prim
);
eosio_assert
(
ub_prim
==
0
&&
ub_sec
==
N
(
joe
),
err
.
c_str
());
eosio_assert
(
ub
<
0
,
err
.
c_str
());
...
...
contracts/test_api_mem/test_api_mem.cpp
浏览文件 @
dbbd9717
...
...
@@ -14,7 +14,7 @@ extern "C" {
}
void
apply
(
unsigned
long
long
code
,
unsigned
long
long
action
)
{
void
apply
(
unsigned
long
long
,
unsigned
long
long
action
)
{
//eosio::print("==> CONTRACT: ", code, " ", action, "\n");
...
...
contracts/test_api_mem/test_extended_memory.cpp
浏览文件 @
dbbd9717
...
...
@@ -2,7 +2,7 @@
#include <eosiolib/memory.hpp>
#include "../test_api/test_api.hpp"
using
namespace
eosio
;
//
using namespace eosio;
void
verify
(
const
void
*
const
ptr
,
const
uint32_t
val
,
const
uint32_t
size
)
{
const
char
*
char_ptr
=
(
const
char
*
)
ptr
;
...
...
@@ -90,8 +90,8 @@ void test_extended_memory::test_page_memory_exceeded() {
}
void
test_extended_memory
::
test_page_memory_negative_bytes
()
{
sbrk
(
-
1
);
eosio_assert
(
0
,
"Should have thrown exception for trying to remove memory"
);
sbrk
((
uint32_t
)
-
1
);
eosio_assert
(
0
,
"Should have thrown exception for trying to remove memory"
);
}
void
test_extended_memory
::
test_initial_buffer
()
{
...
...
contracts/test_api_mem/test_memory.cpp
浏览文件 @
dbbd9717
...
...
@@ -2,10 +2,9 @@
* @file
* @copyright defined in eos/LICENSE.txt
*/
//#include <eoslib/message.h>
#include <eosiolib/memory.hpp>
using
namespace
eosio
;
void
verify_mem
(
const
void
*
const
ptr
,
const
uint32_t
val
,
const
uint32_t
size
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录