Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
377719e1
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,发现更多精彩内容 >>
提交
377719e1
编写于
5月 02, 2018
作者:
K
Kayan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #2626(CFA) with additional unittests
上级
1504771c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
129 addition
and
8 deletion
+129
-8
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+4
-1
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+2
-0
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+10
-0
libraries/chain/transaction_context.cpp
libraries/chain/transaction_context.cpp
+6
-7
unittests/api_tests.cpp
unittests/api_tests.cpp
+107
-0
未找到文件。
contracts/test_api/test_api.cpp
浏览文件 @
377719e1
...
...
@@ -41,7 +41,8 @@ extern "C" {
}
WASM_TEST_HANDLER
(
test_action
,
assert_true_cf
);
require_auth
(
code
);
if
(
action
!=
WASM_TEST_ACTION
(
"test_transaction"
,
"stateful_api"
)
&&
action
!=
WASM_TEST_ACTION
(
"test_transaction"
,
"context_free_api"
))
require_auth
(
code
);
//test_types
WASM_TEST_HANDLER
(
test_types
,
types_size
);
...
...
@@ -139,6 +140,8 @@ extern "C" {
WASM_TEST_HANDLER
(
test_transaction
,
cancel_deferred_transaction
);
WASM_TEST_HANDLER
(
test_transaction
,
send_cf_action
);
WASM_TEST_HANDLER
(
test_transaction
,
send_cf_action_fail
);
WASM_TEST_HANDLER
(
test_transaction
,
stateful_api
);
WASM_TEST_HANDLER
(
test_transaction
,
context_free_api
);
//test chain
WASM_TEST_HANDLER
(
test_chain
,
test_activeprods
);
...
...
contracts/test_api/test_api.hpp
浏览文件 @
377719e1
...
...
@@ -170,6 +170,8 @@ struct test_transaction {
static
void
cancel_deferred_transaction
();
static
void
send_cf_action
();
static
void
send_cf_action_fail
();
static
void
stateful_api
();
static
void
context_free_api
();
};
struct
test_chain
{
...
...
contracts/test_api/test_transaction.cpp
浏览文件 @
377719e1
...
...
@@ -287,3 +287,13 @@ void test_transaction::send_cf_action_fail() {
act
.
send_context_free
();
eosio_assert
(
false
,
"send_cfa_action_fail() should've thrown an error"
);
}
void
test_transaction
::
stateful_api
()
{
char
buf
[
4
]
=
{
1
};
db_store_i64
(
N
(
test_transaction
),
N
(
table
),
N
(
test_transaction
),
0
,
buf
,
4
);
}
void
test_transaction
::
context_free_api
()
{
char
buf
[
128
]
=
{
0
};
get_context_free_data
(
0
,
buf
,
sizeof
(
buf
));
}
libraries/chain/transaction_context.cpp
浏览文件 @
377719e1
...
...
@@ -114,7 +114,7 @@ namespace eosio { namespace chain {
{
trace
->
scheduled
=
true
;
is_input
=
false
;
apply_context_free
=
false
;
//apply_context_free = false; // does CFAs always execute immediately?
}
transaction_context
::
transaction_context
(
transaction_trace_ptr
&
trace_ptr
,
...
...
@@ -142,13 +142,12 @@ namespace eosio { namespace chain {
record_transaction
(
id
,
trx
.
expiration
);
/// checks for dupes
}
if
(
apply_context_free
)
{
for
(
const
auto
&
act
:
trx
.
context_free_actions
)
{
dispatch_action
(
act
,
true
);
}
}
if
(
delay
==
fc
::
microseconds
()
)
{
if
(
apply_context_free
)
{
for
(
const
auto
&
act
:
trx
.
context_free_actions
)
{
dispatch_action
(
act
,
true
);
}
}
for
(
const
auto
&
act
:
trx
.
actions
)
{
dispatch_action
(
act
);
}
...
...
unittests/api_tests.cpp
浏览文件 @
377719e1
...
...
@@ -525,6 +525,113 @@ BOOST_FIXTURE_TEST_CASE(cfa_tx_signature, TESTER) try {
BOOST_REQUIRE_EQUAL
(
validate
(),
true
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
cfa_stateful_api
,
TESTER
)
try
{
create_account
(
N
(
testapi
)
);
produce_blocks
(
1
);
set_code
(
N
(
testapi
),
test_api_wast
);
account_name
a
=
N
(
testapi2
);
account_name
creator
=
N
(
eosio
);
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
creator
,
config
::
active_name
}},
newaccount
{
.
creator
=
creator
,
.
name
=
a
,
.
owner
=
authority
(
get_public_key
(
a
,
"owner"
)
),
.
active
=
authority
(
get_public_key
(
a
,
"active"
)
),
.
recovery
=
authority
(
get_public_key
(
a
,
"recovery"
)
),
});
action
act
({},
test_api_action
<
TEST_METHOD
(
"test_transaction"
,
"stateful_api"
)
>
{});
trx
.
context_free_actions
.
push_back
(
act
);
set_transaction_headers
(
trx
);
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
BOOST_CHECK_EXCEPTION
(
push_transaction
(
trx
),
fc
::
exception
,
[
&
](
const
fc
::
exception
&
e
)
{
return
expect_assert_message
(
e
,
"only context free api's can be used in this context"
);
});
BOOST_REQUIRE_EQUAL
(
validate
(),
true
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
deferred_cfa_failed
,
TESTER
)
try
{
create_account
(
N
(
testapi
)
);
produce_blocks
(
1
);
set_code
(
N
(
testapi
),
test_api_wast
);
account_name
a
=
N
(
testapi2
);
account_name
creator
=
N
(
eosio
);
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
creator
,
config
::
active_name
}},
newaccount
{
.
creator
=
creator
,
.
name
=
a
,
.
owner
=
authority
(
get_public_key
(
a
,
"owner"
)
),
.
active
=
authority
(
get_public_key
(
a
,
"active"
)
),
.
recovery
=
authority
(
get_public_key
(
a
,
"recovery"
)
),
});
action
act
({},
test_api_action
<
TEST_METHOD
(
"test_transaction"
,
"stateful_api"
)
>
{});
trx
.
context_free_actions
.
push_back
(
act
);
set_transaction_headers
(
trx
,
10
,
2
);
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
auto
trace
=
push_transaction
(
trx
);
BOOST_ASSERT
(
trace
!=
nullptr
);
if
(
trace
)
{
BOOST_REQUIRE_EQUAL
(
transaction_receipt_header
::
status_enum
::
delayed
,
trace
->
receipt
.
status
);
BOOST_REQUIRE_EQUAL
(
0
,
trace
->
action_traces
.
size
());
}
produce_blocks
(
10
);
// defered CFA failed, testapi2 creation failed
create_account
(
N
(
testapi2
)
);
BOOST_REQUIRE_EQUAL
(
validate
(),
true
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
deferred_cfa_success
,
TESTER
)
try
{
create_account
(
N
(
testapi
)
);
produce_blocks
(
1
);
set_code
(
N
(
testapi
),
test_api_wast
);
account_name
a
=
N
(
testapi2
);
account_name
creator
=
N
(
eosio
);
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
creator
,
config
::
active_name
}},
newaccount
{
.
creator
=
creator
,
.
name
=
a
,
.
owner
=
authority
(
get_public_key
(
a
,
"owner"
)
),
.
active
=
authority
(
get_public_key
(
a
,
"active"
)
),
.
recovery
=
authority
(
get_public_key
(
a
,
"recovery"
)
),
});
action
act
({},
test_api_action
<
TEST_METHOD
(
"test_transaction"
,
"context_free_api"
)
>
{});
trx
.
context_free_actions
.
push_back
(
act
);
set_transaction_headers
(
trx
,
10
,
2
);
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
auto
trace
=
push_transaction
(
trx
);
BOOST_ASSERT
(
trace
!=
nullptr
);
if
(
trace
)
{
BOOST_REQUIRE_EQUAL
(
transaction_receipt_header
::
status_enum
::
delayed
,
trace
->
receipt
.
status
);
BOOST_REQUIRE_EQUAL
(
0
,
trace
->
action_traces
.
size
());
}
produce_blocks
(
10
);
// defered CFA success, testapi2 already created
BOOST_CHECK_EXCEPTION
(
create_account
(
N
(
testapi2
)
),
fc
::
exception
,
[
&
](
const
fc
::
exception
&
e
)
{
return
expect_assert_message
(
e
,
"Cannot create account named testapi2, as that name is already taken"
);
});
BOOST_REQUIRE_EQUAL
(
validate
(),
true
);
}
FC_LOG_AND_RETHROW
()
/*************************************************************************************
* checktime_tests test case
*************************************************************************************/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录