Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
ccd9ad7b
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,发现更多精彩内容 >>
提交
ccd9ad7b
编写于
2月 07, 2018
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
split nonce from the `require_auth` invoker for test system, unified users of such a thing
上级
37d50288
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
52 addition
and
62 deletion
+52
-62
contracts/test.system/test.system.abi
contracts/test.system/test.system.abi
+9
-1
contracts/test.system/test.system.cpp
contracts/test.system/test.system.cpp
+4
-4
libraries/testing/include/eosio/testing/tester.hpp
libraries/testing/include/eosio/testing/tester.hpp
+1
-0
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+22
-0
tests/chain_tests/auth_tests.cpp
tests/chain_tests/auth_tests.cpp
+7
-31
tests/chain_tests/recovery_tests.cpp
tests/chain_tests/recovery_tests.cpp
+9
-26
未找到文件。
contracts/test.system/test.system.abi
浏览文件 @
ccd9ad7b
...
...
@@ -34,10 +34,15 @@
{"name":"producer", "type":"producer_key[]"}
]
},{
"name": "
nonce
",
"name": "
require_auth
",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
]
},{
"name": "nonce",
"base": "",
"fields": [
{"name":"value", "type":"string"}
]
}],
...
...
@@ -50,6 +55,9 @@
},{
"name": "setprods",
"type": "set_producers"
},{
"name": "reqauth",
"type": "require_auth"
},{
"name": "nonce",
"type": "nonce"
...
...
contracts/test.system/test.system.cpp
浏览文件 @
ccd9ad7b
...
...
@@ -60,11 +60,11 @@ namespace testsystem {
EOSLIB_SERIALIZE
(
set_producers
,
(
version
)(
producers
)
);
};
struct
nonce
:
dispatchable
<
N
(
nonce
)
>
{
struct
require_auth
:
dispatchable
<
N
(
reqauth
)
>
{
account_name
from
;
static
void
process
(
const
nonce
&
n
)
{
require_auth
(
n
.
from
);
static
void
process
(
const
require_auth
&
r
)
{
::
require_auth
(
r
.
from
);
}
};
...
...
@@ -90,7 +90,7 @@ namespace testsystem {
}
};
using
dispatcher
=
dispatcher_impl
<
set_account_limits
,
set_global_limits
,
set_producers
,
nonce
>
;
using
dispatcher
=
dispatcher_impl
<
set_account_limits
,
set_global_limits
,
set_producers
,
require_auth
>
;
};
...
...
libraries/testing/include/eosio/testing/tester.hpp
浏览文件 @
ccd9ad7b
...
...
@@ -42,6 +42,7 @@ namespace eosio { namespace testing {
void
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_nonce
(
account_name
from
,
const
string
&
v
=
"blah"
);
transaction_trace
transfer
(
account_name
from
,
account_name
to
,
asset
amount
,
string
memo
,
account_name
currency
);
transaction_trace
transfer
(
account_name
from
,
account_name
to
,
string
amount
,
string
memo
,
account_name
currency
);
...
...
libraries/testing/tester.cpp
浏览文件 @
ccd9ad7b
...
...
@@ -140,6 +140,28 @@ 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
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
(
"account"
,
name
(
config
::
system_account_name
))
(
"name"
,
"reqauth"
)
(
"authorization"
,
auths
)
(
"data"
,
fc
::
mutable_variant_object
()
(
"from"
,
from
)
)
})
);
signed_transaction
trx
;
contracts
::
abi_serializer
::
from_variant
(
pretty_trx
,
trx
,
get_resolver
());
set_tapos
(
trx
);
for
(
auto
iter
=
keys
.
begin
();
iter
!=
keys
.
end
();
iter
++
)
trx
.
sign
(
*
iter
,
chain_id_type
()
);
return
push_transaction
(
trx
);
}
transaction_trace
tester
::
push_nonce
(
account_name
from
,
const
string
&
v
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
...
...
tests/chain_tests/auth_tests.cpp
浏览文件 @
ccd9ad7b
...
...
@@ -7,50 +7,26 @@ using namespace eosio::chain;
using
namespace
eosio
::
chain
::
contracts
;
using
namespace
eosio
::
testing
;
struct
auth_tester
:
public
tester
{
transaction_trace
push_nonce
(
account_name
from
,
std
::
initializer_list
<
permission_level
>
&&
permissions
,
std
::
initializer_list
<
private_key_type
>
&&
sign_with
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
(
"account"
,
name
(
config
::
system_account_name
))
(
"name"
,
"nonce"
)
(
"authorization"
,
vector
<
permission_level
>
(
permissions
))
(
"data"
,
fc
::
mutable_variant_object
()
(
"from"
,
from
)
(
"value"
,
fc
::
time_point
::
now
())
)
})
);
signed_transaction
trx
;
contracts
::
abi_serializer
::
from_variant
(
pretty_trx
,
trx
,
get_resolver
());
set_tapos
(
trx
);
for
(
auto
iter
=
sign_with
.
begin
();
iter
!=
sign_with
.
end
();
iter
++
)
trx
.
sign
(
*
iter
,
chain_id_type
()
);
return
push_transaction
(
trx
);
}
};
BOOST_AUTO_TEST_SUITE
(
auth_tests
)
BOOST_FIXTURE_TEST_CASE
(
missing_sigs
,
auth_
tester
)
{
try
{
BOOST_FIXTURE_TEST_CASE
(
missing_sigs
,
tester
)
{
try
{
create_accounts
(
{
N
(
alice
)}
);
produce_block
();
BOOST_REQUIRE_THROW
(
push_
nonce
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{}
),
tx_missing_sigs
);
auto
trace
=
push_
nonce
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{
get_private_key
(
N
(
alice
),
"active"
)
}
);
BOOST_REQUIRE_THROW
(
push_
reqauth
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{}
),
tx_missing_sigs
);
auto
trace
=
push_
reqauth
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{
get_private_key
(
N
(
alice
),
"active"
)
}
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trace
.
id
));
}
FC_LOG_AND_RETHROW
()
}
/// missing_sigs
BOOST_FIXTURE_TEST_CASE
(
missing_auths
,
auth_
tester
)
{
try
{
BOOST_FIXTURE_TEST_CASE
(
missing_auths
,
tester
)
{
try
{
create_accounts
(
{
N
(
alice
),
N
(
bob
)}
);
produce_block
();
/// action not provided from authority
BOOST_REQUIRE_THROW
(
push_
nonce
(
N
(
alice
),
{
permission_level
{
N
(
bob
),
config
::
active_name
}},
{
get_private_key
(
N
(
bob
),
"active"
)
}
),
tx_missing_auth
);
BOOST_REQUIRE_THROW
(
push_
reqauth
(
N
(
alice
),
{
permission_level
{
N
(
bob
),
config
::
active_name
}},
{
get_private_key
(
N
(
bob
),
"active"
)
}
),
tx_missing_auth
);
}
FC_LOG_AND_RETHROW
()
}
/// transfer_test
...
...
@@ -59,7 +35,7 @@ BOOST_FIXTURE_TEST_CASE( missing_auths, auth_tester ) { try {
* This test case will attempt to allow one account to transfer on behalf
* of another account by updating the active authority.
*/
BOOST_FIXTURE_TEST_CASE
(
delegate_auth
,
auth_
tester
)
{
try
{
BOOST_FIXTURE_TEST_CASE
(
delegate_auth
,
tester
)
{
try
{
create_accounts
(
{
N
(
alice
),
N
(
bob
)});
produce_block
();
...
...
@@ -73,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE( delegate_auth, auth_tester ) { try {
produce_block
(
fc
::
hours
(
2
)
);
///< skip 2 hours
/// execute nonce from alice signed by bob
auto
trace
=
push_
nonce
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{
get_private_key
(
N
(
bob
),
"active"
)
}
);
auto
trace
=
push_
reqauth
(
N
(
alice
),
{
permission_level
{
N
(
alice
),
config
::
active_name
}},
{
get_private_key
(
N
(
bob
),
"active"
)
}
);
produce_block
();
BOOST_REQUIRE_EQUAL
(
true
,
chain_has_transaction
(
trace
.
id
));
...
...
tests/chain_tests/recovery_tests.cpp
浏览文件 @
ccd9ad7b
...
...
@@ -36,25 +36,8 @@ auto make_vetorecovery(const tester &t, account_name account, permission_name ve
}
struct
recov_tester
:
public
tester
{
transaction_trace
push_nonce
(
account_name
from
,
string
role
)
{
variant
pretty_trx
=
fc
::
mutable_variant_object
()
(
"actions"
,
fc
::
variants
({
fc
::
mutable_variant_object
()
(
"account"
,
name
(
config
::
system_account_name
))
(
"name"
,
"nonce"
)
(
"authorization"
,
vector
<
permission_level
>
{{
from
,
config
::
owner_name
}})
(
"data"
,
fc
::
mutable_variant_object
()
(
"from"
,
from
)
(
"value"
,
fc
::
time_point
::
now
())
)
})
);
signed_transaction
trx
;
contracts
::
abi_serializer
::
from_variant
(
pretty_trx
,
trx
,
get_resolver
());
set_tapos
(
trx
);
trx
.
sign
(
get_private_key
(
from
,
role
),
chain_id_type
()
);
return
push_transaction
(
trx
);
transaction_trace
push_reqauth
(
account_name
from
,
string
role
)
{
return
tester
::
push_reqauth
(
from
,
vector
<
permission_level
>
{{
from
,
config
::
owner_name
}},
{
get_private_key
(
from
,
role
)}
);
}
};
...
...
@@ -84,13 +67,13 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner, recov_tester ) try {
auto
skip_time
=
expected_recovery
-
control
->
head_block_time
()
-
fc
::
milliseconds
(
config
::
block_interval_ms
);
produce_block
(
skip_time
);
control
->
push_deferred_transactions
(
true
);
auto
last_old_nonce_id
=
push_
nonce
(
N
(
alice
),
"owner"
).
id
;
auto
last_old_nonce_id
=
push_
reqauth
(
N
(
alice
),
"owner"
).
id
;
produce_block
();
control
->
push_deferred_transactions
(
true
);
BOOST_REQUIRE_EQUAL
(
chain_has_transaction
(
last_old_nonce_id
),
true
);
BOOST_REQUIRE_THROW
(
push_
nonce
(
N
(
alice
),
"owner"
),
tx_missing_sigs
);
auto
first_new_nonce_id
=
push_
nonce
(
N
(
alice
),
"owner.recov"
).
id
;
BOOST_REQUIRE_THROW
(
push_
reqauth
(
N
(
alice
),
"owner"
),
tx_missing_sigs
);
auto
first_new_nonce_id
=
push_
reqauth
(
N
(
alice
),
"owner.recov"
).
id
;
produce_block
();
BOOST_REQUIRE_EQUAL
(
chain_has_transaction
(
first_new_nonce_id
),
true
);
...
...
@@ -116,7 +99,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {
auto
skip_time
=
expected_recovery
-
control
->
head_block_time
()
-
fc
::
milliseconds
(
config
::
block_interval_ms
);
produce_block
(
skip_time
);
control
->
push_deferred_transactions
(
true
);
auto
last_old_nonce_id
=
push_
nonce
(
N
(
alice
),
"owner"
).
id
;
auto
last_old_nonce_id
=
push_
reqauth
(
N
(
alice
),
"owner"
).
id
;
// post the veto at the last possible time
{
...
...
@@ -131,8 +114,8 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {
// make sure the old owner is still in control
BOOST_REQUIRE_THROW
(
push_
nonce
(
N
(
alice
),
"owner.recov"
),
tx_missing_sigs
);
auto
first_new_nonce_id
=
push_
nonce
(
N
(
alice
),
"owner"
).
id
;
BOOST_REQUIRE_THROW
(
push_
reqauth
(
N
(
alice
),
"owner.recov"
),
tx_missing_sigs
);
auto
first_new_nonce_id
=
push_
reqauth
(
N
(
alice
),
"owner"
).
id
;
produce_block
();
BOOST_REQUIRE_EQUAL
(
chain_has_transaction
(
first_new_nonce_id
),
true
);
...
...
@@ -184,7 +167,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, recov_tester ) try {
control
->
push_deferred_transactions
(
true
);
// make sure the recovery goes through
auto
first_new_nonce_id
=
push_
nonce
(
N
(
alice
),
"owner"
).
id
;
auto
first_new_nonce_id
=
push_
reqauth
(
N
(
alice
),
"owner"
).
id
;
produce_block
();
BOOST_REQUIRE_EQUAL
(
chain_has_transaction
(
first_new_nonce_id
),
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录