Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
afa5cc22
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,发现更多精彩内容 >>
提交
afa5cc22
编写于
3月 02, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
system contract test fixes
上级
5950dff1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
46 addition
and
15 deletion
+46
-15
contracts/eosio.system/delegate_bandwith.hpp
contracts/eosio.system/delegate_bandwith.hpp
+7
-3
contracts/eosio.system/eosio.system.abi
contracts/eosio.system/eosio.system.abi
+1
-1
contracts/eosio.system/eosio.system.cpp
contracts/eosio.system/eosio.system.cpp
+1
-1
contracts/eosio.system/eosio.system.hpp
contracts/eosio.system/eosio.system.hpp
+2
-2
contracts/eosiolib/eosiolib.cpp
contracts/eosiolib/eosiolib.cpp
+11
-0
tests/wasm_tests/eosio.system_tests.cpp
tests/wasm_tests/eosio.system_tests.cpp
+24
-8
未找到文件。
contracts/eosio.system/delegate_bandwith.hpp
浏览文件 @
afa5cc22
...
...
@@ -130,6 +130,7 @@ 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
"
);
auto
itr
=
del_index
.
find
(
del
.
receiver
);
if
(
itr
!=
nullptr
)
{
del_index
.
emplace
(
del
.
from
,
[
&
](
auto
&
dbo
){
...
...
@@ -188,7 +189,9 @@ namespace eosiosystem {
//eosio_assert( is_account( del.receiver ), "can only delegate resources to an existing account" );
const
auto
&
dbw
=
del_index
.
get
(
del
.
receiver
);
print
(
"undelegatebw: from = "
,
del
.
from
,
" receiver = "
,
del
.
receiver
,
"
\n
"
);
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"
);
...
...
@@ -196,7 +199,7 @@ namespace eosiosystem {
system_token_type
storage_stake_decrease
=
totals
.
storage_stake
*
del
.
unstake_storage_bytes
/
totals
.
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
;
...
...
@@ -215,7 +218,8 @@ 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
currency
::
inline_transfer
(
SystemAccount
,
del
.
from
,
asset
(
total_refund
.
quantity
),
"unstake bandwidth"
);
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
();
parameters
.
total_storage_bytes_reserved
-=
del
.
unstake_storage_bytes
;
...
...
contracts/eosio.system/eosio.system.abi
浏览文件 @
afa5cc22
...
...
@@ -52,7 +52,7 @@
{"name":"receiver", "type":"account_name"},
{"name":"unstake_net", "type":"asset"},
{"name":"unstake_cpu", "type":"asset"},
{"name":"
stake_storag
e_bytes", "type":"uint64"}
{"name":"
unstak
e_bytes", "type":"uint64"}
]
},{
"name": "total_resources",
...
...
contracts/eosio.system/eosio.system.cpp
浏览文件 @
afa5cc22
...
...
@@ -11,7 +11,7 @@ extern "C" {
/// The apply method implements the dispatch of events to this contract
void
apply
(
uint64_t
code
,
uint64_t
act
)
{
print
(
eosio
::
name
(
code
),
"::"
,
eosio
::
name
(
act
)
);
//
print( eosio::name(code), "::", eosio::name(act) );
eosiosystem
::
contract
<
N
(
eosio
)
>::
apply
(
code
,
act
);
}
}
contracts/eosio.system/eosio.system.hpp
浏览文件 @
afa5cc22
...
...
@@ -30,7 +30,8 @@ namespace eosiosystem {
}
static
void
apply
(
account_name
code
,
action_name
act
)
{
if
(
!
eosio
::
dispatch
<
contract
,
typename
delegate_bandwith
<
SystemAccount
>::
delegatebw
,
if
(
!
eosio
::
dispatch
<
currency
,
typename
currency
::
transfer
,
typename
currency
::
issue
>
(
code
,
act
)
)
{
if
(
!
eosio
::
dispatch
<
contract
,
typename
delegate_bandwith
<
SystemAccount
>::
delegatebw
,
typename
delegate_bandwith
<
SystemAccount
>::
undelegatebw
,
typename
voting
<
SystemAccount
>::
register_proxy
,
typename
voting
<
SystemAccount
>::
unregister_proxy
,
...
...
@@ -40,7 +41,6 @@ namespace eosiosystem {
typename
voting
<
SystemAccount
>::
unstake_vote
,
typename
voting
<
SystemAccount
>::
unstake_vote_deferred
,
nonce
>
(
code
,
act
)
)
{
if
(
!
eosio
::
dispatch
<
currency
,
typename
currency
::
transfer
,
typename
currency
::
issue
>
(
code
,
act
)
)
{
eosio
::
print
(
"Unexpected action: "
,
eosio
::
name
(
act
),
"
\n
"
);
eosio_assert
(
false
,
"received unexpected action"
);
}
...
...
contracts/eosiolib/eosiolib.cpp
浏览文件 @
afa5cc22
...
...
@@ -510,4 +510,15 @@ void set_blockchain_parameters(const struct blockchain_parameters* params) {
set_blockchain_parameters_packed
(
data
.
data
(),
data
.
size
()
);
}
int
get_blockchain_parameters_packed
(
char
*
data
,
size_t
datalen
);
void
get_blockchain_parameters
(
struct
blockchain_parameters
*
params
)
{
char
buf
[
sizeof
(
struct
blockchain_parameters
)];
size_t
size
=
get_blockchain_parameters_packed
(
buf
,
sizeof
(
buf
)
);
eosio_assert
(
size
<=
sizeof
(
buf
),
"buffer is too small"
);
static_assert
(
sizeof
(
blockchain_parameters
)
==
sizeof
(
eosio
::
blockchain_parameters
),
"data structures are not the same"
);
eosio
::
datastream
<
const
char
*>
ds
(
buf
,
size_t
(
size
)
);
ds
>>
*
reinterpret_cast
<
eosio
::
blockchain_parameters
*>
(
params
);
}
}
tests/wasm_tests/eosio.system_tests.cpp
浏览文件 @
afa5cc22
...
...
@@ -85,8 +85,7 @@ BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE
(
delegate_to_myself
,
eosio_system_tester
)
try
{
issue
(
"alice"
,
"1000.0000 EOS"
,
config
::
system_account_name
);
auto
balance
=
get_balance
(
"alice"
);
std
::
cout
<<
"Balance: "
<<
N
(
alice
)
<<
": "
<<
balance
<<
std
::
endl
;
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000.0000 EOS"
),
get_balance
(
"alice"
)
);
push_action
(
N
(
alice
),
N
(
delegatebw
),
mvo
()
(
"from"
,
"alice"
)
...
...
@@ -97,13 +96,30 @@ BOOST_FIXTURE_TEST_CASE( delegate_to_myself, eosio_system_tester ) try {
);
auto
stake
=
get_total_stake
(
"alice"
);
BOOST_REQUIRE_EQUAL
(
2000000
,
stake
[
"net_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
1000000
,
stake
[
"cpu_weight"
].
as_uint64
());
BOOST_REQUIRE_EQUAL
(
3000000
,
stake
[
"storage_stake"
].
as_uint64
());
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
());
balance
=
get_balance
(
"alice"
);
std
::
cout
<<
"Balance: "
<<
balance
<<
std
::
endl
;
auto
bytes
=
stake
[
"storage_bytes"
].
as_uint64
(
);
BOOST_REQUIRE_EQUAL
(
true
,
0
<
bytes
)
;
}
FC_LOG_AND_RETHROW
()
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"400.0000 EOS"
),
get_balance
(
"alice"
)
);
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"
);
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());
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录