Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
c059de75
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,发现更多精彩内容 >>
提交
c059de75
编写于
4月 09, 2018
作者:
A
Andrianto Lie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add additional test case for 1972
上级
124c62d0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
53 addition
and
5 deletion
+53
-5
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+6
-3
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+2
-2
tests/chain_tests/block_tests.cpp
tests/chain_tests/block_tests.cpp
+45
-0
未找到文件。
libraries/testing/include/eosio/testing/tester.hpp
浏览文件 @
c059de75
...
@@ -89,8 +89,11 @@ namespace eosio { namespace testing {
...
@@ -89,8 +89,11 @@ namespace eosio { namespace testing {
uint32_t
expiration
=
DEFAULT_EXPIRATION_DELTA
,
uint32_t
expiration
=
DEFAULT_EXPIRATION_DELTA
,
uint32_t
delay_sec
=
0
)
const
;
uint32_t
delay_sec
=
0
)
const
;
void
create_accounts
(
vector
<
account_name
>
names
,
bool
multisig
=
false
)
{
vector
<
transaction_trace
>
create_accounts
(
vector
<
account_name
>
names
,
bool
multisig
=
false
)
{
for
(
auto
n
:
names
)
create_account
(
n
,
config
::
system_account_name
,
multisig
);
vector
<
transaction_trace
>
traces
;
traces
.
reserve
(
names
.
size
());
for
(
auto
n
:
names
)
traces
.
emplace_back
(
create_account
(
n
,
config
::
system_account_name
,
multisig
));
return
traces
;
}
}
void
push_genesis_block
();
void
push_genesis_block
();
...
@@ -105,7 +108,7 @@ namespace eosio { namespace testing {
...
@@ -105,7 +108,7 @@ namespace eosio { namespace testing {
void
delete_authority
(
account_name
account
,
permission_name
perm
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
);
void
delete_authority
(
account_name
account
,
permission_name
perm
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
);
void
delete_authority
(
account_name
account
,
permission_name
perm
);
void
delete_authority
(
account_name
account
,
permission_name
perm
);
void
create_account
(
account_name
name
,
account_name
creator
=
config
::
system_account_name
,
bool
multisig
=
false
);
transaction_trace
create_account
(
account_name
name
,
account_name
creator
=
config
::
system_account_name
,
bool
multisig
=
false
);
transaction_trace
push_reqauth
(
account_name
from
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
);
transaction_trace
push_reqauth
(
account_name
from
,
const
vector
<
permission_level
>&
auths
,
const
vector
<
private_key_type
>&
keys
);
transaction_trace
push_reqauth
(
account_name
from
,
string
role
,
bool
multi_sig
=
false
);
transaction_trace
push_reqauth
(
account_name
from
,
string
role
,
bool
multi_sig
=
false
);
...
...
libraries/testing/tester.cpp
浏览文件 @
c059de75
...
@@ -131,7 +131,7 @@ namespace eosio { namespace testing {
...
@@ -131,7 +131,7 @@ namespace eosio { namespace testing {
}
}
void
base_tester
::
create_account
(
account_name
a
,
account_name
creator
,
bool
multisig
)
{
transaction_trace
base_tester
::
create_account
(
account_name
a
,
account_name
creator
,
bool
multisig
)
{
signed_transaction
trx
;
signed_transaction
trx
;
set_transaction_headers
(
trx
);
set_transaction_headers
(
trx
);
...
@@ -154,7 +154,7 @@ namespace eosio { namespace testing {
...
@@ -154,7 +154,7 @@ namespace eosio { namespace testing {
set_transaction_headers
(
trx
);
set_transaction_headers
(
trx
);
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
push_transaction
(
trx
);
return
push_transaction
(
trx
);
}
}
transaction_trace
base_tester
::
push_transaction
(
packed_transaction
&
trx
,
uint32_t
skip_flag
)
{
try
{
transaction_trace
base_tester
::
push_transaction
(
packed_transaction
&
trx
,
uint32_t
skip_flag
)
{
try
{
...
...
tests/chain_tests/block_tests.cpp
浏览文件 @
c059de75
...
@@ -956,4 +956,49 @@ BOOST_AUTO_TEST_CASE(get_required_keys)
...
@@ -956,4 +956,49 @@ BOOST_AUTO_TEST_CASE(get_required_keys)
}
FC_LOG_AND_RETHROW
()
}
}
FC_LOG_AND_RETHROW
()
}
// Test transaction_mroot matches with the specification in Github #1972 https://github.com/EOSIO/eos/issues/1972
// Which is a root of a Merkle tree over commitments for each region processed in the block ordered in ascending region id order.
// Commitment for each region is a merkle tree over commitments for each shard inside the cycle of that region.
// Commitment for the shard itself is a merkle tree over the transactions commitments inside that shard.
// The transaction commitment is digest of the concentanation of region_id, cycle_index, shard_index, tx_index,
// transaction_receipt and packed_trx_digest (if the tx is an input tx, which doesn't include implicit/ deferred tx)
BOOST_AUTO_TEST_CASE
(
transaction_mroot
)
{
try
{
validating_tester
chain
;
// Finalize current block (which has set contract transaction for eosio)
chain
.
produce_block
();
// any transaction will do
vector
<
transaction_trace
>
traces
=
chain
.
create_accounts
({
"test1"
,
"test2"
,
"test3"
});
// Calculate expected tx roots
vector
<
digest_type
>
tx_roots
;
for
(
uint64_t
tx_index
=
0
;
tx_index
<
traces
.
size
();
tx_index
++
)
{
const
auto
&
tx
=
traces
[
tx_index
];
digest_type
::
encoder
enc
;
// region_id, cycle_index, shard_index, tx_index, transaction_receipt and packed_trx_digest (if the tx is an input tx)
fc
::
raw
::
pack
(
enc
,
tx
.
region_id
);
fc
::
raw
::
pack
(
enc
,
tx
.
cycle_index
);
fc
::
raw
::
pack
(
enc
,
tx
.
shard_index
);
fc
::
raw
::
pack
(
enc
,
tx_index
);
fc
::
raw
::
pack
(
enc
,
*
static_cast
<
const
transaction_receipt
*>
(
&
tx
)
);
if
(
tx
.
packed_trx_digest
.
valid
()
)
fc
::
raw
::
pack
(
enc
,
*
tx
.
packed_trx_digest
);
tx_roots
.
emplace_back
(
enc
.
result
());
}
auto
expected_shard_tx_root
=
merkle
(
tx_roots
);
// Hardcoded on_block tx_root, since there's no easy way to calculate the tx_root with current interface
auto
on_block_tx_root
=
digest_type
(
"aa63d366cc2ef41746bb150258d1c0662c8133469f785425cb996dbe2a227086"
);
// There is only 1 region, 2 cycle, 1 shard in first cycle, 1 shard in second cycle
auto
expected_tx_mroot
=
merkle
({
on_block_tx_root
,
expected_shard_tx_root
});
// Compare with head block tx mroot
chain
.
produce_block
();
auto
head_block_tx_mroot
=
chain
.
control
->
head_block_header
().
transaction_mroot
;
BOOST_TEST
(
expected_tx_mroot
.
str
()
==
head_block_tx_mroot
.
str
());
}
FC_LOG_AND_RETHROW
()
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录