Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
643db667
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,发现更多精彩内容 >>
提交
643db667
编写于
3月 05, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unit-tests + small bugfixes for system contract (delegate bandwith and storage)
上级
21f1a2b2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
8 deletion
+123
-8
contracts/eosio.system/delegate_bandwith.hpp
contracts/eosio.system/delegate_bandwith.hpp
+9
-5
contracts/eosiolib/token.hpp
contracts/eosiolib/token.hpp
+1
-1
tests/wasm_tests/eosio.system_tests.cpp
tests/wasm_tests/eosio.system_tests.cpp
+113
-2
未找到文件。
contracts/eosio.system/delegate_bandwith.hpp
浏览文件 @
643db667
...
...
@@ -105,8 +105,9 @@ namespace eosiosystem {
eosio_assert
(
del
.
stake_net_quantity
.
amount
>=
0
,
"must stake a positive amount"
);
eosio_assert
(
del
.
stake_storage_quantity
.
amount
>=
0
,
"must stake a positive amount"
);
system_token_type
total_stake
=
system_token_type
(
del
.
stake_cpu_quantity
)
+
system_token_type
(
del
.
stake_net_quantity
)
+
system_token_type
(
del
.
stake_storage_quantity
);
eosio_assert
(
total_stake
.
quantity
>=
0
,
"must stake a positive amount"
);
system_token_type
total_stake
=
system_token_type
(
del
.
stake_cpu_quantity
)
+
system_token_type
(
del
.
stake_net_quantity
)
+
system_token_type
(
del
.
stake_storage_quantity
);
eosio_assert
(
total_stake
.
quantity
>
0
,
"must stake a positive amount"
);
require_auth
(
del
.
from
);
...
...
@@ -190,11 +191,14 @@ namespace eosiosystem {
eosio_assert
(
dbw
.
cpu_weight
>=
del
.
unstake_cpu_quantity
,
"insufficient staked cpu bandwidth"
);
eosio_assert
(
dbw
.
storage_bytes
>=
del
.
unstake_storage_bytes
,
"insufficient staked storage"
);
system_token_type
storage_stake_decrease
=
dbw
.
storage_stake
*
del
.
unstake_storage_bytes
/
dbw
.
storage_bytes
;
system_token_type
storage_stake_decrease
=
0
<
dbw
.
storage_bytes
?
dbw
.
storage_stake
*
del
.
unstake_storage_bytes
/
dbw
.
storage_bytes
:
system_token_type
(
0
);
auto
total_refund
=
system_token_type
(
del
.
unstake_cpu_quantity
)
+
system_token_type
(
del
.
unstake_net_quantity
)
+
storage_stake_decrease
;
auto
total_refund
=
system_token_type
(
del
.
unstake_cpu_quantity
)
+
system_token_type
(
del
.
unstake_net_quantity
)
+
storage_stake_decrease
;
eosio_assert
(
total_refund
.
quantity
>
=
0
,
"must unstake a positive amount"
);
eosio_assert
(
total_refund
.
quantity
>
0
,
"must unstake a positive amount"
);
del_index
.
update
(
dbw
,
del
.
from
,
[
&
](
auto
&
dbo
){
dbo
.
net_weight
-=
del
.
unstake_net_quantity
;
...
...
contracts/eosiolib/token.hpp
浏览文件 @
643db667
...
...
@@ -128,7 +128,7 @@ namespace eosio {
* @return this token after addition
*/
token
&
operator
*=
(
uint64_t
a
)
{
eosio_assert
(
(
quantity
*
a
)
/
a
==
quantity
,
"integer overflow multiplying token balance"
);
eosio_assert
(
a
==
0
||
(
quantity
*
a
)
/
a
==
quantity
,
"integer overflow multiplying token balance"
);
quantity
*=
a
;
return
*
this
;
}
...
...
tests/wasm_tests/eosio.system_tests.cpp
浏览文件 @
643db667
...
...
@@ -151,10 +151,37 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
);
stake
=
get_total_stake
(
"alice"
);
std
::
cout
<<
"STAKE: "
<<
stake
[
"net_weight"
].
as_uint64
()
<<
' '
<<
stake
[
"cpu_weight"
].
as_uint64
()
<<
std
::
endl
;
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"0.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"0.0000 EOS"
).
amount
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
0
,
stake
[
"storage_stake"
].
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
());
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
fail_without_auth
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
error
(
"missing authority of alice"
),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"10.0000 EOS"
)
(
"stake_cpu"
,
"10.0000 EOS"
)
(
"stake_storage"
,
"10.0000 EOS"
),
false
)
);
BOOST_REQUIRE_EQUAL
(
error
(
"missing authority of alice"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"200.0000 EOS"
)
(
"unstake_cpu"
,
"100.0000 EOS"
)
(
"unstake_bytes"
,
0
)
,
false
)
);
}
FC_LOG_AND_RETHROW
()
...
...
@@ -188,6 +215,90 @@ BOOST_FIXTURE_TEST_CASE( stake_negative, eosio_system_tester ) try {
(
"stake_storage"
,
"-0.0001 EOS"
)
)
);
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: must stake a positive amount"
),
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
(
"stake_net"
,
"0.0000 EOS"
)
(
"stake_cpu"
,
"0.0000 EOS"
)
(
"stake_storage"
,
"0.0000 EOS"
)
)
);
}
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
()
(
"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"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"200.0000 EOS"
).
amount
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: must unstake a positive amount"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"-1.0000 EOS"
)
(
"unstake_cpu"
,
"0.0000 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: must unstake a positive amount"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"0.0000 EOS"
)
(
"unstake_cpu"
,
"-1.0000 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
//unstake all zeros
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: must unstake a positive amount"
),
push_action
(
N
(
alice
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"0.0000 EOS"
)
(
"unstake_cpu"
,
"0.0000 EOS"
)
(
"unstake_bytes"
,
0
)
)
);
}
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
()
(
"from"
,
"alice"
)
(
"receiver"
,
"bob"
)
(
"stake_net"
,
"000.0000 EOS"
)
(
"stake_cpu"
,
"100.0000 EOS"
)
(
"stake_storage"
,
"80.0000 EOS"
)
);
auto
stake
=
get_total_stake
(
"bob"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"000.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
);
//bob should not be able to unstake what was staked by alice
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: unable to find key"
),
push_action
(
N
(
bob
),
N
(
undelegatebw
),
mvo
()
(
"from"
,
"bob"
)
(
"receiver"
,
"bob"
)
(
"unstake_net"
,
"000.0000 EOS"
)
(
"unstake_cpu"
,
"10.0000 EOS"
)
(
"unstake_bytes"
,
bytes
)
)
);
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录