Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
9ad9bb69
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,发现更多精彩内容 >>
提交
9ad9bb69
编写于
3月 05, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unit-tests for system contract
上级
643db667
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
205 addition
and
65 deletion
+205
-65
contracts/eosio.system/delegate_bandwith.hpp
contracts/eosio.system/delegate_bandwith.hpp
+1
-1
tests/wasm_tests/eosio.system_tests.cpp
tests/wasm_tests/eosio.system_tests.cpp
+204
-64
未找到文件。
contracts/eosio.system/delegate_bandwith.hpp
浏览文件 @
9ad9bb69
...
...
@@ -129,7 +129,7 @@ namespace eosiosystem {
eosio_assert
(
0
<
storage_bytes
,
"stake is too small to increase storage even by 1 byte"
);
del_bandwidth_index_type
del_index
(
SystemAccount
,
del
.
from
);
auto
itr
=
del_index
.
find
(
del
.
receiver
);
auto
itr
=
del_index
.
find
(
del
.
receiver
);
if
(
itr
==
nullptr
)
{
del_index
.
emplace
(
del
.
from
,
[
&
](
auto
&
dbo
){
dbo
.
from
=
del
.
from
;
...
...
tests/wasm_tests/eosio.system_tests.cpp
浏览文件 @
9ad9bb69
...
...
@@ -83,16 +83,17 @@ public:
BOOST_AUTO_TEST_SUITE
(
eosio_system_tests
)
BOOST_FIXTURE_TEST_CASE
(
delegate_to_myself
,
eosio_system_tester
)
try
{
BOOST_FIXTURE_TEST_CASE
(
stake_unstake
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000.0000 EOS"
),
get_balance
(
"alice"
)
);
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"stake_net"
,
"200.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"300.0000 EOS"
)
)
);
auto
stake
=
get_total_stake
(
"alice"
);
...
...
@@ -105,49 +106,13 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"400.0000 EOS"
),
get_balance
(
"alice"
)
);
//trying to unstake more net bandwith than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked net bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"200.0001 EOS"
)
(
"unstake_cpu"
,
"0.0000 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
//trying to unstake more cpu bandwith than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked cpu bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"000.0000 EOS"
)
(
"unstake_cpu"
,
"100.0001 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
//trying to unstake more storage than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked storage"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"000.0000 EOS"
)
(
"unstake_cpu"
,
"000.0001 EOS"
)
(
"unstake_bytes"
,
bytes
+
1
)
)
);
//check that nothing has changed
stake
=
get_total_stake
(
"alice"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"200.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"100.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"300.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
bytes
,
stake
[
"storage_bytes"
].
as_uint64
()
);
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"200.0000 EOS"
)
(
"unstake_cpu"
,
"100.0000 EOS"
)
(
"unstake_bytes"
,
bytes
)
)
);
stake
=
get_total_stake
(
"alice"
);
...
...
@@ -155,9 +120,11 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"0.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"0.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
0
,
stake
[
"storage_bytes"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000.0000 EOS"
),
get_balance
(
"alice"
)
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
fail_without_auth
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
...
...
@@ -185,6 +152,7 @@ BOOST_FIXTURE_TEST_CASE( fail_without_auth, eosio_system_tester ) try {
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
stake_negative
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
...
...
@@ -226,15 +194,17 @@ BOOST_FIXTURE_TEST_CASE( stake_negative, eosio_system_tester ) try {
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
unstake_negative
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"200.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"300.0000 EOS"
)
)
);
auto
stake
=
get_total_stake
(
"bob"
);
...
...
@@ -270,24 +240,86 @@ BOOST_FIXTURE_TEST_CASE( unstake_negative, eosio_system_tester ) try {
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
unstake_more_than_at_stake
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"stake_net"
,
"200.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"300.0000 EOS"
)
)
);
auto
stake
=
get_total_stake
(
"alice"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"200.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"100.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"300.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
auto
bytes
=
stake
[
"storage_bytes"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
true
,
0
<
bytes
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"400.0000 EOS"
),
get_balance
(
"alice"
)
);
//trying to unstake more net bandwith than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked net bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"200.0001 EOS"
)
(
"unstake_cpu"
,
"0.0000 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
//trying to unstake more cpu bandwith than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked cpu bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"000.0000 EOS"
)
(
"unstake_cpu"
,
"100.0001 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
//trying to unstake more storage than at stake
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked storage"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"unstake_net"
,
"000.0000 EOS"
)
(
"unstake_cpu"
,
"000.0001 EOS"
)
(
"unstake_bytes"
,
bytes
+
1
)
)
);
//check that nothing has changed
stake
=
get_total_stake
(
"alice"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"200.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"100.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"300.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
bytes
,
stake
[
"storage_bytes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"400.0000 EOS"
),
get_balance
(
"alice"
)
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
delegate_to_another_user
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000.0000 EOS"
),
get_balance
(
"alice"
)
);
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"0
00.0000 EOS"
)
(
"stake_net"
,
"2
00.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"80.0000 EOS"
)
)
);
auto
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"
0
00.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"
2
00.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"100.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"80.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
auto
bytes
=
stake
[
"storage_bytes"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
true
,
0
<
bytes
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"620.0000 EOS"
),
get_balance
(
"alice"
)
);
//bob should not be able to unstake what was staked by alice
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: unable to find key"
),
...
...
@@ -299,6 +331,114 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_another_user, eosio_system_tester ) try {
(
"unstake_bytes"
,
bytes
)
)
);
issue
(
"carol"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
carol
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"carol"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"20.0000 EOS"
)
(
"stake_cpu"
,
"10.0000 EOS"
)
(
"stake_storage"
,
"8.0000 EOS"
)
)
);
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"220.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"110.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"88.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
auto
bytes2
=
stake
[
"storage_bytes"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
true
,
bytes
<
bytes2
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"962.0000 EOS"
),
get_balance
(
"carol"
)
);
//alice should not be able to unstake money staked by carol
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked net bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"201.0000 EOS"
)
(
"unstake_cpu"
,
"1.0000 EOS"
)
(
"unstake_bytes"
,
bytes
-
1
)
)
);
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked cpu bandwidth"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"1.0000 EOS"
)
(
"unstake_cpu"
,
"101.0000 EOS"
)
(
"unstake_bytes"
,
bytes
-
1
)
)
);
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: insufficient staked storage"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"1.0000 EOS"
)
(
"unstake_cpu"
,
"1.0000 EOS"
)
(
"unstake_bytes"
,
bytes
+
1
)
)
);
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"220.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"110.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"88.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
bytes2
,
stake
[
"storage_bytes"
].
as_uint64
());
//balance should not change after unsuccessfull attempts to unstake
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"620.0000 EOS"
),
get_balance
(
"alice"
)
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
adding_stake_partial_unstake
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"200.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"80.0000 EOS"
)
)
);
auto
stake
=
get_total_stake
(
"bob"
);
auto
bytes0
=
stake
[
"storage_bytes"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"100.0000 EOS"
)
(
"stake_cpu"
,
"50.0000 EOS"
)
(
"stake_storage"
,
"40.0000 EOS"
)
)
);
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"300.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"150.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"120.0000 EOS"
).
amount
,
stake
[
"storage_stake"
].
as_uint64
());
auto
bytes
=
stake
[
"storage_bytes"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
true
,
bytes0
<
bytes
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"430.0000 EOS"
),
get_balance
(
"alice"
)
);
//trying to unstake more cpu bandwith than at stake
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"150.0000 EOS"
)
(
"unstake_cpu"
,
"75.0000 EOS"
)
(
"unstake_bytes"
,
bytes
/
2
)
)
);
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"150.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"75.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
bytes
-
bytes
/
2
,
stake
[
"storage_bytes"
].
as_uint64
()
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"120.0000 EOS"
).
amount
-
asset
::
from_string
(
"120.0000 EOS"
).
amount
*
(
bytes
/
2
)
/
bytes
,
stake
[
"storage_stake"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"714.9599 EOS"
),
get_balance
(
"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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录