Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
05bac683
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,发现更多精彩内容 >>
未验证
提交
05bac683
编写于
3月 16, 2018
作者:
K
Kevin Heifner
提交者:
GitHub
3月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1650 from EOSIO/DAWN-379
DAWN 379 - Restore block_tests
上级
51f24f4c
d8e6d99a
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
725 addition
and
602 deletion
+725
-602
libraries/testing/CMakeLists.txt
libraries/testing/CMakeLists.txt
+1
-0
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+8
-3
libraries/testing/include/eosio/testing/tester_network.hpp
libraries/testing/include/eosio/testing/tester_network.hpp
+48
-0
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+64
-6
libraries/testing/tester_network.cpp
libraries/testing/tester_network.cpp
+39
-0
tests/chain_tests/block_tests.cpp
tests/chain_tests/block_tests.cpp
+565
-2
tests/tests/block_tests.cpp
tests/tests/block_tests.cpp
+0
-591
未找到文件。
libraries/testing/CMakeLists.txt
浏览文件 @
05bac683
...
...
@@ -3,6 +3,7 @@ file(GLOB HEADERS "include/eosio/testing/*.hpp")
## SORT .cpp by most likely to change / break compile
add_library
(
eosio_testing
tester.cpp
tester_network.cpp
${
HEADERS
}
)
...
...
libraries/testing/include/eosio/testing/tester.hpp
浏览文件 @
05bac683
...
...
@@ -18,15 +18,17 @@ namespace eosio { namespace testing {
typedef
string
action_result
;
base_tester
(
chain_controller
::
runtime_limits
limits
=
chain_controller
::
runtime_limits
());
explicit
base_tester
(
chain_controller
::
controller_config
config
);
void
close
();
void
open
();
signed_block
produce_block
(
fc
::
microseconds
skip_time
=
fc
::
milliseconds
(
config
::
block_interval_ms
)
);
signed_block
produce_block
(
fc
::
microseconds
skip_time
=
fc
::
milliseconds
(
config
::
block_interval_ms
)
,
uint32_t
skip_flag
=
skip_missed_block_penalty
);
void
produce_blocks
(
uint32_t
n
=
1
);
void
produce_blocks_until_end_of_round
();
transaction_trace
push_transaction
(
packed_transaction
&
trx
);
transaction_trace
push_transaction
(
signed_transaction
&
trx
);
transaction_trace
push_transaction
(
packed_transaction
&
trx
,
uint32_t
skip_flag
=
skip_nothing
);
transaction_trace
push_transaction
(
signed_transaction
&
trx
,
uint32_t
skip_flag
=
skip_nothing
);
action_result
push_action
(
action
&&
cert_act
,
uint64_t
authorizer
);
transaction_trace
push_action
(
const
account_name
&
code
,
const
action_name
&
act
,
const
account_name
&
signer
,
const
variant_object
&
data
);
...
...
@@ -112,6 +114,7 @@ namespace eosio { namespace testing {
};
}
void
sync_with
(
base_tester
&
other
);
private:
fc
::
temp_directory
tempdir
;
...
...
@@ -123,8 +126,10 @@ namespace eosio { namespace testing {
class
tester
:
public
base_tester
{
public:
tester
(
chain_controller
::
runtime_limits
limits
=
chain_controller
::
runtime_limits
());
tester
(
chain_controller
::
controller_config
config
);
void
push_genesis_block
();
void
set_producers
(
const
vector
<
account_name
>&
producer_names
);
};
/**
...
...
libraries/testing/include/eosio/testing/tester_network.hpp
0 → 100644
浏览文件 @
05bac683
#pragma once
#include "tester.hpp"
#include <boost/signals2/signal.hpp>
#include <boost/signals2/shared_connection_block.hpp>
namespace
eosio
{
namespace
testing
{
using
namespace
boost
::
signals2
;
/**
* @brief The tester_network class provides a simplistic virtual P2P network connecting testing_blockchains together.
*
* A tester may be connected to zero or more tester_networks at any given time. When a new
* tester joins the network, it will be synced with all other blockchains already in the network (blocks
* known only to the new chain will be pushed to the prior network members and vice versa, ignoring blocks not on the
* main fork). After this, whenever any blockchain in the network gets a new block, that block will be pushed to all
* other blockchains in the network as well.
*/
class
tester_network
{
public:
/**
* @brief Add a new blockchain to the network
* @param new_blockchain The blockchain to add
*/
void
connect_blockchain
(
tester
&
new_blockchain
);
/**
* @brief Remove a blockchain from the network
* @param leaving_blockchain The blockchain to remove
*/
void
disconnect_blockchain
(
tester
&
leaving_blockchain
);
/**
* @brief Disconnect all blockchains from the network
*/
void
disconnect_all
();
/**
* @brief Send a block to all blockchains in this network
* @param block The block to send
*/
void
propagate_block
(
const
signed_block
&
block
,
const
tester
&
skip_db
);
protected:
std
::
map
<
tester
*
,
scoped_connection
>
blockchains
;
};
}
}
/// eosio::testing
\ No newline at end of file
libraries/testing/tester.cpp
浏览文件 @
05bac683
...
...
@@ -30,6 +30,11 @@ namespace eosio { namespace testing {
open
();
}
base_tester
::
base_tester
(
chain_controller
::
controller_config
config
)
{
cfg
=
config
;
open
();
}
public_key_type
base_tester
::
get_public_key
(
name
keyname
,
string
role
)
const
{
return
get_private_key
(
keyname
,
role
).
get_public_key
();
}
...
...
@@ -59,14 +64,14 @@ namespace eosio { namespace testing {
});
}
signed_block
base_tester
::
produce_block
(
fc
::
microseconds
skip_time
)
{
signed_block
base_tester
::
produce_block
(
fc
::
microseconds
skip_time
,
uint32_t
skip_flag
)
{
auto
head_time
=
control
->
head_block_time
();
auto
next_time
=
head_time
+
skip_time
;
uint32_t
slot
=
control
->
get_slot_at_time
(
next_time
);
auto
sch_pro
=
control
->
get_scheduled_producer
(
slot
);
auto
priv_key
=
get_private_key
(
sch_pro
,
"active"
);
return
control
->
generate_block
(
next_time
,
sch_pro
,
priv_key
,
skip_
missed_block_penalty
);
return
control
->
generate_block
(
next_time
,
sch_pro
,
priv_key
,
skip_
flag
);
}
void
base_tester
::
produce_blocks
(
uint32_t
n
)
{
...
...
@@ -74,6 +79,15 @@ namespace eosio { namespace testing {
produce_block
();
}
void
base_tester
::
produce_blocks_until_end_of_round
()
{
uint64_t
blocks_per_round
;
while
(
true
)
{
blocks_per_round
=
control
->
get_global_properties
().
active_producers
.
producers
.
size
()
*
config
::
producer_repetitions
;
produce_block
();
if
(
control
->
head_block_num
()
%
blocks_per_round
==
(
blocks_per_round
-
1
)
)
break
;
}
}
void
base_tester
::
set_tapos
(
signed_transaction
&
trx
)
const
{
trx
.
set_reference_block
(
control
->
head_block_id
()
);
}
...
...
@@ -104,13 +118,13 @@ namespace eosio { namespace testing {
push_transaction
(
trx
);
}
transaction_trace
base_tester
::
push_transaction
(
packed_transaction
&
trx
)
{
return
control
->
push_transaction
(
trx
);
transaction_trace
base_tester
::
push_transaction
(
packed_transaction
&
trx
,
uint32_t
skip_flag
)
{
return
control
->
push_transaction
(
trx
,
skip_flag
);
}
transaction_trace
base_tester
::
push_transaction
(
signed_transaction
&
trx
)
{
transaction_trace
base_tester
::
push_transaction
(
signed_transaction
&
trx
,
uint32_t
skip_flag
)
{
auto
ptrx
=
packed_transaction
(
trx
);
return
push_transaction
(
ptrx
);
return
push_transaction
(
ptrx
,
skip_flag
);
}
base_tester
::
action_result
base_tester
::
push_action
(
action
&&
cert_act
,
uint64_t
authorizer
)
{
...
...
@@ -421,14 +435,58 @@ namespace eosio { namespace testing {
return
s
;
}
void
base_tester
::
sync_with
(
base_tester
&
other
)
{
// Already in sync?
if
(
control
->
head_block_id
()
==
other
.
control
->
head_block_id
())
return
;
// If other has a longer chain than we do, sync it to us first
if
(
control
->
head_block_num
()
<
other
.
control
->
head_block_num
())
return
other
.
sync_with
(
*
this
);
auto
sync_dbs
=
[](
base_tester
&
a
,
base_tester
&
b
)
{
for
(
int
i
=
1
;
i
<=
a
.
control
->
head_block_num
();
++
i
)
{
auto
block
=
a
.
control
->
fetch_block_by_number
(
i
);
if
(
block
&&
!
b
.
control
->
is_known_block
(
block
->
id
()))
{
b
.
control
->
push_block
(
*
block
,
eosio
::
chain
::
validation_steps
::
created_block
);
}
}
};
sync_dbs
(
*
this
,
other
);
sync_dbs
(
other
,
*
this
);
}
tester
::
tester
(
chain_controller
::
runtime_limits
limits
)
:
base_tester
(
limits
)
{
push_genesis_block
();
}
tester
::
tester
(
chain_controller
::
controller_config
config
)
:
base_tester
(
config
)
{};
void
tester
::
push_genesis_block
()
{
set_code
(
config
::
system_account_name
,
test_system_wast
);
set_abi
(
config
::
system_account_name
,
test_system_abi
);
}
void
tester
::
set_producers
(
const
vector
<
account_name
>&
producer_names
)
{
// Create producer accounts, if it does not exist yet
for
(
auto
&
producer_name
:
producer_names
)
{
create_account
(
producer_name
);
}
// Construct the param for setprods action
vector
<
fc
::
mutable_variant_object
>
producer_keys
;
for
(
auto
&
producer_name
:
producer_names
)
{
producer_keys
.
emplace_back
(
fc
::
mutable_variant_object
()
(
"producer_name"
,
producer_name
)
(
"signing_key"
,
get_public_key
(
producer_name
,
"active"
)));
}
// Send setprods action
static
uint32_t
version
=
1
;
push_action
(
N
(
eosio
),
N
(
setprods
),
N
(
eosio
),
fc
::
mutable_variant_object
()
(
"version"
,
version
++
)
(
"producers"
,
producer_keys
));
}
}
}
/// eosio::test
libraries/testing/tester_network.cpp
0 → 100644
浏览文件 @
05bac683
#include <eosio/testing/tester_network.hpp>
namespace
eosio
{
namespace
testing
{
void
tester_network
::
connect_blockchain
(
tester
&
new_blockchain
)
{
if
(
blockchains
.
count
(
&
new_blockchain
))
return
;
// If the network isn't empty, sync the new blockchain with one of the old ones. The old ones are already in sync with
// each other, so just grab one arbitrarily. The old blockchains are connected to the propagation signals, so when one
// of them gets synced, it will propagate blocks to the others as well.
if
(
!
blockchains
.
empty
())
{
blockchains
.
begin
()
->
first
->
sync_with
(
new_blockchain
);
}
// The new blockchain is now in sync with any old ones; go ahead and connect the propagation signal.
blockchains
[
&
new_blockchain
]
=
new_blockchain
.
control
->
applied_block
.
connect
(
[
this
,
&
new_blockchain
](
const
chain
::
block_trace
&
bt
)
{
propagate_block
(
bt
.
block
,
new_blockchain
);
});
}
void
tester_network
::
disconnect_blockchain
(
tester
&
leaving_blockchain
)
{
blockchains
.
erase
(
&
leaving_blockchain
);
}
void
tester_network
::
disconnect_all
()
{
blockchains
.
clear
();
}
void
tester_network
::
propagate_block
(
const
signed_block
&
block
,
const
tester
&
skip_blockchain
)
{
for
(
const
auto
&
pair
:
blockchains
)
{
if
(
pair
.
first
==
&
skip_blockchain
)
continue
;
boost
::
signals2
::
shared_connection_block
blocker
(
pair
.
second
);
pair
.
first
->
control
->
push_block
(
block
,
eosio
::
chain
::
validation_steps
::
created_block
);
}
}
}
}
/// eosio::testing
\ No newline at end of file
tests/chain_tests/block_tests.cpp
浏览文件 @
05bac683
此差异已折叠。
点击以展开。
tests/tests/block_tests.cpp
已删除
100644 → 0
浏览文件 @
51f24f4c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录