Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
cbff805f
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,发现更多精彩内容 >>
提交
cbff805f
编写于
3月 15, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more tests for voting
上级
1209953c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
93 addition
and
17 deletion
+93
-17
contracts/eosio.system/voting.hpp
contracts/eosio.system/voting.hpp
+1
-1
tests/wasm_tests/eosio.system_tests.cpp
tests/wasm_tests/eosio.system_tests.cpp
+92
-16
未找到文件。
contracts/eosio.system/voting.hpp
浏览文件 @
cbff805f
...
...
@@ -547,7 +547,7 @@ namespace eosiosystem {
voters_table
voters_tbl
(
SystemAccount
,
SystemAccount
);
auto
proxy
=
voters_tbl
.
find
(
reg
.
proxy
);
eosio_assert
(
bool
(
proxy
),
"proxy not found"
);
eosio_assert
(
proxy
->
is_proxy
==
1
,
"account is
already
a proxy"
);
eosio_assert
(
proxy
->
is_proxy
==
1
,
"account is
not
a proxy"
);
voters_tbl
.
update
(
*
proxy
,
0
,
[
&
](
voter_info
&
a
)
{
a
.
is_proxy
=
0
;
...
...
tests/wasm_tests/eosio.system_tests.cpp
浏览文件 @
cbff805f
...
...
@@ -1005,15 +1005,21 @@ BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
"producer3"
)[
"total_votes"
].
as_uint64
()
);
//proxied voter
(carol)
increases stake
//proxied voter
carol
increases stake
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"carol"
,
"50.0000 EOS"
,
"70.0000 EOS"
,
"0.0000 EOS"
)
);
BOOST_REQUIRE_EQUAL
(
3200005
,
get_voter_info
(
"alice"
)[
"proxied_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
3700007
,
get_producer_info
(
"producer1"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
3700007
,
get_producer_info
(
"producer2"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
"producer3"
)[
"total_votes"
].
as_uint64
()
);
//bob decreases stake
//
proxied voter
bob decreases stake
BOOST_REQUIRE_EQUAL
(
success
(),
unstake
(
"bob"
,
"50.0001 EOS"
,
"50.0001 EOS"
,
0
)
);
BOOST_REQUIRE_EQUAL
(
2200003
,
get_voter_info
(
"alice"
)[
"proxied_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
2700005
,
get_producer_info
(
"producer1"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
2700005
,
get_producer_info
(
"producer2"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
"producer3"
)[
"total_votes"
].
as_uint64
()
);
//carol chooses another proxy
//
proxied voter
carol chooses another proxy
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
carol
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"carol"
)
(
"proxy"
,
"donald"
)
...
...
@@ -1022,18 +1028,21 @@ BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system
);
BOOST_REQUIRE_EQUAL
(
500001
,
get_voter_info
(
"alice"
)[
"proxied_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
1700002
,
get_voter_info
(
"donald"
)[
"proxied_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
1000003
,
get_producer_info
(
"producer1"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
1000003
,
get_producer_info
(
"producer2"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
"producer3"
)[
"total_votes"
].
as_uint64
()
);
//bob
chooses direct voting
//bob
switches to direct voting and votes for one of the same producers, but not for another one
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
bob
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"bob"
)
(
"proxy"
,
""
)
(
"producers"
,
vector
<
account_name
>
()
)
(
"producers"
,
vector
<
account_name
>
{
N
(
producer2
)
}
)
)
);
BOOST_REQUIRE_EQUAL
(
0
,
get_voter_info
(
"alice"
)[
"proxied_votes"
].
as_uint64
()
);
//new proxied user affects producers
BOOST_REQUIRE_EQUAL
(
500002
,
get_producer_info
(
"producer1"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
1000003
,
get_producer_info
(
"producer2"
)[
"total_votes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
"producer3"
)[
"total_votes"
].
as_uint64
()
);
}
FC_LOG_AND_RETHROW
()
...
...
@@ -1047,14 +1056,7 @@ BOOST_FIXTURE_TEST_CASE( vote_both_proxy_and_producers, eosio_system_tester ) tr
REQUIRE_MATCHING_OBJECT
(
proxy
(
"alice"
),
get_voter_info
(
"alice"
)
);
//carol becomes a producer
fc
::
variant
params
=
producer_parameters_example
(
1
);
vector
<
char
>
key
=
fc
::
raw
::
pack
(
get_public_key
(
N
(
alice
),
"active"
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
regproducer
),
mvo
()
(
"producer"
,
"alice"
)
(
"producer_key"
,
key
)
(
"prefs"
,
params
)
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
regproducer
(
"carol"
,
1
)
);
//bob chooses alice as a proxy
issue
(
"bob"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
...
...
@@ -1069,4 +1071,78 @@ BOOST_FIXTURE_TEST_CASE( vote_both_proxy_and_producers, eosio_system_tester ) tr
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
select_invalid_proxy
,
eosio_system_tester
)
try
{
//accumulate proxied votes
issue
(
"bob"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"bob"
,
"100.0002 EOS"
,
"50.0001 EOS"
,
"50.0000 EOS"
)
);
//selecting account not registered as a proxy
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: proxy not found"
),
push_action
(
N
(
bob
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"bob"
)
(
"proxy"
,
"alice"
)
(
"producers"
,
vector
<
account_name
>
()
)
)
);
//selecting not existing account as a proxy
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: proxy not found"
),
push_action
(
N
(
bob
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"bob"
)
(
"proxy"
,
"notexist"
)
(
"producers"
,
vector
<
account_name
>
()
)
)
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
double_register_unregister_proxy_keeps_votes
,
eosio_system_tester
)
try
{
//alice becomes a producer
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
regproxy
),
mvo
()
(
"proxy"
,
"alice"
)
)
);
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"alice"
,
"5.0000 EOS"
,
"5.0000 EOS"
,
"50.0000 EOS"
)
);
REQUIRE_MATCHING_OBJECT
(
proxy
(
"alice"
)(
"staked"
,
M
(
"10.0000 EOS"
)
),
get_voter_info
(
"alice"
)
);
//bob stakes and selects alice as a proxy
issue
(
"bob"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"bob"
,
"100.0002 EOS"
,
"50.0001 EOS"
,
"50.0000 EOS"
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
bob
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"bob"
)
(
"proxy"
,
"alice"
)
(
"producers"
,
vector
<
account_name
>
()
)
)
);
REQUIRE_MATCHING_OBJECT
(
proxy
(
"alice"
)(
"proxied_votes"
,
1500003
)(
"staked"
,
M
(
"10.0000 EOS"
)
),
get_voter_info
(
"alice"
)
);
//double regestering should fail without affecting total votes and stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: account is already a proxy"
),
push_action
(
N
(
alice
),
N
(
regproxy
),
mvo
()
(
"proxy"
,
"alice"
)
)
);
REQUIRE_MATCHING_OBJECT
(
proxy
(
"alice"
)(
"proxied_votes"
,
1500003
)(
"staked"
,
M
(
"10.0000 EOS"
)
),
get_voter_info
(
"alice"
)
);
//uregister
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
unregproxy
),
mvo
()
(
"proxy"
,
"alice"
)
)
);
REQUIRE_MATCHING_OBJECT
(
voter
(
"alice"
)(
"proxied_votes"
,
1500003
)(
"staked"
,
M
(
"10.0000 EOS"
)
),
get_voter_info
(
"alice"
)
);
//double unregistering should not affect proxied_votes and stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: account is not a proxy"
),
push_action
(
N
(
alice
),
N
(
unregproxy
),
mvo
()
(
"proxy"
,
"alice"
)
)
);
REQUIRE_MATCHING_OBJECT
(
voter
(
"alice"
)(
"proxied_votes"
,
1500003
)(
"staked"
,
M
(
"10.0000 EOS"
)
),
get_voter_info
(
"alice"
)
);
}
FC_LOG_AND_RETHROW
()
BOOST_AUTO_TEST_SUITE_END
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录