Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
22923514
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,发现更多精彩内容 >>
未验证
提交
22923514
编写于
2月 20, 2018
作者:
W
wanderingbort
提交者:
GitHub
2月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1380 from cj-oci/improveTestingFixture-stat576
Test framework improvement - stat576
上级
f0bd4800
e3dc3082
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
65 deletion
+72
-65
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+9
-4
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+61
-60
tests/chain_tests/block_tests.cpp
tests/chain_tests/block_tests.cpp
+2
-1
未找到文件。
libraries/testing/include/eosio/testing/tester.hpp
浏览文件 @
22923514
...
...
@@ -9,20 +9,18 @@ namespace eosio { namespace testing {
using
namespace
eosio
::
chain
;
/**
* @class tester
* @brief provides utility function to simplify the creation of unit tests
*/
class
tester
{
class
base_
tester
{
public:
typedef
string
action_result
;
tester
(
chain_controller
::
runtime_limits
limits
=
chain_controller
::
runtime_limits
(),
bool
process_genesis
=
true
);
base_tester
(
chain_controller
::
runtime_limits
limits
=
chain_controller
::
runtime_limits
()
);
void
close
();
void
open
();
void
push_genesis_block
();
signed_block
produce_block
(
fc
::
microseconds
skip_time
=
fc
::
milliseconds
(
config
::
block_interval_ms
)
);
void
produce_blocks
(
uint32_t
n
=
1
);
...
...
@@ -105,6 +103,13 @@ namespace eosio { namespace testing {
map
<
transaction_id_type
,
transaction_receipt
>
chain_transactions
;
};
class
tester
:
public
base_tester
{
public:
tester
(
chain_controller
::
runtime_limits
limits
=
chain_controller
::
runtime_limits
());
void
push_genesis_block
();
};
/**
* Utility predicate to check whether an FC_ASSERT message ends with a given string
*/
...
...
libraries/testing/tester.cpp
浏览文件 @
22923514
...
...
@@ -18,7 +18,7 @@
namespace
eosio
{
namespace
testing
{
tester
::
tester
(
chain_controller
::
runtime_limits
limits
,
bool
process_genesi
s
)
{
base_tester
::
base_tester
(
chain_controller
::
runtime_limits
limit
s
)
{
cfg
.
block_log_dir
=
tempdir
.
path
()
/
"blocklog"
;
cfg
.
shared_memory_dir
=
tempdir
.
path
()
/
"shared"
;
cfg
.
shared_memory_size
=
1024
*
1024
*
8
;
...
...
@@ -27,28 +27,22 @@ namespace eosio { namespace testing {
cfg
.
genesis
.
initial_key
=
get_public_key
(
config
::
system_account_name
,
"active"
);
cfg
.
limits
=
limits
;
open
();
if
(
process_genesis
)
push_genesis_block
();
}
void
tester
::
push_genesis_block
()
{
set_code
(
config
::
system_account_name
,
test_system_wast
);
set_abi
(
config
::
system_account_name
,
test_system_abi
);
}
public_key_type
tester
::
get_public_key
(
name
keyname
,
string
role
)
const
{
public_key_type
base_tester
::
get_public_key
(
name
keyname
,
string
role
)
const
{
return
get_private_key
(
keyname
,
role
).
get_public_key
();
}
private_key_type
tester
::
get_private_key
(
name
keyname
,
string
role
)
const
{
private_key_type
base_
tester
::
get_private_key
(
name
keyname
,
string
role
)
const
{
return
private_key_type
::
regenerate
<
fc
::
ecc
::
private_key_shim
>
(
fc
::
sha256
::
hash
(
string
(
keyname
)
+
role
));
}
void
tester
::
close
()
{
void
base_
tester
::
close
()
{
control
.
reset
();
chain_transactions
.
clear
();
}
void
tester
::
open
()
{
void
base_tester
::
open
()
{
control
.
reset
(
new
chain_controller
(
cfg
)
);
chain_transactions
.
clear
();
control
->
applied_block
.
connect
([
this
](
const
block_trace
&
trace
){
...
...
@@ -64,7 +58,7 @@ namespace eosio { namespace testing {
});
}
signed_block
tester
::
produce_block
(
fc
::
microseconds
skip_time
)
{
signed_block
base_
tester
::
produce_block
(
fc
::
microseconds
skip_time
)
{
auto
head_time
=
control
->
head_block_time
();
auto
next_time
=
head_time
+
skip_time
;
uint32_t
slot
=
control
->
get_slot_at_time
(
next_time
);
...
...
@@ -74,18 +68,16 @@ namespace eosio { namespace testing {
return
control
->
generate_block
(
next_time
,
sch_pro
,
priv_key
,
skip_missed_block_penalty
);
}
void
tester
::
produce_blocks
(
uint32_t
n
)
{
void
base_tester
::
produce_blocks
(
uint32_t
n
)
{
for
(
uint32_t
i
=
0
;
i
<
n
;
++
i
)
produce_block
();
}
void
tester
::
set_tapos
(
signed_transaction
&
trx
)
const
{
void
base_
tester
::
set_tapos
(
signed_transaction
&
trx
)
const
{
trx
.
set_reference_block
(
control
->
head_block_id
()
);
}
void
tester
::
create_account
(
account_name
a
,
account_name
creator
,
bool
multisig
)
{
void
base_tester
::
create_account
(
account_name
a
,
account_name
creator
,
bool
multisig
)
{
signed_transaction
trx
;
set_tapos
(
trx
);
...
...
@@ -111,16 +103,16 @@ namespace eosio { namespace testing {
push_transaction
(
trx
);
}
transaction_trace
tester
::
push_transaction
(
packed_transaction
&
trx
)
{
transaction_trace
base_
tester
::
push_transaction
(
packed_transaction
&
trx
)
{
return
control
->
push_transaction
(
trx
);
}
transaction_trace
tester
::
push_transaction
(
signed_transaction
&
trx
)
{
transaction_trace
base_
tester
::
push_transaction
(
signed_transaction
&
trx
)
{
auto
ptrx
=
packed_transaction
(
trx
);
return
push_transaction
(
ptrx
);
}
tester
::
action_result
tester
::
push_action
(
action
&&
cert_act
,
uint64_t
authorizer
)
{
base_tester
::
action_result
base_
tester
::
push_action
(
action
&&
cert_act
,
uint64_t
authorizer
)
{
signed_transaction
trx
;
if
(
authorizer
)
{
cert_act
.
authorization
=
vector
<
permission_level
>
{{
authorizer
,
config
::
active_name
}};
...
...
@@ -140,7 +132,33 @@ namespace eosio { namespace testing {
return
success
();
}
transaction_trace
tester
::
push_reqauth
(
account_name
from
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
)
{
transaction_trace
base_tester
::
push_action
(
const
account_name
&
code
,
const
action_name
&
acttype
,
const
account_name
&
actor
,
const
variant_object
&
data
)
{
try
{
chain
::
contracts
::
abi_serializer
abis
(
control
->
get_database
().
get
<
account_object
,
by_name
>
(
code
).
get_abi
()
);
string
action_type_name
=
abis
.
get_action_type
(
acttype
);
action
act
;
act
.
account
=
code
;
act
.
name
=
acttype
;
act
.
authorization
=
vector
<
permission_level
>
{{
actor
,
config
::
active_name
}};
act
.
data
=
abis
.
variant_to_binary
(
action_type_name
,
data
);
wdump
((
act
));
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
std
::
move
(
act
));
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
actor
,
"active"
),
chain_id_type
());
wdump
((
get_public_key
(
actor
,
"active"
)));;
return
push_transaction
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
code
)(
acttype
)(
actor
)
)
}
transaction_trace
base_tester
::
push_reqauth
(
account_name
from
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
...
...
@@ -161,8 +179,7 @@ namespace eosio { namespace testing {
return
push_transaction
(
trx
);
}
transaction_trace
tester
::
push_nonce
(
account_name
from
,
const
string
&
v
)
{
transaction_trace
base_tester
::
push_nonce
(
account_name
from
,
const
string
&
v
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
...
...
@@ -187,11 +204,11 @@ namespace eosio { namespace testing {
return
push_transaction
(
trx
);
}
transaction_trace
tester
::
transfer
(
account_name
from
,
account_name
to
,
string
amount
,
string
memo
,
account_name
currency
)
{
transaction_trace
base_
tester
::
transfer
(
account_name
from
,
account_name
to
,
string
amount
,
string
memo
,
account_name
currency
)
{
return
transfer
(
from
,
to
,
asset
::
from_string
(
amount
),
memo
,
currency
);
}
transaction_trace
tester
::
transfer
(
account_name
from
,
account_name
to
,
asset
amount
,
string
memo
,
account_name
currency
)
{
transaction_trace
base_
tester
::
transfer
(
account_name
from
,
account_name
to
,
asset
amount
,
string
memo
,
account_name
currency
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
...
...
@@ -219,7 +236,7 @@ namespace eosio { namespace testing {
return
push_transaction
(
trx
);
}
void
tester
::
set_authority
(
account_name
account
,
void
base_
tester
::
set_authority
(
account_name
account
,
permission_name
perm
,
authority
auth
,
permission_name
parent
)
{
try
{
...
...
@@ -237,7 +254,7 @@ namespace eosio { namespace testing {
push_transaction
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
account
)(
perm
)(
auth
)(
parent
)
)
}
void
tester
::
set_code
(
account_name
account
,
const
char
*
wast
)
try
{
void
base_
tester
::
set_code
(
account_name
account
,
const
char
*
wast
)
try
{
const
auto
assemble
=
[](
const
char
*
wast
)
->
vector
<
unsigned
char
>
{
using
namespace
IR
;
using
namespace
WAST
;
...
...
@@ -295,7 +312,7 @@ namespace eosio { namespace testing {
push_transaction
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
account
)(
wast
)
)
void
tester
::
set_abi
(
account_name
account
,
const
char
*
abi_json
)
{
void
base_
tester
::
set_abi
(
account_name
account
,
const
char
*
abi_json
)
{
auto
abi
=
fc
::
json
::
from_string
(
abi_json
).
template
as
<
contracts
::
abi_def
>();
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
account
,
config
::
active_name
}},
...
...
@@ -309,18 +326,18 @@ namespace eosio { namespace testing {
push_transaction
(
trx
);
}
bool
tester
::
chain_has_transaction
(
const
transaction_id_type
&
txid
)
const
{
bool
base_
tester
::
chain_has_transaction
(
const
transaction_id_type
&
txid
)
const
{
return
chain_transactions
.
count
(
txid
)
!=
0
;
}
const
transaction_receipt
&
tester
::
get_transaction_receipt
(
const
transaction_id_type
&
txid
)
const
{
const
transaction_receipt
&
base_
tester
::
get_transaction_receipt
(
const
transaction_id_type
&
txid
)
const
{
return
chain_transactions
.
at
(
txid
);
}
/**
* Reads balance as stored by generic_currency contract
*/
asset
tester
::
get_currency_balance
(
const
account_name
&
code
,
asset
base_
tester
::
get_currency_balance
(
const
account_name
&
code
,
const
symbol
&
asset_symbol
,
const
account_name
&
account
)
const
{
const
auto
&
db
=
control
->
get_database
();
...
...
@@ -338,26 +355,26 @@ namespace eosio { namespace testing {
return
asset
(
result
,
asset_symbol
);
}
vector
<
uint8_t
>
tester
::
to_uint8_vector
(
const
string
&
s
)
{
vector
<
uint8_t
>
base_
tester
::
to_uint8_vector
(
const
string
&
s
)
{
vector
<
uint8_t
>
v
(
s
.
size
());
copy
(
s
.
begin
(),
s
.
end
(),
v
.
begin
());
return
v
;
};
vector
<
uint8_t
>
tester
::
to_uint8_vector
(
uint64_t
x
)
{
vector
<
uint8_t
>
base_
tester
::
to_uint8_vector
(
uint64_t
x
)
{
vector
<
uint8_t
>
v
(
sizeof
(
x
));
*
reinterpret_cast
<
uint64_t
*>
(
v
.
data
())
=
x
;
return
v
;
};
uint64_t
tester
::
to_uint64
(
fc
::
variant
x
)
{
uint64_t
base_
tester
::
to_uint64
(
fc
::
variant
x
)
{
vector
<
uint8_t
>
blob
;
fc
::
from_variant
<
uint8_t
>
(
x
,
blob
);
FC_ASSERT
(
8
==
blob
.
size
());
return
*
reinterpret_cast
<
uint64_t
*>
(
blob
.
data
());
}
string
tester
::
to_string
(
fc
::
variant
x
)
{
string
base_
tester
::
to_string
(
fc
::
variant
x
)
{
vector
<
uint8_t
>
v
;
fc
::
from_variant
<
uint8_t
>
(
x
,
v
);
string
s
(
v
.
size
(),
0
);
...
...
@@ -365,30 +382,14 @@ namespace eosio { namespace testing {
return
s
;
}
transaction_trace
tester
::
push_action
(
const
account_name
&
code
,
const
action_name
&
acttype
,
const
account_name
&
actor
,
const
variant_object
&
data
)
{
try
{
chain
::
contracts
::
abi_serializer
abis
(
control
->
get_database
().
get
<
account_object
,
by_name
>
(
code
).
get_abi
()
);
string
action_type_name
=
abis
.
get_action_type
(
acttype
);
action
act
;
act
.
account
=
code
;
act
.
name
=
acttype
;
act
.
authorization
=
vector
<
permission_level
>
{{
actor
,
config
::
active_name
}};
act
.
data
=
abis
.
variant_to_binary
(
action_type_name
,
data
);
wdump
((
act
));
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
std
::
move
(
act
));
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
actor
,
"active"
),
chain_id_type
());
wdump
((
get_public_key
(
actor
,
"active"
)));;
tester
::
tester
(
chain_controller
::
runtime_limits
limits
)
:
base_tester
(
limits
)
{
push_genesis_block
();
}
return
push_transaction
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
code
)(
acttype
)(
actor
)
)
}
void
tester
::
push_genesis_block
()
{
set_code
(
config
::
system_account_name
,
test_system_wast
);
set_abi
(
config
::
system_account_name
,
test_system_abi
);
}
}
}
/// eosio::test
tests/chain_tests/block_tests.cpp
浏览文件 @
22923514
...
...
@@ -36,7 +36,8 @@ BOOST_AUTO_TEST_CASE( schedule_test ) { try {
}
FC_LOG_AND_RETHROW
()
}
/// schedule_test
BOOST_AUTO_TEST_CASE
(
push_block
)
{
try
{
tester
test1
,
test2
(
chain_controller
::
runtime_limits
(),
false
);
tester
test1
;
base_tester
test2
;
for
(
uint32
i
=
0
;
i
<
1000
;
++
i
)
{
test2
.
control
->
push_block
(
test1
.
produce_block
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录