Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
f3c69990
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,发现更多精彩内容 >>
提交
f3c69990
编写于
11月 14, 2017
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
creating testing library for new unit tests
上级
19561e85
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
203 addition
and
11 deletion
+203
-11
libraries/CMakeLists.txt
libraries/CMakeLists.txt
+2
-1
libraries/chain/CMakeLists.txt
libraries/chain/CMakeLists.txt
+3
-3
libraries/chain/chain_controller.cpp
libraries/chain/chain_controller.cpp
+2
-4
libraries/chain/contracts/chain_initializer.cpp
libraries/chain/contracts/chain_initializer.cpp
+2
-2
libraries/chain/contracts/eos_contract.cpp
libraries/chain/contracts/eos_contract.cpp
+1
-1
libraries/chain/include/eosio/chain/config.hpp
libraries/chain/include/eosio/chain/config.hpp
+1
-0
libraries/chain/include/eosio/chain/contracts/types.hpp
libraries/chain/include/eosio/chain/contracts/types.hpp
+2
-0
libraries/chain/include/eosio/chain/wasm_interface.hpp
libraries/chain/include/eosio/chain/wasm_interface.hpp
+4
-0
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+4
-0
libraries/testing/CMakeLists.txt
libraries/testing/CMakeLists.txt
+29
-0
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+39
-0
libraries/testing/main.cpp
libraries/testing/main.cpp
+17
-0
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+97
-0
未找到文件。
libraries/CMakeLists.txt
浏览文件 @
f3c69990
add_subdirectory
(
fc
)
add_subdirectory
(
chainbase
)
add_subdirectory
(
wasm-jit
)
add_subdirectory
(
chain
)
add_subdirectory
(
egenesis
)
add_subdirectory
(
utilities
)
add_subdirectory
(
appbase
)
add_subdirectory
(
chain
)
add_subdirectory
(
testing
)
libraries/chain/CMakeLists.txt
浏览文件 @
f3c69990
...
...
@@ -46,7 +46,7 @@ INSTALL( TARGETS
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
INSTALL
(
FILES
${
HEADERS
}
DESTINATION
"include/eos/chain"
)
INSTALL
(
FILES
${
HEADERS
}
DESTINATION
"include/eos
io
/chain"
)
add_executable
(
test test.cpp
)
target_link_libraries
(
test eos_chain
${
CMAKE_DL_LIBS
}
${
PLATFORM_SPECIFIC_LIBS
}
${
Intl_LIBRARIES
}
)
#
add_executable( test test.cpp )
#
target_link_libraries( test eos_chain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} )
libraries/chain/chain_controller.cpp
浏览文件 @
f3c69990
...
...
@@ -256,13 +256,11 @@ void chain_controller::_push_transaction(const signed_transaction& trx) {
auto
temp_session
=
_db
.
start_undo_session
(
true
);
#if 0
validate_referenced_accounts
(
trx
);
check_transaction_authorization
(
trx
);
/*auto pt = */
_apply_transaction(trx);
_pending_transactions.push_back(trx);
_apply_transaction
(
trx
);
//
_pending_transactions.push_back(trx);
#endif
// notify_changed_objects();
// The transaction applied successfully. Merge its changes into the pending block session.
...
...
libraries/chain/contracts/chain_initializer.cpp
浏览文件 @
f3c69990
...
...
@@ -235,11 +235,11 @@ std::vector<action> chain_initializer::prepare_database( chain_controller& chain
// Queue up messages which will run contracts to create the initial accounts
for
(
const
auto
&
acct
:
genesis
.
initial_accounts
)
{
action
message
(
{{
config
::
system_account_name
,
config
::
active_name
}},
newaccount
(
config
::
system_account_name
,
acct
.
name
,
newaccount
{
config
::
system_account_name
,
acct
.
name
,
authority
(
acct
.
owner_key
),
authority
(
acct
.
active_key
),
authority
(
acct
.
owner_key
),
acct
.
staking_balance
)
);
acct
.
staking_balance
}
);
messages_to_process
.
emplace_back
(
move
(
message
));
...
...
libraries/chain/contracts/eos_contract.cpp
浏览文件 @
f3c69990
...
...
@@ -491,7 +491,7 @@ void apply_eosio_unlinkauth(apply_context& context) {
db
.
remove
(
*
link
);
}
void
apply_eos_nonce
(
apply_context
&
)
{
void
apply_eos
io
_nonce
(
apply_context
&
)
{
/// do nothing
}
...
...
libraries/chain/include/eosio/chain/config.hpp
浏览文件 @
f3c69990
...
...
@@ -19,6 +19,7 @@ const static uint64_t system_account_name = N(eosio);
const
static
uint64_t
nobody_account_name
=
N
(
nobody
);
const
static
uint64_t
anybody_account_name
=
N
(
anybody
);
const
static
uint64_t
producers_account_name
=
N
(
producers
);
const
static
uint64_t
eosio_auth_scope
=
N
(
eosio
.
auth
);
const
static
uint64_t
active_name
=
N
(
active
);
const
static
uint64_t
owner_name
=
N
(
owner
);
...
...
libraries/chain/include/eosio/chain/contracts/types.hpp
浏览文件 @
f3c69990
...
...
@@ -178,10 +178,12 @@ struct claim {
};
struct
newaccount
{
/*
newaccount() = default;
newaccount(const account_name& creator, const account_name& name, const authority& owner, const authority& active, const authority& recovery, const asset& deposit)
:creator(creator), name(name), owner(owner), active(active), recovery(recovery), deposit(deposit)
{}
*/
account_name
creator
;
account_name
name
;
...
...
libraries/chain/include/eosio/chain/wasm_interface.hpp
浏览文件 @
f3c69990
...
...
@@ -55,6 +55,10 @@ namespace eosio { namespace chain {
*/
void
apply
(
apply_context
&
context
);
/**
*/
void
error
(
apply_context
&
context
);
private:
wasm_interface
();
unique_ptr
<
struct
wasm_interface_impl
>
my
;
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
f3c69990
...
...
@@ -216,6 +216,10 @@ namespace eosio { namespace chain {
std
::
cerr
<<
name
(
val
).
to_string
();
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
prints
,
prints
,
none
,
i32
,
charptr
)
{
auto
&
wasm
=
wasm_interface
::
get
();
auto
mem
=
wasm
.
memory
();
...
...
libraries/testing/CMakeLists.txt
0 → 100644
浏览文件 @
f3c69990
file
(
GLOB HEADERS
"include/eosio/tester/*.hpp"
)
## SORT .cpp by most likely to change / break compile
add_library
(
eosio_testing
tester.cpp
${
HEADERS
}
)
target_link_libraries
(
eosio_testing eos_chain eos_utilities fc chainbase Logging IR WAST WASM Runtime
)
target_include_directories
(
eosio_testing
PUBLIC
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/include"
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../wasm-jit/Include"
)
if
(
MSVC
)
set_source_files_properties
(
db_init.cpp db_block.cpp database.cpp block_log.cpp PROPERTIES COMPILE_FLAGS
"/bigobj"
)
endif
(
MSVC
)
INSTALL
(
TARGETS
eosio_testing
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
INSTALL
(
FILES
${
HEADERS
}
DESTINATION
"include/eos/chain"
)
add_executable
(
runtest main.cpp
)
target_link_libraries
(
runtest eosio_testing
${
CMAKE_DL_LIBS
}
${
PLATFORM_SPECIFIC_LIBS
}
${
Intl_LIBRARIES
}
)
libraries/testing/include/eosio/testing/tester.hpp
0 → 100644
浏览文件 @
f3c69990
#pragma once
#include <eosio/chain/chain_controller.hpp>
namespace
eosio
{
namespace
testing
{
using
namespace
eosio
::
chain
;
/**
* @class tester
* @brief provides utility function to simplify the creation of unit tests
*/
class
tester
{
public:
tester
();
void
close
();
void
open
();
signed_block
produce_block
(
fc
::
microseconds
skip_time
=
fc
::
milliseconds
(
config
::
block_interval_ms
)
);
void
produce_blocks
(
uint32_t
n
=
1
);
void
push_transaction
(
signed_transaction
&
trx
);
void
set_tapos
(
signed_transaction
&
trx
);
void
create_account
(
account_name
name
,
asset
initial_balance
=
asset
(),
account_name
creator
=
N
(
inita
)
);
void
create_account
(
account_name
name
,
string
balance
=
"0.0000 EOS"
,
account_name
creator
=
N
(
inita
));
public_key_type
get_public_key
(
name
keyname
,
string
role
=
"owner"
);
private_key_type
get_private_key
(
name
keyname
,
string
role
=
"owner"
);
unique_ptr
<
chain_controller
>
control
;
private:
fc
::
temp_directory
tempdir
;
chain_controller
::
controller_config
cfg
;
};
}
}
/// eosio::testing
libraries/testing/main.cpp
0 → 100644
浏览文件 @
f3c69990
#include <eosio/testing/tester.hpp>
using
namespace
eosio
;
using
namespace
eosio
::
testing
;
int
main
(
int
argc
,
char
**
argv
)
{
try
{
tester
test
;
test
.
produce_blocks
(
50
);
test
.
create_account
(
N
(
dan
),
"100.0000 EOS"
);
}
catch
(
const
fc
::
exception
&
e
)
{
elog
(
"${e}"
,
(
"e"
,
e
.
to_detail_string
())
);
}
}
libraries/testing/tester.cpp
0 → 100644
浏览文件 @
f3c69990
#include <eosio/testing/tester.hpp>
#include <eosio/chain/asset.hpp>
#include <eosio/chain/contracts/types.hpp>
namespace
eosio
{
namespace
testing
{
tester
::
tester
()
{
cfg
.
block_log_dir
=
tempdir
.
path
()
/
"blocklog"
;
cfg
.
shared_memory_dir
=
tempdir
.
path
()
/
"shared"
;
cfg
.
shared_memory_size
=
1024
*
1024
*
8
;
cfg
.
genesis
.
initial_timestamp
=
fc
::
time_point
::
from_iso_string
(
"2020-01-01T00:00:00.000"
);
cfg
.
genesis
.
initial_accounts
.
resize
(
config
::
producer_count
);
cfg
.
genesis
.
initial_producers
.
resize
(
config
::
producer_count
);
uint64_t
init_name
=
N
(
inita
);
for
(
uint32_t
i
=
0
;
i
<
config
::
producer_count
;
++
i
)
{
auto
pubkey
=
get_public_key
(
init_name
);
cfg
.
genesis
.
initial_accounts
[
i
].
name
=
string
(
account_name
(
init_name
));
cfg
.
genesis
.
initial_accounts
[
i
].
owner_key
=
get_public_key
(
init_name
,
"owner"
);
cfg
.
genesis
.
initial_accounts
[
i
].
active_key
=
get_public_key
(
init_name
,
"active"
);
cfg
.
genesis
.
initial_accounts
[
i
].
liquid_balance
=
asset
::
from_string
(
"1000000.0000 EOS"
);
cfg
.
genesis
.
initial_accounts
[
i
].
staking_balance
=
asset
::
from_string
(
"1000000.0000 EOS"
);
cfg
.
genesis
.
initial_producers
[
i
].
owner_name
=
string
(
account_name
(
init_name
));
cfg
.
genesis
.
initial_producers
[
i
].
block_signing_key
=
get_public_key
(
init_name
,
"producer"
);
init_name
++
;
}
open
();
}
public_key_type
tester
::
get_public_key
(
name
keyname
,
string
role
)
{
return
get_private_key
(
keyname
,
role
).
get_public_key
();
}
private_key_type
tester
::
get_private_key
(
name
keyname
,
string
role
)
{
return
private_key_type
::
regenerate
<
fc
::
ecc
::
private_key_shim
>
(
fc
::
sha256
::
hash
(
string
(
keyname
)
+
role
));
}
void
tester
::
close
()
{
control
.
reset
();
}
void
tester
::
open
()
{
control
.
reset
(
new
chain_controller
(
cfg
)
);
}
signed_block
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
);
auto
sch_pro
=
control
->
get_scheduled_producer
(
slot
);
auto
priv_key
=
get_private_key
(
sch_pro
,
"producer"
);
return
control
->
generate_block
(
next_time
,
sch_pro
,
priv_key
);
}
void
tester
::
produce_blocks
(
uint32_t
n
)
{
for
(
uint32_t
i
=
0
;
i
<
n
;
++
i
)
produce_block
();
}
void
tester
::
set_tapos
(
signed_transaction
&
trx
)
{
trx
.
set_reference_block
(
control
->
head_block_id
()
);
}
void
tester
::
create_account
(
account_name
a
,
asset
initial_balance
,
account_name
creator
)
{
signed_transaction
trx
;
set_tapos
(
trx
);
trx
.
write_scope
=
{
creator
,
config
::
eosio_auth_scope
};
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
creator
,
config
::
active_name
}},
contracts
::
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"
)
),
.
deposit
=
initial_balance
});
trx
.
sign
(
get_private_key
(
creator
,
"active"
),
chain_id_type
()
);
push_transaction
(
trx
);
}
void
tester
::
push_transaction
(
signed_transaction
&
trx
)
{
set_tapos
(
trx
);
control
->
push_transaction
(
trx
);
}
void
tester
::
create_account
(
account_name
a
,
string
initial_balance
,
account_name
creator
)
{
create_account
(
a
,
asset
::
from_string
(
initial_balance
),
creator
);
}
}
}
/// eosio::test
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录