Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
c85e061d
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,发现更多精彩内容 >>
提交
c85e061d
编写于
4月 17, 2018
作者:
K
Kayan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
created unit test cases for 353(DAWN-472) for ram_limit, weighted cpu/net limit
上级
41ea5d97
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
148 addition
and
0 deletion
+148
-0
tests/chain_tests/block_tests.cpp
tests/chain_tests/block_tests.cpp
+29
-0
tests/wasm_tests/wasm_tests.cpp
tests/wasm_tests/wasm_tests.cpp
+119
-0
未找到文件。
tests/chain_tests/block_tests.cpp
浏览文件 @
c85e061d
...
...
@@ -1029,5 +1029,34 @@ BOOST_AUTO_TEST_CASE(transaction_mroot)
}
FC_LOG_AND_RETHROW
()
}
BOOST_AUTO_TEST_CASE
(
account_ram_limit
)
{
try
{
const
int64_t
ramlimit
=
5000
;
validating_tester
chain
;
resource_limits_manager
mgr
=
chain
.
control
->
get_mutable_resource_limits_manager
();
account_name
acc1
=
N
(
test1
);
chain
.
create_account
(
acc1
);
mgr
.
set_account_limits
(
acc1
,
ramlimit
,
-
1
,
-
1
);
transaction_trace
trace
=
chain
.
create_account
(
N
(
acc2
),
acc1
);
chain
.
produce_block
();
BOOST_ASSERT
(
trace
.
status
==
transaction_trace
::
executed
);
trace
=
chain
.
create_account
(
N
(
acc3
),
acc1
);
chain
.
produce_block
();
BOOST_ASSERT
(
trace
.
status
==
transaction_trace
::
executed
);
BOOST_REQUIRE_EXCEPTION
(
chain
.
create_account
(
N
(
acc4
),
acc1
),
tx_resource_exhausted
,
[]
(
const
tx_resource_exhausted
&
e
)
->
bool
{
BOOST_REQUIRE_EQUAL
(
std
::
string
(
"transaction exhausted allowed resources"
),
e
.
what
());
return
true
;
}
);
}
FC_LOG_AND_RETHROW
()
}
BOOST_AUTO_TEST_SUITE_END
()
tests/wasm_tests/wasm_tests.cpp
浏览文件 @
c85e061d
...
...
@@ -521,6 +521,70 @@ BOOST_FIXTURE_TEST_CASE(cpu_usage_tests, tester ) try {
BOOST_REQUIRE_EQUAL
(
true
,
limit
>
101
&&
limit
<
250
);
}
FC_LOG_AND_RETHROW
()
// test weighted cpu limit
BOOST_FIXTURE_TEST_CASE
(
weighted_cpu_limit_tests
,
tester
)
try
{
resource_limits_manager
mgr
=
control
->
get_mutable_resource_limits_manager
();
create_accounts
(
{
N
(
f_tests
)}
);
create_accounts
(
{
N
(
acc2
)}
);
bool
pass
=
false
;
std
::
string
code
=
R"=====(
(module
(import "env" "require_auth" (func $require_auth (param i64)))
(import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
(table 0 anyfunc)
(memory $0 1)
(export "apply" (func $apply))
(func $i64_trunc_u_f64 (param $0 f64) (result i64) (i64.trunc_u/f64 (get_local $0)))
(func $test (param $0 i64))
(func $apply (param $0 i64)(param $1 i64)(param $2 i64)
)====="
;
for
(
int
i
=
0
;
i
<
1024
;
++
i
)
{
code
+=
"(call $test (call $i64_trunc_u_f64 (f64.const 1)))
\n
"
;
}
code
+=
"))"
;
produce_blocks
(
1
);
set_code
(
N
(
f_tests
),
code
.
c_str
());
produce_blocks
(
10
);
mgr
.
set_account_limits
(
N
(
f_tests
),
-
1
,
-
1
,
1
);
int
count
=
0
;
while
(
count
<
12
)
{
signed_transaction
trx
;
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
action
act
;
act
.
account
=
N
(
f_tests
);
act
.
name
=
N
()
+
(
i
*
16
);
act
.
authorization
=
vector
<
permission_level
>
{{
N
(
f_tests
),
config
::
active_name
}};
trx
.
actions
.
push_back
(
act
);
}
set_transaction_headers
(
trx
);
trx
.
sign
(
get_private_key
(
N
(
f_tests
),
"active"
),
chain_id_type
());
try
{
push_transaction
(
trx
);
produce_blocks
(
1
);
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trx
.
id
()));
pass
=
true
;
count
++
;
}
catch
(
eosio
::
chain
::
tx_resource_exhausted
&
)
{
BOOST_ASSERT
(
count
==
10
);
break
;
}
BOOST_REQUIRE_EQUAL
(
true
,
validate
());
if
(
count
==
10
)
{
// add a big weight on acc2, making f_tests out of resource
mgr
.
set_account_limits
(
N
(
acc2
),
-
1
,
-
1
,
1000
);
}
}
BOOST_ASSERT
(
count
==
10
);
}
FC_LOG_AND_RETHROW
()
/**
* Make sure WASM "start" method is used correctly
*/
...
...
@@ -1345,4 +1409,59 @@ BOOST_FIXTURE_TEST_CASE(net_usage_tests, tester ) try {
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
weighted_net_usage_tests
,
tester
)
try
{
account_name
account
=
N
(
f_tests
);
account_name
acc2
=
N
(
acc2
);
create_accounts
({
account
,
acc2
});
int
ver
=
0
;
auto
check
=
[
&
](
int
coderepeat
)
->
bool
{
std
::
string
code
=
R"=====(
(module
(import "env" "require_auth" (func $require_auth (param i64)))
(import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
(table 0 anyfunc)
(memory $0 1)
(export "apply" (func $apply))
(func $i64_trunc_u_f64 (param $0 f64) (result i64) (i64.trunc_u/f64 (get_local $0)))
(func $test (param $0 i64))
(func $apply (param $0 i64)(param $1 i64)(param $2 i64)
)====="
;
for
(
int
i
=
0
;
i
<
coderepeat
;
++
i
)
{
code
+=
"(call $test (call $i64_trunc_u_f64 (f64.const "
;
code
+=
(
char
)(
'0'
+
ver
);
code
+=
")))
\n
"
;
}
code
+=
"))"
;
ver
++
;
produce_blocks
(
1
);
signed_transaction
trx
;
auto
wasm
=
::
eosio
::
chain
::
wast_to_wasm
(
code
);
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
account
,
config
::
active_name
}},
contracts
::
setcode
{
.
account
=
account
,
.
vmtype
=
0
,
.
vmversion
=
0
,
.
code
=
bytes
(
wasm
.
begin
(),
wasm
.
end
())
});
set_transaction_headers
(
trx
);
trx
.
sign
(
get_private_key
(
account
,
"active"
),
chain_id_type
()
);
try
{
push_transaction
(
trx
);
produce_blocks
(
1
);
return
true
;
}
catch
(
tx_resource_exhausted
&
)
{
return
false
;
}
};
BOOST_REQUIRE_EQUAL
(
true
,
check
(
128
));
// no limits, should pass
resource_limits_manager
mgr
=
control
->
get_mutable_resource_limits_manager
();
mgr
.
set_account_limits
(
account
,
-
1
,
1
,
-
1
);
// set weight = 1 for account
BOOST_REQUIRE_EQUAL
(
true
,
check
(
128
));
mgr
.
set_account_limits
(
acc2
,
-
1
,
1000
,
-
1
);
// set a big weight for other account
BOOST_REQUIRE_EQUAL
(
false
,
check
(
128
));
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录