Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
e47b55c7
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,发现更多精彩内容 >>
提交
e47b55c7
编写于
3月 02, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unit-test for system contract (failing)
上级
27b72a3d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
16 deletion
+80
-16
contracts/eosio.system/delegate_bandwith.hpp
contracts/eosio.system/delegate_bandwith.hpp
+10
-14
contracts/eosiolib/singleton.hpp
contracts/eosiolib/singleton.hpp
+1
-1
tests/wasm_tests/eosio.system_tests.cpp
tests/wasm_tests/eosio.system_tests.cpp
+69
-1
未找到文件。
contracts/eosio.system/delegate_bandwith.hpp
浏览文件 @
e47b55c7
...
...
@@ -110,9 +110,6 @@ namespace eosiosystem {
require_auth
(
del
.
from
);
del_bandwidth_index_type
del_index
(
SystemAccount
,
del
.
from
);
total_resources_index_type
total_index
(
SystemAccount
,
del
.
receiver
);
//eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" );
auto
parameters
=
eosio_parameters_singleton
::
exists
()
?
eosio_parameters_singleton
::
get
()
...
...
@@ -130,9 +127,9 @@ namespace eosiosystem {
eosio_assert
(
0
<
storage_bytes
,
"stake is too small to increase storage even by 1 byte"
);
print
(
"delegatebw: from = "
,
del
.
from
,
" receiver = "
,
del
.
receiver
,
"
\n
"
);
del_bandwidth_index_type
del_index
(
SystemAccount
,
del
.
from
);
auto
itr
=
del_index
.
find
(
del
.
receiver
);
if
(
itr
!
=
nullptr
)
{
if
(
itr
=
=
nullptr
)
{
del_index
.
emplace
(
del
.
from
,
[
&
](
auto
&
dbo
){
dbo
.
from
=
del
.
from
;
dbo
.
to
=
del
.
receiver
;
...
...
@@ -151,6 +148,7 @@ namespace eosiosystem {
});
}
total_resources_index_type
total_index
(
SystemAccount
,
del
.
receiver
);
auto
tot_itr
=
total_index
.
find
(
del
.
receiver
);
if
(
tot_itr
==
nullptr
)
{
tot_itr
=
&
total_index
.
emplace
(
del
.
from
,
[
&
](
auto
&
tot
)
{
...
...
@@ -184,22 +182,19 @@ namespace eosiosystem {
require_auth
(
del
.
from
);
del_bandwidth_index_type
del_index
(
SystemAccount
,
del
.
from
);
total_resources_index_type
total_index
(
SystemAccount
,
del
.
receiver
);
//eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" );
print
(
"undelegatebw: from = "
,
del
.
from
,
" receiver = "
,
del
.
receiver
,
"
\n
"
);
del_bandwidth_index_type
del_index
(
SystemAccount
,
del
.
from
);
const
auto
&
dbw
=
del_index
.
get
(
del
.
receiver
);
eosio_assert
(
dbw
.
net_weight
>=
del
.
unstake_net_quantity
,
"insufficient staked net bandwidth"
);
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"
);
const
auto
&
totals
=
total_index
.
get
(
del
.
receiver
);
system_token_type
storage_stake_decrease
=
totals
.
storage_stake
*
del
.
unstake_storage_bytes
/
totals
.
storage_bytes
;
system_token_type
storage_stake_decrease
=
dbw
.
storage_stake
*
del
.
unstake_storage_bytes
/
dbw
.
storage_bytes
;
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
;
...
...
@@ -208,6 +203,8 @@ namespace eosiosystem {
dbo
.
storage_bytes
-=
del
.
unstake_storage_bytes
;
});
total_resources_index_type
total_index
(
SystemAccount
,
del
.
receiver
);
const
auto
&
totals
=
total_index
.
get
(
del
.
receiver
);
total_index
.
update
(
totals
,
0
,
[
&
](
auto
&
tot
)
{
tot
.
net_weight
-=
del
.
unstake_net_quantity
;
tot
.
cpu_weight
-=
del
.
unstake_cpu_quantity
;
...
...
@@ -218,7 +215,6 @@ namespace eosiosystem {
set_resource_limits
(
totals
.
owner
,
totals
.
storage_bytes
,
totals
.
net_weight
.
quantity
,
totals
.
cpu_weight
.
quantity
,
0
);
/// TODO: implement / enforce time delays on withdrawing
print
(
"undelegatebw: "
,
total_refund
.
quantity
,
"
\n
"
);
currency
::
inline_transfer
(
SystemAccount
,
del
.
from
,
asset
(
static_cast
<
int64_t
>
(
total_refund
.
quantity
)),
"unstake bandwidth"
);
auto
parameters
=
eosio_parameters_singleton
::
get
();
...
...
contracts/eosiolib/singleton.hpp
浏览文件 @
e47b55c7
...
...
@@ -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
;
...
...
tests/wasm_tests/eosio.system_tests.cpp
浏览文件 @
e47b55c7
...
...
@@ -105,6 +105,43 @@ 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
()
(
"from"
,
"alice"
)
(
"receiver"
,
"alice"
)
...
...
@@ -117,8 +154,39 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
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( asset::from_string("0.0000 EOS").amount, stake["storage_stake"].as_uint64());
BOOST_REQUIRE_EQUAL
(
0
,
stake
[
"storage_stake"
].
as_uint64
());
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
stake_negative
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
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.0001 EOS"
)
(
"stake_cpu"
,
"0.0000 EOS"
)
(
"stake_storage"
,
"0.0000 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.0001 EOS"
)
(
"stake_storage"
,
"0.0000 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.0001 EOS"
)
)
);
}
FC_LOG_AND_RETHROW
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录