Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
d432b6c2
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,发现更多精彩内容 >>
提交
d432b6c2
编写于
8月 21, 2017
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow validation of GeneratedTransactions and unify as much code as possible. ref EOSIO/eos#174
上级
54b2387d
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
161 addition
and
125 deletion
+161
-125
libraries/chain/block.cpp
libraries/chain/block.cpp
+1
-1
libraries/chain/chain_controller.cpp
libraries/chain/chain_controller.cpp
+9
-18
libraries/chain/include/eos/chain/chain_controller.hpp
libraries/chain/include/eos/chain/chain_controller.hpp
+19
-6
libraries/chain/include/eos/chain/transaction.hpp
libraries/chain/include/eos/chain/transaction.hpp
+50
-25
libraries/chain/transaction.cpp
libraries/chain/transaction.cpp
+17
-13
programs/eosc/main.cpp
programs/eosc/main.cpp
+5
-5
tests/api_tests/api_tests.cpp
tests/api_tests/api_tests.cpp
+4
-4
tests/common/macro_support.hpp
tests/common/macro_support.hpp
+24
-24
tests/common/testing_macros.hpp
tests/common/testing_macros.hpp
+3
-3
tests/slow_tests/slow_tests.cpp
tests/slow_tests/slow_tests.cpp
+21
-20
tests/tests/block_tests.cpp
tests/tests/block_tests.cpp
+5
-4
tests/tests/native_contract_tests.cpp
tests/tests/native_contract_tests.cpp
+3
-2
未找到文件。
libraries/chain/block.cpp
浏览文件 @
d432b6c2
...
...
@@ -102,7 +102,7 @@ namespace eos { namespace chain {
*/
for
(
const
auto
&
trx
:
user_input
)
ids
.
push_back
(
tr
x
.
digest
(
)
);
ids
.
push_back
(
tr
ansaction_helpers
::
digest
(
trx
)
);
/**
* When generating the merkle hash of an output transaction we hash it
...
...
libraries/chain/chain_controller.cpp
浏览文件 @
d432b6c2
...
...
@@ -23,7 +23,6 @@
*/
#include <eos/chain/chain_controller.hpp>
#include <eos/chain/exceptions.hpp>
#include <eos/chain/block_summary_object.hpp>
#include <eos/chain/global_property_object.hpp>
...
...
@@ -57,7 +56,6 @@
#include <iostream>
//#include <Wren++.h>
namespace
eos
{
namespace
chain
{
...
...
@@ -585,18 +583,7 @@ ProcessedTransaction chain_controller::apply_transaction(const SignedTransaction
return
with_skip_flags
(
skip
,
[
&
]()
{
return
_apply_transaction
(
trx
);
});
}
void
chain_controller
::
validate_transaction
(
const
SignedTransaction
&
trx
)
const
{
try
{
EOS_ASSERT
(
trx
.
messages
.
size
()
>
0
,
transaction_exception
,
"A transaction must have at least one message"
);
validate_scope
(
trx
);
validate_expiration
(
trx
);
validate_uniqueness
(
trx
);
validate_tapos
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
trx
)
)
}
void
chain_controller
::
validate_scope
(
const
SignedTransaction
&
trx
)
const
{
void
chain_controller
::
validate_scope
(
const
Transaction
&
trx
)
const
{
EOS_ASSERT
(
trx
.
scope
.
size
()
>
0
,
transaction_exception
,
"No scope specified by transaction"
);
for
(
uint32_t
i
=
1
;
i
<
trx
.
scope
.
size
();
++
i
)
EOS_ASSERT
(
trx
.
scope
[
i
-
1
]
<
trx
.
scope
[
i
],
transaction_exception
,
"Scopes must be sorted and unique"
);
...
...
@@ -630,18 +617,22 @@ void chain_controller::validate_uniqueness( const SignedTransaction& trx )const
EOS_ASSERT
(
transaction
==
nullptr
,
tx_duplicate
,
"Transaction is not unique"
);
}
void
chain_controller
::
validate_tapos
(
const
SignedTransaction
&
trx
)
const
{
void
chain_controller
::
validate_uniqueness
(
const
GeneratedTransaction
&
trx
)
const
{
if
(
!
should_check_for_duplicate_transactions
()
)
return
;
}
void
chain_controller
::
validate_tapos
(
const
Transaction
&
trx
)
const
{
if
(
!
should_check_tapos
())
return
;
const
auto
&
tapos_block_summary
=
_db
.
get
<
block_summary_object
>
((
uint16_t
)
trx
.
refBlockNum
);
//Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration
EOS_ASSERT
(
tr
x
.
verify_reference_block
(
tapos_block_summary
.
block_id
),
transaction_exception
,
EOS_ASSERT
(
tr
ansaction_helpers
::
verify_reference_block
(
trx
,
tapos_block_summary
.
block_id
),
transaction_exception
,
"Transaction's reference block did not match. Is this transaction from a different fork?"
,
(
"tapos_summary"
,
tapos_block_summary
));
}
void
chain_controller
::
validate_referenced_accounts
(
const
Signed
Transaction
&
trx
)
const
{
void
chain_controller
::
validate_referenced_accounts
(
const
Transaction
&
trx
)
const
{
for
(
const
auto
&
scope
:
trx
.
scope
)
require_account
(
scope
);
for
(
const
auto
&
msg
:
trx
.
messages
)
{
...
...
@@ -651,7 +642,7 @@ void chain_controller::validate_referenced_accounts(const SignedTransaction& trx
}
}
void
chain_controller
::
validate_expiration
(
const
Signed
Transaction
&
trx
)
const
void
chain_controller
::
validate_expiration
(
const
Transaction
&
trx
)
const
{
try
{
fc
::
time_point_sec
now
=
head_block_time
();
const
BlockchainConfiguration
&
chain_configuration
=
get_global_properties
().
configuration
;
...
...
libraries/chain/include/eos/chain/chain_controller.hpp
浏览文件 @
d432b6c2
...
...
@@ -38,6 +38,7 @@
#include <eos/chain/message_handling_contexts.hpp>
#include <eos/chain/chain_initializer_interface.hpp>
#include <eos/chain/chain_administration_interface.hpp>
#include <eos/chain/exceptions.hpp>
#include <fc/log/logger.hpp>
...
...
@@ -282,15 +283,27 @@ namespace eos { namespace chain {
/**
* This method performs some consistency checks on a transaction.
* @
return true if the transaction would validate
* @
thow transaction_exception if the transaction is invalid
*/
void
validate_transaction
(
const
SignedTransaction
&
trx
)
const
;
template
<
typename
T
>
void
validate_transaction
(
const
T
&
trx
)
const
{
try
{
EOS_ASSERT
(
trx
.
messages
.
size
()
>
0
,
transaction_exception
,
"A transaction must have at least one message"
);
validate_scope
(
trx
);
validate_expiration
(
trx
);
validate_uniqueness
(
trx
);
validate_tapos
(
trx
);
}
FC_CAPTURE_AND_RETHROW
(
(
trx
)
)
}
/// Validate transaction helpers @{
void
validate_uniqueness
(
const
SignedTransaction
&
trx
)
const
;
void
validate_tapos
(
const
SignedTransaction
&
trx
)
const
;
void
validate_referenced_accounts
(
const
SignedTransaction
&
trx
)
const
;
void
validate_expiration
(
const
SignedTransaction
&
trx
)
const
;
void
validate_scope
(
const
SignedTransaction
&
trx
)
const
;
void
validate_uniqueness
(
const
GeneratedTransaction
&
trx
)
const
;
void
validate_tapos
(
const
Transaction
&
trx
)
const
;
void
validate_referenced_accounts
(
const
Transaction
&
trx
)
const
;
void
validate_expiration
(
const
Transaction
&
trx
)
const
;
void
validate_scope
(
const
Transaction
&
trx
)
const
;
/// @}
/**
...
...
libraries/chain/include/eos/chain/transaction.hpp
浏览文件 @
d432b6c2
...
...
@@ -52,6 +52,49 @@ namespace eos { namespace chain {
* @{
*/
/**
* @brief A base transaction without any explicit or implied authorizations.
*
* This is a utility class for sharing common operations between inheriting types which defines
* additional features and requirements.
*/
namespace
transaction_helpers
{
/// Calculate the digest for a transaction
digest_type
digest
(
const
Transaction
&
t
);
void
set_reference_block
(
Transaction
&
t
,
const
block_id_type
&
reference_block
);
bool
verify_reference_block
(
const
Transaction
&
t
,
const
block_id_type
&
reference_block
);
template
<
typename
T
>
void
set_message
(
Transaction
&
t
,
int
index
,
const
types
::
FuncName
&
type
,
T
&&
value
)
{
Message
m
(
t
.
messages
[
index
]);
m
.
set
(
type
,
std
::
forward
<
T
>
(
value
));
t
.
messages
[
index
]
=
m
;
}
template
<
typename
T
>
T
message_as
(
Transaction
&
t
,
int
index
)
{
Message
m
(
t
.
messages
[
index
]);
return
m
.
as
<
T
>
();
}
template
<
typename
...
Args
>
void
emplace_message
(
Transaction
&
t
,
Args
&&
...
a
)
{
t
.
messages
.
emplace_back
(
Message
(
std
::
forward
<
Args
>
(
a
)...));
}
/**
* clear all common data
*/
inline
void
clear
(
Transaction
&
t
)
{
t
.
messages
.
clear
();
}
}
/**
* @brief A generated_transaction is a transaction which was internally generated by the blockchain, typically as a
* result of running a contract.
...
...
@@ -65,7 +108,7 @@ namespace eos { namespace chain {
* sequential ID, then stored in the block that generated them. These generated transactions can then be included in
* subsequent blocks by referencing this ID.
*/
struct
GeneratedTransaction
:
public
Transaction
{
struct
GeneratedTransaction
:
public
types
::
Transaction
{
generated_transaction_id_type
id
;
digest_type
merkle_digest
()
const
;
...
...
@@ -78,17 +121,15 @@ namespace eos { namespace chain {
* and the signatures backing those authorizations.
*/
struct
SignedTransaction
:
public
types
::
SignedTransaction
{
using
types
::
SignedTransaction
::
SignedTransaction
;
typedef
types
::
SignedTransaction
super
;
using
super
::
super
;
/// Calculate the digest for a transaction
digest_type
digest
()
const
;
/// Calculate the id of the transaction
transaction_id_type
id
()
const
;
/// Calculate the digest used for signature validation
digest_type
sig_digest
(
const
chain_id_type
&
chain_id
)
const
;
void
set_reference_block
(
const
block_id_type
&
reference_block
);
bool
verify_reference_block
(
const
block_id_type
&
reference_block
)
const
;
/** signs and appends to signatures */
const
signature_type
&
sign
(
const
private_key_type
&
key
,
const
chain_id_type
&
chain_id
);
...
...
@@ -97,28 +138,12 @@ namespace eos { namespace chain {
flat_set
<
public_key_type
>
get_signature_keys
(
const
chain_id_type
&
chain_id
)
const
;
template
<
typename
T
>
void
setMessage
(
int
messageIndex
,
const
types
::
FuncName
&
type
,
T
&&
value
)
{
Message
m
(
messages
[
messageIndex
]);
m
.
set
(
type
,
std
::
forward
<
T
>
(
value
));
messages
[
messageIndex
]
=
m
;
}
template
<
typename
T
>
T
messageAs
(
int
messageIndex
)
{
Message
m
(
messages
[
messageIndex
]);
return
m
.
as
<
T
>
();
}
template
<
typename
...
Args
>
void
emplaceMessage
(
Args
&&
...
a
)
{
messages
.
emplace_back
(
Message
(
std
::
forward
<
Args
>
(
a
)...));
}
/**
* Removes all messages, signatures, and authorizations
*/
void
clear
()
{
messages
.
clear
(
);
signatures
.
clear
();
}
void
clear
()
{
transaction_helpers
::
clear
(
*
this
);
signatures
.
clear
();
}
digest_type
merkle_digest
()
const
;
digest_type
merkle_digest
()
const
;
};
struct
ProcessedTransaction
;
...
...
libraries/chain/transaction.cpp
浏览文件 @
d432b6c2
...
...
@@ -31,12 +31,26 @@
namespace
eos
{
namespace
chain
{
digest_type
SignedTransaction
::
digest
()
const
{
namespace
transaction_helpers
{
digest_type
digest
(
const
Transaction
&
t
)
{
digest_type
::
encoder
enc
;
fc
::
raw
::
pack
(
enc
,
static_cast
<
const
types
::
Transaction
&>
(
*
this
)
);
fc
::
raw
::
pack
(
enc
,
t
);
return
enc
.
result
();
}
void
set_reference_block
(
Transaction
&
t
,
const
block_id_type
&
reference_block
)
{
t
.
refBlockNum
=
fc
::
endian_reverse_u32
(
reference_block
.
_hash
[
0
]);
t
.
refBlockPrefix
=
reference_block
.
_hash
[
1
];
}
bool
verify_reference_block
(
const
Transaction
&
t
,
const
block_id_type
&
reference_block
)
{
return
t
.
refBlockNum
==
(
decltype
(
t
.
refBlockNum
))
fc
::
endian_reverse_u32
(
reference_block
.
_hash
[
0
])
&&
t
.
refBlockPrefix
==
(
decltype
(
t
.
refBlockPrefix
))
reference_block
.
_hash
[
1
];
}
}
// namespace transaction_helpers
digest_type
SignedTransaction
::
sig_digest
(
const
chain_id_type
&
chain_id
)
const
{
digest_type
::
encoder
enc
;
fc
::
raw
::
pack
(
enc
,
chain_id
);
...
...
@@ -45,7 +59,7 @@ digest_type SignedTransaction::sig_digest( const chain_id_type& chain_id )const
}
eos
::
chain
::
transaction_id_type
SignedTransaction
::
id
()
const
{
auto
h
=
digest
(
);
auto
h
=
transaction_helpers
::
digest
(
*
this
);
transaction_id_type
result
;
memcpy
(
result
.
_hash
,
h
.
_hash
,
std
::
min
(
sizeof
(
result
),
sizeof
(
h
)));
return
result
;
...
...
@@ -60,16 +74,6 @@ signature_type eos::chain::SignedTransaction::sign(const private_key_type& key,
return
key
.
sign_compact
(
sig_digest
(
chain_id
));
}
void
SignedTransaction
::
set_reference_block
(
const
block_id_type
&
reference_block
)
{
refBlockNum
=
fc
::
endian_reverse_u32
(
reference_block
.
_hash
[
0
]);
refBlockPrefix
=
reference_block
.
_hash
[
1
];
}
bool
SignedTransaction
::
verify_reference_block
(
const
block_id_type
&
reference_block
)
const
{
return
refBlockNum
==
(
decltype
(
refBlockNum
))
fc
::
endian_reverse_u32
(
reference_block
.
_hash
[
0
])
&&
refBlockPrefix
==
(
decltype
(
refBlockPrefix
))
reference_block
.
_hash
[
1
];
}
flat_set
<
public_key_type
>
SignedTransaction
::
get_signature_keys
(
const
chain_id_type
&
chain_id
)
const
{
try
{
using
boost
::
adaptors
::
transformed
;
...
...
programs/eosc/main.cpp
浏览文件 @
d432b6c2
...
...
@@ -102,7 +102,7 @@ eos::chain_apis::read_only::get_info_results get_info() {
fc
::
variant
push_transaction
(
SignedTransaction
&
trx
)
{
auto
info
=
get_info
();
trx
.
expiration
=
info
.
head_block_time
+
100
;
//chain.head_block_time() + 100;
tr
x
.
set_reference_block
(
info
.
head_block_id
);
tr
ansaction_helpers
::
set_reference_block
(
trx
,
info
.
head_block_id
);
boost
::
sort
(
trx
.
scope
);
return
call
(
push_txn_func
,
trx
);
...
...
@@ -127,7 +127,7 @@ void create_account( const vector<string>& cmd_line ) {
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
creator
,
eosaccnt
});
tr
x
.
emplaceMessage
(
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
creator
,
"active"
}},
"newaccount"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
creator
,
"active"
}},
"newaccount"
,
types
::
newaccount
{
creator
,
newaccount
,
owner_auth
,
active_auth
,
recovery_auth
,
deposit
});
...
...
@@ -308,7 +308,7 @@ int send_command (const vector<string> &cmd_line)
SignedTransaction
trx
;
trx
.
scope
=
{
config
::
EosContractName
,
account
};
tr
x
.
emplaceMessage
(
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
account
,
"active"
}},
tr
ansaction_helpers
::
emplace_message
(
trx
,
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
account
,
"active"
}},
"setcode"
,
handler
);
std
::
cout
<<
fc
::
json
::
to_pretty_string
(
push_transaction
(
trx
)
)
<<
std
::
endl
;
...
...
@@ -322,11 +322,11 @@ int send_command (const vector<string> &cmd_line)
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
sender
,
recipient
});
tr
x
.
emplaceMessage
(
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
sender
,
"active"
}},
"transfer"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
sender
,
"active"
}},
"transfer"
,
types
::
transfer
{
sender
,
recipient
,
amount
});
auto
info
=
get_info
();
trx
.
expiration
=
info
.
head_block_time
+
100
;
//chain.head_block_time() + 100;
tr
x
.
set_reference_block
(
info
.
head_block_id
);
tr
ansaction_helpers
::
set_reference_block
(
trx
,
info
.
head_block_id
);
std
::
cout
<<
fc
::
json
::
to_pretty_string
(
call
(
push_txn_func
,
trx
))
<<
std
::
endl
;
}
...
...
tests/api_tests/api_tests.cpp
浏览文件 @
d432b6c2
...
...
@@ -86,10 +86,10 @@ uint32_t CallFunction( testing_blockchain& chain, const types::Message& msg, con
std
::
copy
(
data
.
begin
(),
data
.
end
(),
std
::
back_inserter
(
dest
));
//std::cout << "MANDO: " << msg.code << " " << msg.type << std::endl;
tr
x
.
emplaceMessage
(
msg
);
tr
ansaction_helpers
::
emplace_message
(
trx
,
msg
);
trx
.
expiration
=
chain
.
head_block_time
()
+
expiration
++
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
//idump((trx));
chain
.
push_transaction
(
trx
);
...
...
@@ -177,9 +177,9 @@ void send_set_code_message(testing_blockchain& chain, types::setcode& handler, A
trx
.
messages
.
resize
(
1
);
trx
.
messages
[
0
].
authorization
=
{{
account
,
"active"
}};
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
tr
x
.
setMessage
(
0
,
"setcode"
,
handler
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"setcode"
,
handler
);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
chain
.
produce_blocks
(
1
);
}
...
...
tests/common/macro_support.hpp
浏览文件 @
d432b6c2
...
...
@@ -46,11 +46,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names({ #creator, config::EosContractName }); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#creator, "active"}}, \
"newaccount", types::newaccount{#creator, #name, owner, active, recovery, deposit}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Created account " << #name); \
}
...
...
@@ -78,11 +78,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = {#account}; \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#account,"active"}}, \
"updateauth", types::updateauth{#account, authname, parentname, auth}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Set " << #account << "'s " << authname << " authority."); \
}
...
...
@@ -91,11 +91,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = {#account}; \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#account,"active"}}, \
"deleteauth", types::deleteauth{#account, authname}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Deleted " << #account << "'s " << authname << " authority."); \
}
...
...
@@ -104,11 +104,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = {#account}; \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#account,"active"}}, \
"linkauth", types::linkauth{#account, #codeacct, messagetype, authname}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Link " << #codeacct << "::" << messagetype << " to " << #account \
<< "'s " << authname << " authority."); \
...
...
@@ -119,11 +119,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = {#account}; \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#account,"active"}}, \
"unlinkauth", types::unlinkauth{#account, #codeacct, messagetype}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Unlink " << #codeacct << "::" << messagetype << " from " << #account); \
}
...
...
@@ -133,11 +133,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names({#sender,#recipient}); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{ {#sender,"active"} }, \
"transfer", types::transfer{#sender, #recipient, Amount.amount}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Transfered " << Amount << " from " << #sender << " to " << #recipient); \
}
...
...
@@ -147,10 +147,10 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( { #sender, #recipient, config::EosContractName } ); \
tr
x.emplaceMessage(
config::EosContractName, vector<types::AccountPermission>{{#sender, "active"}}, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, vector<types::AccountPermission>{{#sender, "active"}}, \
"lock", types::lock{#sender, #recipient, amount}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Staked " << amount << " to " << #recipient); \
}
...
...
@@ -160,11 +160,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( { config::EosContractName } ); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#account, "active"}}, \
"unlock", types::unlock{#account, amount}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Begin unstake " << amount << " to " << #account); \
}
...
...
@@ -173,10 +173,10 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( { config::EosContractName, #account } ); \
tr
x.emplaceMessage(
config::EosContractName, vector<types::AccountPermission>{{#account, "active"}}, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, vector<types::AccountPermission>{{#account, "active"}}, \
"claim", types::claim{#account, amount}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Finish unstake " << amount << " to " << #account); \
}
...
...
@@ -185,11 +185,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( {#owner, config::EosContractName} ); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#owner, "active"}}, \
"setproducer", types::setproducer{#owner, key, cfg}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Create producer " << #owner); \
}
...
...
@@ -202,11 +202,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( {#voter, config::EosContractName} ); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{#voter, "active"}}, \
"okproducer", types::okproducer{#voter, #producer, approved? 1 : 0}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Set producer approval from " << #voter << " for " << #producer << " to " << approved); \
}
...
...
@@ -215,11 +215,11 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
{ \
eos::chain::SignedTransaction trx; \
trx.scope = sort_names( {owner, config::EosContractName} ); \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{{owner, "active"}}, \
"setproducer", types::setproducer{owner, key, cfg}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
BOOST_TEST_CHECKPOINT("Update producer " << owner); \
}
...
...
tests/common/testing_macros.hpp
浏览文件 @
d432b6c2
...
...
@@ -284,13 +284,13 @@
{ \
eos::chain::SignedTransaction trx; \
if (std::string(#stakeholder) != std::string(#proxy)) \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{ {#stakeholder,"active"} }, "setproxy", types::setproxy{#stakeholder, #proxy}); \
else \
tr
x.emplaceMessage(
config::EosContractName, \
tr
ansaction_helpers::emplace_message(trx,
config::EosContractName, \
vector<types::AccountPermission>{ {#stakeholder,"active"} }, "setproxy", types::setproxy{#stakeholder, #proxy}); \
trx.expiration = chain.head_block_time() + 100; \
tr
x.set_reference_block(
chain.head_block_id()); \
tr
ansaction_helpers::set_reference_block(trx,
chain.head_block_id()); \
chain.push_transaction(trx); \
}
...
...
tests/slow_tests/slow_tests.cpp
浏览文件 @
d432b6c2
...
...
@@ -51,6 +51,7 @@
using
namespace
eos
;
using
namespace
chain
;
struct
OrderID
{
AccountName
name
;
uint64_t
number
=
0
;
...
...
@@ -297,9 +298,9 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast )
trx
.
messages
.
resize
(
1
);
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
trx
.
messages
[
0
].
authorization
.
emplace_back
(
types
::
AccountPermission
{
account
,
"active"
});
tr
x
.
setMessage
(
0
,
"setcode"
,
handler
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"setcode"
,
handler
);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
chain
.
produce_blocks
(
1
);
}
...
...
@@ -308,12 +309,12 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast )
void
TransferCurrency
(
testing_blockchain
&
chain
,
AccountName
from
,
AccountName
to
,
uint64_t
amount
)
{
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
from
,
to
});
tr
x
.
emplaceMessage
(
"currency"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"currency"
,
vector
<
types
::
AccountPermission
>
{
{
from
,
"active"
}
},
"transfer"
,
types
::
transfer
{
from
,
to
,
amount
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
idump
((
trx
));
chain
.
push_transaction
(
trx
);
}
...
...
@@ -321,11 +322,11 @@ void TransferCurrency( testing_blockchain& chain, AccountName from, AccountName
void
WithdrawCurrency
(
testing_blockchain
&
chain
,
AccountName
from
,
AccountName
to
,
uint64_t
amount
)
{
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
from
,
to
});
tr
x
.
emplaceMessage
(
"currency"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"currency"
,
vector
<
types
::
AccountPermission
>
{
{
from
,
"active"
},{
to
,
"active"
}
},
"transfer"
,
types
::
transfer
{
from
,
to
,
amount
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
}
...
...
@@ -351,9 +352,9 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
trx
.
messages
.
resize
(
1
);
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
trx
.
messages
[
0
].
authorization
.
emplace_back
(
types
::
AccountPermission
{
"currency"
,
"active"
});
tr
x
.
setMessage
(
0
,
"setcode"
,
handler
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"setcode"
,
handler
);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
chain
.
produce_blocks
(
1
);
}
...
...
@@ -364,11 +365,11 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
{
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
"currency"
,
"inita"
});
tr
x
.
emplaceMessage
(
"currency"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"currency"
,
vector
<
types
::
AccountPermission
>
{
{
"currency"
,
"active"
}
},
"transfer"
,
types
::
transfer
{
"currency"
,
"inita"
,
1
+
i
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
//idump((trx));
chain
.
push_transaction
(
trx
);
}
...
...
@@ -402,12 +403,12 @@ void SellCurrency( testing_blockchain& chain, AccountName seller, AccountName ex
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
"exchange"
});
tr
x
.
emplaceMessage
(
"exchange"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"exchange"
,
vector
<
types
::
AccountPermission
>
{
{
seller
,
"active"
}
},
"sell"
,
b
);
//trx.messages.back().set_packed( "sell", b);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
}
...
...
@@ -420,12 +421,12 @@ void BuyCurrency( testing_blockchain& chain, AccountName buyer, AccountName exch
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
"exchange"
});
tr
x
.
emplaceMessage
(
"exchange"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"exchange"
,
vector
<
types
::
AccountPermission
>
{
{
buyer
,
"active"
}
},
"buy"
,
b
);
//trx.messages.back().set_packed( "buy", b);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
}
...
...
@@ -1116,9 +1117,9 @@ R"(
trx
.
messages
.
resize
(
1
);
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
trx
.
messages
[
0
].
authorization
.
emplace_back
(
types
::
AccountPermission
{
"simplecoin"
,
"active"
});
tr
x
.
setMessage
(
0
,
"setcode"
,
handler
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"setcode"
,
handler
);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
try
{
chain
.
push_transaction
(
trx
);
BOOST_FAIL
(
"floating point instructions should be rejected"
);
...
...
@@ -1153,9 +1154,9 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture)
trx
.
messages
.
resize
(
1
);
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
trx
.
messages
[
0
].
authorization
.
emplace_back
(
types
::
AccountPermission
{
"currency"
,
"active"
});
tr
x
.
setMessage
(
0
,
"setcode"
,
handler
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"setcode"
,
handler
);
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
);
chain
.
produce_blocks
(
1
);
}
...
...
@@ -1164,11 +1165,11 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture)
{
eos
::
chain
::
SignedTransaction
trx
;
trx
.
scope
=
sort_names
({
"currency"
,
"inita"
});
tr
x
.
emplaceMessage
(
"currency"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"currency"
,
vector
<
types
::
AccountPermission
>
{
{
"currency"
,
"active"
}
},
"transfer"
,
types
::
transfer
{
"currency"
,
"inita"
,
1
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
try
{
wlog
(
"starting long transaction"
);
...
...
tests/tests/block_tests.cpp
浏览文件 @
d432b6c2
...
...
@@ -48,6 +48,7 @@ using namespace chain;
BOOST_AUTO_TEST_SUITE
(
block_tests
)
...
...
@@ -145,11 +146,11 @@ BOOST_FIXTURE_TEST_CASE(trx_variant, testing_fixture) {
eos
::
chain
::
ProcessedTransaction
trx
;
trx
.
scope
=
sort_names
({
from
,
to
});
tr
x
.
emplaceMessage
(
"eos"
,
tr
ansaction_helpers
::
emplace_message
(
trx
,
"eos"
,
vector
<
types
::
AccountPermission
>
{
{
from
,
"active"
}
},
"transfer"
,
types
::
transfer
{
from
,
to
,
amount
/*, ""*/
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
auto
original
=
fc
::
raw
::
pack
(
trx
);
auto
var
=
chain
.
transaction_to_variant
(
trx
);
...
...
@@ -178,10 +179,10 @@ BOOST_FIXTURE_TEST_CASE(irrelevant_auth, testing_fixture) {
ProcessedTransaction
trx
;
trx
.
scope
=
sort_names
({
"joe"
,
"inita"
});
tr
x
.
emplaceMessage
(
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
"inita"
,
"active"
}},
tr
ansaction_helpers
::
emplace_message
(
trx
,
config
::
EosContractName
,
vector
<
types
::
AccountPermission
>
{{
"inita"
,
"active"
}},
"transfer"
,
types
::
transfer
{
"inita"
,
"joe"
,
50
});
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
chain
.
push_transaction
(
trx
,
chain_controller
::
skip_transaction_signatures
);
chain
.
clear_pending
();
...
...
tests/tests/native_contract_tests.cpp
浏览文件 @
d432b6c2
...
...
@@ -23,6 +23,7 @@
using
namespace
eos
;
using
namespace
chain
;
BOOST_AUTO_TEST_SUITE
(
native_contract_tests
)
//Simple test of account creation
...
...
@@ -91,7 +92,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
SignedTransaction
trx
;
BOOST_REQUIRE_THROW
(
chain
.
push_transaction
(
trx
),
transaction_exception
);
// no messages
trx
.
messages
.
resize
(
1
);
tr
x
.
set_reference_block
(
chain
.
head_block_id
());
tr
ansaction_helpers
::
set_reference_block
(
trx
,
chain
.
head_block_id
());
trx
.
expiration
=
chain
.
head_block_time
()
+
100
;
trx
.
scope
=
sort_names
(
{
"inita"
,
"initb"
}
);
...
...
@@ -104,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
trx
.
messages
[
0
].
type
=
"transfer"
;
trx
.
messages
[
0
].
authorization
=
{{
"inita"
,
"active"
}};
trx
.
messages
[
0
].
code
=
config
::
EosContractName
;
tr
x
.
setMessage
(
0
,
"transfer"
,
trans
);
tr
ansaction_helpers
::
set_message
(
trx
,
0
,
"transfer"
,
trans
);
chain
.
push_transaction
(
trx
,
chain_controller
::
skip_transaction_signatures
);
BOOST_CHECK_EQUAL
(
chain
.
get_liquid_balance
(
"inita"
),
Asset
(
100000
-
100
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录