Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
bdf4ec7d
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,发现更多精彩内容 >>
提交
bdf4ec7d
编写于
2月 06, 2018
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes for bugs related to identity contract tests
上级
719e69ca
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
29 deletion
+40
-29
contracts/eosiolib/singleton.hpp
contracts/eosiolib/singleton.hpp
+4
-4
contracts/eosiolib/table.hpp
contracts/eosiolib/table.hpp
+2
-2
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+5
-4
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-1
tests/wasm_tests/identity_tests.cpp
tests/wasm_tests/identity_tests.cpp
+28
-18
未找到文件。
contracts/eosiolib/singleton.hpp
浏览文件 @
bdf4ec7d
...
...
@@ -19,14 +19,14 @@ namespace eosio {
static
bool
exists
(
scope_name
scope
=
Code
)
{
uint64_t
key
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Cod
e
,
key
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
auto
read
=
load_i64
(
Code
,
scop
e
,
key
,
(
char
*
)
&
key
,
sizeof
(
key
)
);
return
read
>
0
;
}
static
T
get
(
scope_name
scope
=
Code
)
{
char
temp
[
1024
+
8
];
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Cod
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
Code
,
scop
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
assert
(
read
>
0
,
"singleton does not exist"
);
return
unpack
<
T
>
(
temp
+
sizeof
(
SingletonName
),
read
);
}
...
...
@@ -34,7 +34,7 @@ namespace eosio {
static
T
get_or_default
(
scope_name
scope
=
Code
,
const
T
&
def
=
T
()
)
{
char
temp
[
1024
+
8
];
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Cod
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
Code
,
scop
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
if
(
read
<
0
)
{
return
def
;
}
...
...
@@ -46,7 +46,7 @@ namespace eosio {
*
reinterpret_cast
<
uint64_t
*>
(
temp
)
=
SingletonName
;
auto
read
=
load_i64
(
scope
,
Cod
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
auto
read
=
load_i64
(
Code
,
scop
e
,
SingletonName
,
temp
,
sizeof
(
temp
)
);
if
(
read
<
0
)
{
set
(
def
,
scope
);
return
def
;
...
...
contracts/eosiolib/table.hpp
浏览文件 @
bdf4ec7d
...
...
@@ -93,7 +93,7 @@ namespace eosio {
temp
[
1
]
=
secondary
;
temp
[
2
]
=
tertiary
;
auto
read
=
lower_bound_primary_i64i64i64
(
_scope
,
Cod
e
,
TableName
,
auto
read
=
lower_bound_primary_i64i64i64
(
Code
,
_scop
e
,
TableName
,
(
char
*
)
temp
,
sizeof
(
temp
)
);
if
(
read
<=
0
)
{
return
false
;
...
...
@@ -114,7 +114,7 @@ namespace eosio {
temp
[
1
]
=
secondary
;
temp
[
2
]
=
tertiary
;
auto
read
=
upper_bound_primary_i64i64i64
(
_scope
,
Cod
e
,
TableName
,
auto
read
=
upper_bound_primary_i64i64i64
(
Code
,
_scop
e
,
TableName
,
(
char
*
)
temp
,
sizeof
(
temp
)
);
if
(
read
<=
0
)
{
return
false
;
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
bdf4ec7d
...
...
@@ -527,9 +527,10 @@ class producer_api : public context_aware_api {
int
get_active_producers
(
array_ptr
<
chain
::
account_name
>
producers
,
size_t
datalen
)
{
auto
active_producers
=
context
.
get_active_producers
();
size_t
len
=
std
::
min
(
datalen
/
sizeof
(
chain
::
account_name
),
active_producers
.
size
());
memcpy
(
producers
,
active_producers
.
data
(),
len
);
return
active_producers
.
size
()
*
sizeof
(
chain
::
account_name
);
size_t
len
=
active_producers
.
size
()
*
sizeof
(
chain
::
account_name
);
size_t
cpy_len
=
std
::
min
(
datalen
,
len
);
memcpy
(
producers
,
active_producers
.
data
(),
cpy_len
);
return
len
;
}
};
...
...
@@ -779,7 +780,7 @@ class db_index_api : public context_aware_api {
int
call
(
ContextMethodType
method
,
const
account_name
&
code
,
const
scope_name
&
scope
,
const
name
&
table
,
array_ptr
<
char
>
data
,
size_t
data_len
)
{
auto
maybe_t_id
=
context
.
find_table
(
co
ntext
.
receiver
,
scope
,
table
);
auto
maybe_t_id
=
context
.
find_table
(
co
de
,
scope
,
table
);
if
(
maybe_t_id
==
nullptr
)
{
return
-
1
;
}
...
...
tests/CMakeLists.txt
浏览文件 @
bdf4ec7d
...
...
@@ -38,7 +38,7 @@ target_link_libraries( chain_test eosio_testing eosio_chain chainbase eos_utilit
if
(
WASM_TOOLCHAIN
)
target_include_directories
(
chain_test PUBLIC
${
CMAKE_BINARY_DIR
}
/contracts
${
CMAKE_CURRENT_BINARY_DIR
}
/tests/contracts
)
target_include_directories
(
chain_test PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
/wasm_tests
)
add_dependencies
(
chain_test asserter test_api currency proxy
)
add_dependencies
(
chain_test asserter test_api currency proxy
identity
)
endif
()
...
...
tests/wasm_tests/identity_tests.cpp
浏览文件 @
bdf4ec7d
...
...
@@ -27,7 +27,7 @@ public:
identity_tester
()
{
produce_blocks
(
2
);
create_accounts
(
{
N
(
identity
),
N
(
identitytest
),
N
(
alice
),
N
(
bob
)},
asset
::
from_string
(
"100000.0000 EOS"
)
);
create_accounts
(
{
N
(
identity
),
N
(
identitytest
),
N
(
alice
),
N
(
bob
)
,
N
(
carol
)
},
asset
::
from_string
(
"100000.0000 EOS"
)
);
produce_blocks
(
1000
);
set_code
(
N
(
identity
),
identity_wast
);
...
...
@@ -45,6 +45,9 @@ public:
abi_def
abi_test
;
BOOST_REQUIRE_EQUAL
(
abi_serializer
::
to_abi
(
acnt_test
.
abi
,
abi_test
),
true
);
abi_ser_test
.
set_abi
(
abi_test
);
const
global_property_object
&
gpo
=
control
->
get_global_properties
();
producer_name
=
(
string
)
gpo
.
active_producers
.
producers
.
front
().
producer_name
;
}
uint64_t
get_result_uint64
()
{
...
...
@@ -194,6 +197,7 @@ public:
public:
abi_serializer
abi_ser
;
abi_serializer
abi_ser_test
;
std
::
string
producer_name
;
};
constexpr
uint64_t
identity_val
=
0xffffffffffffffff
;
//64-bit value
...
...
@@ -455,28 +459,29 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_producer, identity_tester ) try {
BOOST_REQUIRE_EQUAL
(
success
(),
create_identity
(
"alice"
,
identity_val
));
// certify owner by a block producer, should result in trusted certification
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"inita"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
producer_name
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
(
"property"
,
"owner"
)
(
"type"
,
"account"
)
(
"data"
,
to_uint8_vector
(
N
(
alice
)))
(
"memo"
,
""
)
(
"confidence"
,
100
)
}));
fc
::
variant
certrow
=
get_certrow
(
identity_val
,
"owner"
,
1
,
"inita"
);
fc
::
variant
certrow
=
get_certrow
(
identity_val
,
"owner"
,
1
,
producer_name
);
BOOST_REQUIRE_EQUAL
(
true
,
certrow
.
is_object
()
);
BOOST_REQUIRE_EQUAL
(
"owner"
,
certrow
[
"property"
].
as_string
()
);
BOOST_REQUIRE_EQUAL
(
1
,
certrow
[
"trusted"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
"inita"
,
certrow
[
"certifier"
].
as_string
()
);
BOOST_REQUIRE_EQUAL
(
producer_name
,
certrow
[
"certifier"
].
as_string
()
);
BOOST_REQUIRE_EQUAL
(
N
(
alice
),
to_uint64
(
certrow
[
"data"
])
);
//uncertified copy of that row shouldn't exist
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
0
,
"inita"
).
is_null
());
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
0
,
producer_name
).
is_null
());
//alice still has not claimed the identity - she is not the official owner yet
BOOST_REQUIRE_EQUAL
(
0
,
get_owner_for_identity
(
identity_val
));
BOOST_REQUIRE_EQUAL
(
0
,
get_identity_for_account
(
"alice"
));
//alice claims it
//alice claims it
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"alice"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
(
"property"
,
"owner"
)
(
"type"
,
"account"
)
...
...
@@ -491,7 +496,7 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_producer, identity_tester ) try {
BOOST_REQUIRE_EQUAL
(
identity_val
,
get_identity_for_account
(
"alice"
));
//block producer decertifies ownership
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"inita"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
producer_name
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
(
"property"
,
"owner"
)
(
"type"
,
"account"
)
(
"data"
,
to_uint8_vector
(
N
(
alice
)))
...
...
@@ -523,8 +528,8 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_trusted_account, identity_tester ) t
BOOST_REQUIRE_EQUAL
(
0
,
get_identity_for_account
(
"alice"
));
//block producer trusts bob
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
"initb"
,
"bob"
,
1
));
BOOST_REQUIRE_EQUAL
(
true
,
get_trust
(
"initb"
,
"bob"
));
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
producer_name
,
"bob"
,
1
));
BOOST_REQUIRE_EQUAL
(
true
,
get_trust
(
producer_name
,
"bob"
));
// bob (trusted account) certifies alice's ownership, it should result in trusted certification
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"bob"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
...
...
@@ -543,8 +548,8 @@ BOOST_FIXTURE_TEST_CASE( owner_certified_by_trusted_account, identity_tester ) t
BOOST_REQUIRE_EQUAL
(
identity_val
,
get_identity_for_account
(
"alice"
));
//block producer stops trusting bob
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
"initb"
,
"bob"
,
0
));
BOOST_REQUIRE_EQUAL
(
false
,
get_trust
(
"initb"
,
"bob"
));
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
producer_name
,
"bob"
,
0
));
BOOST_REQUIRE_EQUAL
(
false
,
get_trust
(
producer_name
,
"bob"
));
//certification made by bob is still flaged as trusted
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
1
,
"bob"
).
is_object
()
);
...
...
@@ -584,8 +589,8 @@ BOOST_FIXTURE_TEST_CASE( owner_certification_becomes_trusted, identity_tester )
BOOST_REQUIRE_EQUAL
(
0
,
get_identity_for_account
(
"alice"
));
//block producer trusts bob
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
"initb"
,
"bob"
,
1
));
BOOST_REQUIRE_EQUAL
(
true
,
get_trust
(
"initb"
,
"bob"
));
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
producer_name
,
"bob"
,
1
));
BOOST_REQUIRE_EQUAL
(
true
,
get_trust
(
producer_name
,
"bob"
));
//old certification made by bob still shouldn't be flaged as trusted
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
0
,
"bob"
).
is_object
()
);
...
...
@@ -609,14 +614,14 @@ BOOST_FIXTURE_TEST_CASE( ownership_contradiction, identity_tester ) try {
}));
// block producer certifies alice's ownership
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"inita"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
producer_name
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
(
"property"
,
"owner"
)
(
"type"
,
"account"
)
(
"data"
,
to_uint8_vector
(
N
(
alice
)))
(
"memo"
,
""
)
(
"confidence"
,
100
)
}));
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
1
,
"inita"
).
is_object
()
);
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
1
,
producer_name
).
is_object
()
);
//now alice is the official owner of the identity
BOOST_REQUIRE_EQUAL
(
N
(
alice
),
get_owner_for_identity
(
identity_val
));
...
...
@@ -631,15 +636,20 @@ BOOST_FIXTURE_TEST_CASE( ownership_contradiction, identity_tester ) try {
(
"confidence"
,
100
)
}));
//another block producer certifies bob's identity (to the identity already certified to alice)
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"initb"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
//block producer trusts carol
BOOST_REQUIRE_EQUAL
(
success
(),
settrust
(
producer_name
,
"carol"
,
1
));
BOOST_REQUIRE_EQUAL
(
true
,
get_trust
(
producer_name
,
"carol"
));
//another trusted delegate certifies bob's identity (to the identity already certified to alice)
BOOST_REQUIRE_EQUAL
(
success
(),
certify
(
"carol"
,
identity_val
,
vector
<
fc
::
variant
>
{
mutable_variant_object
()
(
"property"
,
"owner"
)
(
"type"
,
"account"
)
(
"data"
,
to_uint8_vector
(
N
(
bob
)))
(
"memo"
,
""
)
(
"confidence"
,
100
)
}));
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
1
,
"initb"
).
is_object
()
);
BOOST_REQUIRE_EQUAL
(
true
,
get_certrow
(
identity_val
,
"owner"
,
1
,
producer_name
).
is_object
()
);
//now neither alice or bob are official owners, because we have 2 trusted certifications in contradiction to each other
BOOST_REQUIRE_EQUAL
(
0
,
get_owner_for_identity
(
identity_val
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录